Skip to content

jerseysu/flutter_bdd

Repository files navigation

flutter_bdd

Sample Project for Flutter + flutter_gherkin demo

jerseysu

The sample project is based on following instruction:

Requirements

flutter_gherkin Installation:

Setup flutter_gherkin into pubspec.yaml dependencies:

dependencies:
    flutter_gherkin: ^1.1.9

Adding a package dependency to an app:

# Install
$ flutter pub get

Execution Test:

Execute target to iOS / Android:

  • Use flutter devices to get target device id
# run flutter devices
$ flutter devices
Ex: (Android), default empty string
..targetDeviceId = "emulator-5554"
  • Execute command line with target devices
# execute command line
$ dart test_driver/app_test.dart

or 

$ flutter drive --target=test_driver/app.dart

Useful Sample:

  • Page Object Patterns
class LandingPage extends BasePage {

  final landingPageTitle = 'firstTabTitle';

  LandingPage(FlutterDriver driver) : super(driver) {
    final locator = super.finElementByKey(landingPageTitle);
    BasePage.waitFor(driver, locator);
  }

  Future<void> doSomething(FlutterWorld world) async {
    // doSomehting

  }
}
  • Step Definition
import '../pages/landing_page.dart';

class TapButtonNTimesStep extends When2WithWorld<String, int, FlutterWorld> {
  TapButtonNTimesStep()
      : super(StepDefinitionConfiguration()..timeout = Duration(seconds: 30));

  @override
  Future<void> executeStep(String key, int times) async {
    final landingPage = new LandingPage(world.driver);
    await landingPage.tapPlusOneBtnForNTimes(key, times, world);
  }

  @override
  RegExp get pattern => RegExp(r"I tap the {string} button {int} times");
}

  • Test Report
  1. Install npm package cucumber-html-reporter
# Install cucumber-html-reporter
$ npm install cucumber-html-reporter
  1. Display Report
# Go to report folder
$ cd report

# Display Report
$ node index.js

Documentation:

Blog: - Gherkin with Flutter

Author

Jersey Su – @jerseysu