diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ad5704..d48cddd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## [1.1.7+3] - 08/01/2019 * Added retry logic to the Futter driver connect call to handle the seemingly random connection failures * Ensured `AttachScreenshotOnFailedStepHook` cannot throw an unhandled exception causing the test run to stop +* Added new well known step `When I tap the back button` which finds and taps the default page back button ## [1.1.7+2] - 07/01/2019 * Increased the Flutter driver reconnection delay to try and overcome some driver to app connection issues on slower machines diff --git a/README.md b/README.md index 46ad8eb..90515fc 100644 --- a/README.md +++ b/README.md @@ -924,6 +924,7 @@ For convenience the library defines a number of pre-defined steps so you can get | I (open\|close) the drawer | Opens or closes the application default drawer | `When I open the drawer`, `And I close the drawer`| | I pause for {int} seconds | Pauses the test execution for the given seconds. Only use in debug scenarios or to inspect the state of the app | `Then I pause for 20 seconds` | | I restart the app | Restarts the app under test | `Then I restart the app` | +| I tap the back button | Taps the page default back button widget | `Then I tap the back button` | #### Flutter Driver Utilities diff --git a/lib/src/flutter/steps/when_tap_the_back_button_step.dart b/lib/src/flutter/steps/when_tap_the_back_button_step.dart new file mode 100644 index 0000000..edb5dfc --- /dev/null +++ b/lib/src/flutter/steps/when_tap_the_back_button_step.dart @@ -0,0 +1,26 @@ +import 'package:flutter_gherkin/src/flutter/flutter_world.dart'; +import 'package:flutter_gherkin/src/flutter/utils/driver_utils.dart'; +import 'package:flutter_driver/flutter_driver.dart'; +import 'package:gherkin/gherkin.dart'; + +/// Taps the back button widget +/// +/// Examples: +/// +/// `When I tap the back button"` +/// `When I tap the back element"` +/// `When I tap the back widget"` +class WhenTapWidget extends When1WithWorld { + @override + RegExp get pattern => + RegExp(r"I tap the back button [button|element|widget]"); + + @override + Future executeStep(String key) async { + await FlutterDriverUtils.tap( + world.driver, + find.pageBack(), + timeout: timeout * .9, + ); + } +} diff --git a/lib/src/flutter/steps/when_tap_widget_step.dart b/lib/src/flutter/steps/when_tap_widget_step.dart index e602f6e..d266b1c 100644 --- a/lib/src/flutter/steps/when_tap_widget_step.dart +++ b/lib/src/flutter/steps/when_tap_widget_step.dart @@ -24,7 +24,10 @@ class WhenTapWidget extends When1WithWorld { @override Future executeStep(String key) async { - await FlutterDriverUtils.tap(world.driver, find.byValueKey(key), - timeout: timeout * .9); + await FlutterDriverUtils.tap( + world.driver, + find.byValueKey(key), + timeout: timeout * .9, + ); } }