This commit is contained in:
Tim Shedor 2020-06-07 12:40:29 -07:00
parent b37cb05c12
commit 72aa1cd59e
10 changed files with 54 additions and 33 deletions

View File

@ -96,8 +96,8 @@ class FlutterTestConfiguration extends TestConfiguration {
Future<FlutterDriver> createFlutterDriver([String dartVmServiceUrl]) async {
final completer = Completer<FlutterDriver>();
dartVmServiceUrl =
(dartVmServiceUrl ?? _observatoryDebuggerUri) ?? Platform.environment['VM_SERVICE_URL'];
dartVmServiceUrl = (dartVmServiceUrl ?? _observatoryDebuggerUri) ??
Platform.environment['VM_SERVICE_URL'];
await runZonedGuarded(
() async {
@ -155,11 +155,12 @@ class FlutterTestConfiguration extends TestConfiguration {
};
hooks = List.from(hooks ?? [])..add(FlutterAppRunnerHook());
customStepParameterDefinitions = List.from(customStepParameterDefinitions ?? [])
..addAll([
ExistenceParameter(),
SwipeDirectionParameter(),
]);
customStepParameterDefinitions =
List.from(customStepParameterDefinitions ?? [])
..addAll([
ExistenceParameter(),
SwipeDirectionParameter(),
]);
stepDefinitions = List.from(stepDefinitions ?? [])
..addAll([
ThenExpectElementToHaveValue(),
@ -213,7 +214,8 @@ class FlutterTestConfiguration extends TestConfiguration {
}
void _ensureCorrectConfiguration() {
if (runningAppProtocolEndpointUri != null && runningAppProtocolEndpointUri.isNotEmpty) {
if (runningAppProtocolEndpointUri != null &&
runningAppProtocolEndpointUri.isNotEmpty) {
if (restartAppBetweenScenarios) {
throw AssertionError(
'Cannot restart app between scenarios if using runningAppProtocolEndpointUri');

View File

@ -13,9 +13,11 @@ import 'package:gherkin/gherkin.dart';
/// Examples:
///
/// `Then I expect a "Row" that contains the text "X" to also contain the text "Y"`
class SiblingContainsTextStep extends When3WithWorld<String, String, String, FlutterWorld> {
class SiblingContainsTextStep
extends When3WithWorld<String, String, String, FlutterWorld> {
@override
Future<void> executeStep(String ancestorType, String leadingText, String valueText) async {
Future<void> executeStep(
String ancestorType, String leadingText, String valueText) async {
final ancestor = await find.ancestor(
of: find.text(leadingText),
matching: find.byType(ancestorType),

View File

@ -5,12 +5,14 @@ import 'package:gherkin/gherkin.dart';
import '../parameters/swipe_direction_parameter.dart';
mixin _SwipeHelper on When3WithWorld<SwipeDirection, int, String, FlutterWorld> {
mixin _SwipeHelper
on When3WithWorld<SwipeDirection, int, String, FlutterWorld> {
@protected
Future<void> swipeOnFinder(
SerializableFinder finder, SwipeDirection direction, int swipeAmount) async {
Future<void> swipeOnFinder(SerializableFinder finder,
SwipeDirection direction, int swipeAmount) async {
if (direction == SwipeDirection.left || direction == SwipeDirection.right) {
final offset = direction == SwipeDirection.right ? swipeAmount : (swipeAmount * -1);
final offset =
direction == SwipeDirection.right ? swipeAmount : (swipeAmount * -1);
await world.driver.scroll(
finder,
@ -20,7 +22,8 @@ mixin _SwipeHelper on When3WithWorld<SwipeDirection, int, String, FlutterWorld>
timeout: timeout,
);
} else {
final offset = direction == SwipeDirection.up ? swipeAmount : (swipeAmount * -1);
final offset =
direction == SwipeDirection.up ? swipeAmount : (swipeAmount * -1);
await world.driver.scroll(
finder,
@ -39,16 +42,19 @@ mixin _SwipeHelper on When3WithWorld<SwipeDirection, int, String, FlutterWorld>
///
/// `Then I swipe up by 800 pixels on the "login_screen"`
/// `Then I swipe left by 200 pixels on the "dismissible_list_item"`
class SwipeOnKeyStep extends When3WithWorld<SwipeDirection, int, String, FlutterWorld>
class SwipeOnKeyStep
extends When3WithWorld<SwipeDirection, int, String, FlutterWorld>
with _SwipeHelper {
@override
Future<void> executeStep(SwipeDirection direction, int swipeAmount, String key) async {
Future<void> executeStep(
SwipeDirection direction, int swipeAmount, String key) async {
final finder = find.byValueKey(key);
await swipeOnFinder(finder, direction, swipeAmount);
}
@override
RegExp get pattern => RegExp(r'I swipe {swipe_direction} by {int} pixels on the {string}$');
RegExp get pattern =>
RegExp(r'I swipe {swipe_direction} by {int} pixels on the {string}$');
}
/// Swipes in a cardinal direction on a widget discovered by its test.
@ -56,10 +62,12 @@ class SwipeOnKeyStep extends When3WithWorld<SwipeDirection, int, String, Flutter
/// Examples:
///
/// `Then I swipe left by 400 pixels on the widget that contains the text "Dismiss Me"`
class SwipeOnTextStep extends When3WithWorld<SwipeDirection, int, String, FlutterWorld>
class SwipeOnTextStep
extends When3WithWorld<SwipeDirection, int, String, FlutterWorld>
with _SwipeHelper {
@override
Future<void> executeStep(SwipeDirection direction, int swipeAmount, String text) async {
Future<void> executeStep(
SwipeDirection direction, int swipeAmount, String text) async {
final finder = find.text(text);
await swipeOnFinder(finder, direction, swipeAmount);
}

View File

@ -8,7 +8,8 @@ import 'package:gherkin/gherkin.dart';
/// Examples:
///
/// `Then I tap the label that contains the text "Logout" within the "user_settings_list"`
class TapTextWithinWidgetStep extends When2WithWorld<String, String, FlutterWorld> {
class TapTextWithinWidgetStep
extends When2WithWorld<String, String, FlutterWorld> {
@override
Future<void> executeStep(String text, String ancestorKey) async {
final finder = find.descendant(

View File

@ -20,6 +20,6 @@ class TapWidgetOfTypeStep extends When1WithWorld<String, FlutterWorld> {
}
@override
RegExp get pattern =>
RegExp(r'I tap the (?:button|element|label|icon|field|text|widget) of type {string}$');
RegExp get pattern => RegExp(
r'I tap the (?:button|element|label|icon|field|text|widget) of type {string}$');
}

View File

@ -7,7 +7,8 @@ import 'package:gherkin/gherkin.dart';
/// Examples:
///
/// `Then I tap the element of type "MaterialButton" within the "user_settings_list"`
class TapWidgetOfTypeWithinStep extends When2WithWorld<String, String, FlutterWorld> {
class TapWidgetOfTypeWithinStep
extends When2WithWorld<String, String, FlutterWorld> {
@override
Future<void> executeStep(String widgetType, String ancestorKey) async {
final finder = find.descendant(

View File

@ -32,5 +32,6 @@ class TextExistsStep extends When2WithWorld<String, Existence, FlutterWorld> {
}
@override
RegExp get pattern => RegExp(r'I expect the text {string} to be {existence}$');
RegExp get pattern =>
RegExp(r'I expect the text {string} to be {existence}$');
}

View File

@ -10,9 +10,11 @@ import '../parameters/existence_parameter.dart';
///
/// `Then I expect the text "Logout" to be present within the "user_settings_list"`
/// `But I expect the text "Signup" to be absent within the "login_screen"`
class TextExistsWithinStep extends When3WithWorld<String, Existence, String, FlutterWorld> {
class TextExistsWithinStep
extends When3WithWorld<String, Existence, String, FlutterWorld> {
@override
Future<void> executeStep(String text, Existence exists, String ancestorKey) async {
Future<void> executeStep(
String text, Existence exists, String ancestorKey) async {
final finder = find.descendant(
of: find.byValueKey(ancestorKey),
matching: find.text(text),
@ -28,6 +30,6 @@ class TextExistsWithinStep extends When3WithWorld<String, Existence, String, Flu
}
@override
RegExp get pattern =>
RegExp(r'I expect the text {string} to be {existence} within the {string}$');
RegExp get pattern => RegExp(
r'I expect the text {string} to be {existence} within the {string}$');
}

View File

@ -10,15 +10,18 @@ import '../parameters/existence_parameter.dart';
///
/// `Then I wait until the "login_loading_indicator" is absent`
/// `And I wait until the "login_screen" is present`
class WaitUntilKeyExistsStep extends When2WithWorld<String, Existence, FlutterWorld> {
class WaitUntilKeyExistsStep
extends When2WithWorld<String, Existence, FlutterWorld> {
@override
Future<void> executeStep(String keyString, Existence existence) async {
await FlutterDriverUtils.waitUntil(
world.driver,
() {
return existence == Existence.absent
? FlutterDriverUtils.isAbsent(world.driver, find.byValueKey(keyString))
: FlutterDriverUtils.isPresent(world.driver, find.byValueKey(keyString));
? FlutterDriverUtils.isAbsent(
world.driver, find.byValueKey(keyString))
: FlutterDriverUtils.isPresent(
world.driver, find.byValueKey(keyString));
},
timeout: timeout,
);

View File

@ -10,7 +10,8 @@ import '../parameters/existence_parameter.dart';
///
/// `Then I wait until the element of type "ProgressIndicator" is absent`
/// `And I wait until the button of type the "MaterialButton" is present`
class WaitUntilTypeExistsStep extends When2WithWorld<String, Existence, FlutterWorld> {
class WaitUntilTypeExistsStep
extends When2WithWorld<String, Existence, FlutterWorld> {
@override
Future<void> executeStep(String ofType, Existence existence) async {
await FlutterDriverUtils.waitUntil(