Sample Project for Flutter + flutter_gherkin demo
The sample project is based on following instruction:
-
Flutter Developer Library: Hello World / Navigate to a new screen and back
-
flutter_gherkin sample: Flutter-Ghkerin Lib
- Flutter v2.0.1
- flutter_gherkin
- Xcode 12.2
- Android Studio 3.1.4
Setup flutter_gherkin into pubspec.yaml dependencies:
dependencies:
flutter_gherkin: ^1.1.9
Adding a package dependency to an app:
# Install
$ flutter pub get
- Use flutter devices to get target device id
# run flutter devices
$ flutter devices
- Config targetDeviceId in app_test.dart
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
- 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
- Install npm package
cucumber-html-reporter
# Install cucumber-html-reporter
$ npm install cucumber-html-reporter
- Display Report
# Go to report folder
$ cd report
# Display Report
$ node index.js
Blog: - Gherkin with Flutter
Jersey Su – @jerseysu