feat(step): added new well known step to test it an element is present

This commit is contained in:
Jon Samwell 2020-01-11 18:54:07 +11:00
parent a8f294b034
commit 37b4054284
5 changed files with 41 additions and 6 deletions

View File

@ -2,6 +2,7 @@
* 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
* Added a new well known step `Then I expect the widget 'notification' to be present` which expects a widget with a given key to be present within 5 seconds
* Updated Gherkin library version
## [1.1.7+2] - 07/01/2019

View File

@ -12,6 +12,8 @@ import 'package:flutter_gherkin/src/flutter/steps/when_tap_the_back_button_step.
import 'package:flutter_driver/flutter_driver.dart';
import 'package:gherkin/gherkin.dart';
import 'steps/then_expect_widget_to_be_present_step.dart';
class FlutterTestConfiguration extends TestConfiguration {
String _observatoryDebuggerUri;
@ -102,6 +104,7 @@ class FlutterTestConfiguration extends TestConfiguration {
GivenOpenDrawer(),
WhenPauseStep(),
WhenFillFieldStep(),
ThenExpectWidgetToBePresent(),
RestartAppStep()
]);
}

View File

@ -0,0 +1,28 @@
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';
/// Expects a widget with the given key to be present within 5 seconds
///
/// Parameters:
/// 1 - {string} the control key
///
/// Examples:
///
/// `Then I expect the widget 'notification' to be present`
/// `Then I expect the button 'save' to be present`
class ThenExpectWidgetToBePresent extends When1WithWorld<String, FlutterWorld> {
@override
RegExp get pattern => RegExp(
r"I expect the [button|element|label|icon|field|text|widget] {string} to be present");
@override
Future<void> executeStep(String key) async {
await FlutterDriverUtils.isPresent(
find.byValueKey(key),
world.driver,
timeout: const Duration(seconds: 5),
);
}
}

View File

@ -12,8 +12,7 @@ import 'package:gherkin/gherkin.dart';
/// `When I tap the back widget"`
class WhenTapBackButtonWidget extends WhenWithWorld<FlutterWorld> {
@override
RegExp get pattern =>
RegExp(r"I tap the back [button|element|widget]");
RegExp get pattern => RegExp(r"I tap the back [button|element|widget]");
@override
Future<void> executeStep() async {

View File

@ -3,6 +3,7 @@ import 'package:flutter_gherkin/src/flutter/hooks/app_runner_hook.dart';
import 'package:flutter_gherkin/src/flutter/steps/given_i_open_the_drawer_step.dart';
import 'package:flutter_gherkin/src/flutter/steps/restart_app_step.dart';
import 'package:flutter_gherkin/src/flutter/steps/then_expect_element_to_have_value_step.dart';
import 'package:flutter_gherkin/src/flutter/steps/then_expect_widget_to_be_present_step.dart';
import 'package:flutter_gherkin/src/flutter/steps/when_fill_field_step.dart';
import 'package:flutter_gherkin/src/flutter/steps/when_pause_step.dart';
import 'package:flutter_gherkin/src/flutter/steps/when_tap_the_back_button_step.dart';
@ -29,17 +30,20 @@ void main() {
config.prepare();
expect(config.stepDefinitions, isNotNull);
expect(config.stepDefinitions.length, 7);
expect(config.stepDefinitions.length, 8);
expect(config.stepDefinitions.elementAt(0),
(x) => x is ThenExpectElementToHaveValue);
expect(config.stepDefinitions.elementAt(1), (x) => x is WhenTapWidget);
expect(config.stepDefinitions.elementAt(2), (x) => x is WhenTapBackButtonWidget);
expect(config.stepDefinitions.elementAt(2),
(x) => x is WhenTapBackButtonWidget);
expect(
config.stepDefinitions.elementAt(3), (x) => x is GivenOpenDrawer);
expect(config.stepDefinitions.elementAt(4), (x) => x is WhenPauseStep);
expect(
config.stepDefinitions.elementAt(5), (x) => x is WhenFillFieldStep);
expect(config.stepDefinitions.elementAt(6), (x) => x is RestartAppStep);
expect(config.stepDefinitions.elementAt(6),
(x) => x is ThenExpectWidgetToBePresent);
expect(config.stepDefinitions.elementAt(7), (x) => x is RestartAppStep);
});
test("common step definition added to existing steps", () {
@ -49,7 +53,7 @@ void main() {
config.prepare();
expect(config.stepDefinitions, isNotNull);
expect(config.stepDefinitions.length, 8);
expect(config.stepDefinitions.length, 9);
expect(config.stepDefinitions.elementAt(0),
(x) => x is MockStepDefinition);
expect(config.stepDefinitions.elementAt(1),