flutter_gherkin_addons 0.1.6

  • Readme
  • Changelog
  • Example
  • Installing
  • 57

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

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      |

[0.0.1] - First Version of library #

[0.1.0] - First candidate with changes suggested by flutter.dev #

[0.1.1] - Adds Description and example #

[0.1.2] - Makes Bootrapper configurable #

[0.1.3] - Adds readme to package #

[0.1.4] - Makes Dynamic Stubbing possible with lambda #

[0.1.5] - Adds Provision for adding hooks #

[0.1.6] - Adds Provision for adding custom timeouts for steps #

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:persona/Config.dart';
import 'package:persona/view/HomePage.dart';
void main() => runApp(PersonaApp('prod'));

class PersonaApp extends StatelessWidget {
  static Future<Config> config;
  String env;
  PersonaApp(this.env);

  @override
  Widget build(BuildContext context) {
    config = getConfig(env);
    return MaterialApp(
      title: 'Persona App',
      theme: ThemeData(
        // This is the theme of your application.
        //
        // Try running your application with "flutter run". You'll see the
        // application has a blue toolbar. Then, without quitting the app, try
        // changing the primarySwatch below to Colors.green and then invoke
        // "hot reload" (press "r" in the console where you ran "flutter run",
        // or simply save your changes to "hot reload" in a Flutter IDE).
        // Notice that the counter didn't reset back to zero; the application
        // is not restarted.
        primarySwatch: Colors.blue,
      ),
      home: HomePage(title: 'List of Persons'),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  flutter_gherkin_addons: ^0.1.6

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:flutter_gherkin_addons/flutter_gherkin_addons.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
15
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
57
Learn more about scoring.

We analyzed this package on Jul 7, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.13
  • Flutter: 1.17.5

Analysis suggestions

Package not compatible with SDK dart

because of import path [flutter_gherkin_addons] that is in a package requiring null.

Package not compatible with runtime flutter-web on web

Because of the import of dart:io via the import chain package:flutter_gherkin_addons/flutter_gherkin_addons.dartpackage:flutter_gherkin_addons/stubber.dartpackage:mock_web_server/mock_web_server.dartdart:io

Health issues and suggestions

Document public APIs. (-1 points)

142 out of 142 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Fix lib/stubber.dart. (-0.50 points)

Analysis of lib/stubber.dart reported 1 hint:

line 3 col 8: Unused import: 'package:flutter_gherkin_addons/flutter_gherkin_addons.dart'.

Format lib/given.dart.

Run flutter format to format lib/given.dart.

Format lib/then.dart.

Run flutter format to format lib/then.dart.

Format lib/when.dart.

Run flutter format to format lib/when.dart.

Format lib/wrapper.dart.

Run flutter format to format lib/wrapper.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
flutter_driver 0.0.0
flutter_gherkin ^1.0.4 1.1.8+2
gherkin ^1.1.7 1.1.8+1
glob ^1.2.0 1.2.0
mock_web_server ^4.1.1 4.1.1
path ^1.6.4 1.6.4 1.7.0
yaml ^2.2.0 2.2.1
Transitive dependencies
_fe_analyzer_shared 5.0.0
analyzer 0.39.12
archive 2.0.13
args 1.6.0
async 2.4.1 2.4.2
boolean_selector 2.0.0
charcode 1.1.3
collection 1.14.12 1.14.13
convert 2.1.1
coverage 0.13.11 0.14.0
crypto 2.1.4 2.1.5
csslib 0.16.1
file 5.1.0 5.2.1
fuchsia_remote_debug_protocol 0.0.0
html 0.14.0+3
http 0.12.1
http_multi_server 2.2.0
http_parser 3.1.4
image 2.1.12 2.1.14
intl 0.16.1
io 0.3.4
js 0.6.2
json_rpc_2 2.1.0 2.2.1
logging 0.11.4
matcher 0.12.6 0.12.8
meta 1.1.8 1.2.1
mime 0.9.6+3
multi_server_socket 1.0.2
node_interop 1.1.1
node_io 1.1.1
node_preamble 1.4.12
package_config 1.9.3
pedantic 1.9.0 1.9.1
petitparser 2.4.0 3.0.4
platform 2.2.1
pool 1.4.0
process 3.0.12 3.0.13
pub_semver 1.4.4
quiver 2.1.3
shelf 0.7.7
shelf_packages_handler 2.0.0
shelf_static 0.2.8
shelf_web_socket 0.2.3
sky_engine 0.0.99
source_map_stack_trace 2.0.0
source_maps 0.10.9
source_span 1.7.0
stack_trace 1.9.3 1.9.5
stream_channel 2.0.0
string_scanner 1.0.5
sync_http 0.2.0
term_glyph 1.1.0
test 1.14.4 1.15.2
test_api 0.2.15 0.2.17
test_core 0.3.4 0.3.10
typed_data 1.1.6 1.2.0
vector_math 2.0.8
vm_service 4.1.0
vm_service_client 0.2.6+2 0.2.6+3
watcher 0.9.7+15
web_socket_channel 1.1.0
webdriver 2.1.2
webkit_inspection_protocol 0.7.3
xml 3.6.1 4.2.0
Dev dependencies
flutter_test 0.0.0