Giter Club home page Giter Club logo

flutter_gherkin_addons's Introduction

flutter_gherkin_addons

Addons for flutter Gherkin Development

Getting Started

Creating Project

Creating a flutter gherkin project is as simple as adding few dependencies in you projects listed below

flutter_gherkin: ^1.0.4
flutter_gherkin_addons: ^0.1.2
flutter_driver:
    sdk: flutter

Assumptions

You have config.yaml file at root of that looks typically like below

reporting: true <This Turns on or of json reporting>
stubbing: true <This turns on or off mocking server launched on port 8081>

You have app.dart file which has necessary steps to launch application in the same directory where app_test.dart located.

Typical app.dart looks like below

import 'package:<your_package>/<your root file where app is located>.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_driver/driver_extension.dart';
void main() {
  enableFlutterDriverExtension();
  runApp(YourApp());
}

Typical app_test.dart looks like below

import 'dart:async';
import 'package:flutter_gherkin_addons/wrapper.dart';
import 'steps/mocking_steps.dart';
Future<void> main() async {
  return TestRuntime.start(
      [
        ... your step definition functions
      ]
  );
}

Writing Step Definitions

You can write step definition with simple wrapper functions (in future probably will be moved to main package) as below

GenericWhen1 whenITapOnPersonOnHomePage(){
  return when1("I tap on {string}", (context,String within) async {
    final locator = find.byValueKey(within);
    FlutterDriverUtils.tap(context.world.driver, locator,timeout: context.timeout);
  });
}

Mocking api requests

You can mock api requests in a step or anywhere as below

import 'dart:convert';
import 'package:flutter_gherkin_addons/given.dart';
import 'package:flutter_gherkin_addons/stubber.dart';
import 'package:flutter_gherkin_addons/wrapper.dart';
import 'package:gherkin/gherkin.dart';
import 'package:persona/models/Person.dart';
GenericGiven1 givenFollowingUserExists(){
  return given1("Below Persona exists",(context,Table dataTable) async  {
    var persons=[];

    for (var row in dataTable.rows) {
      persons.add(Person(
        name: row.columns.elementAt(0),
        hair_color: row.columns.elementAt(1),
        skin_color: row.columns.elementAt(2),
        eye_color: row.columns.elementAt(3),
      ));
    }
    TestRuntime.addStub(StubFor.staticHttpGet("/people",Response(200,json.encode({
      "results":persons
    }),headers: {"Content-Type":"application/json"})));
  });
}

The above step mocks /people get call on http://localhost:8081 (on iOS) http://10.0.2.2:8081 (on Android) you can inject this urls into your app while launching app as demonstrated in example Obove step can be invoked like

Given Below Persona exists
  |name   |hair_color |skin_color |eye_color  |
  |Atmaram|Blonde     |Dark       |Hazel      |
  |Keshav |Black      |Fair       |Balck      |
  |Prasad |Black      |Fair       |Black      |

flutter_gherkin_addons's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.