From e0fe5bb6359d08b560a7f0445a5cb66a5336b8af Mon Sep 17 00:00:00 2001 From: Efthymis Sarmpanis Date: Sun, 16 Jun 2019 13:50:06 +0300 Subject: [PATCH] Add utility method to fill text fields in a form --- android/gradlew | 0 test_driver/products_it_test.dart | 22 +++++++++---------- test_driver/utils/common_actions.dart | 31 ++++++++++++++++++++------- 3 files changed, 33 insertions(+), 20 deletions(-) mode change 100644 => 100755 android/gradlew diff --git a/android/gradlew b/android/gradlew old mode 100644 new mode 100755 diff --git a/test_driver/products_it_test.dart b/test_driver/products_it_test.dart index 9f34173c2..026ad0b5d 100644 --- a/test_driver/products_it_test.dart +++ b/test_driver/products_it_test.dart @@ -51,12 +51,11 @@ void main() { test('Add a new product', () async { await driver.tap(find.byValueKey(ProductKeys.fab)); - await driver.tap(find.byValueKey(ProductKeys.productKey)); - await driver.enterText(productKey); - await driver.tap(find.byValueKey(ProductKeys.notes)); - await driver.enterText(notes); - await driver.tap(find.byValueKey(ProductKeys.cost)); - await driver.enterText(cost); + await fillTextFields(driver, { + ProductKeys.productKey: productKey, + ProductKeys.notes: notes, + ProductKeys.cost: cost, + }); await driver.tap(find.byTooltip(localization.save)); @@ -79,12 +78,11 @@ void main() { await driver.scrollUntilVisible(find.byType('ListView'), find.text(productKey)); await driver.tap(find.text(productKey), timeout: Duration(seconds: 3)); - await driver.tap(find.byValueKey(ProductKeys.productKey)); - await driver.enterText(updatedProductKey); - await driver.tap(find.byValueKey(ProductKeys.notes)); - await driver.enterText(updatedNotes); - await driver.tap(find.byValueKey(ProductKeys.cost)); - await driver.enterText(updatedCost); + await fillTextFields(driver, { + ProductKeys.productKey: updatedProductKey, + ProductKeys.notes: updatedNotes, + ProductKeys.cost: updatedCost, + }); await driver.tap(find.byTooltip(localization.save)); diff --git a/test_driver/utils/common_actions.dart b/test_driver/utils/common_actions.dart index d823ca0b9..69a27298e 100644 --- a/test_driver/utils/common_actions.dart +++ b/test_driver/utils/common_actions.dart @@ -17,16 +17,16 @@ Future login(FlutterDriver driver, await driver.tap(find.byValueKey(LoginKeys.loginSelfHost)); } - await driver.tap(find.byValueKey(LoginKeys.email)); - await driver.enterText(loginEmail); - await driver.tap(find.byValueKey(LoginKeys.password)); - await driver.enterText(loginPassword); + await fillTextFields(driver, { + LoginKeys.email: loginEmail, + LoginKeys.password: loginPassword, + }); if (selfHosted) { - await driver.tap(find.byValueKey(LoginKeys.url)); - await driver.enterText(loginUrl); - await driver.tap(find.byValueKey(LoginKeys.secret)); - await driver.enterText(loginSecret); + await fillTextFields(driver, { + LoginKeys.url: loginUrl, + LoginKeys.secret: loginSecret, + }); } await driver.tap(find.text(LoginKeys.loginButton.toUpperCase())); @@ -55,4 +55,19 @@ Future loginAndOpenProducts(FlutterDriver driver) async { await driver.tap(find.byTooltip(AppKeys.openAppDrawer)); await driver.tap(find.byValueKey(ProductKeys.drawer)); await driver.waitFor(find.byType(ProductKeys.screen)); +} + +Future loginAndOpenClients(FlutterDriver driver) async { + login(driver); + await driver.waitFor(find.byType(AppKeys.dashboardScreen)); + await driver.tap(find.byTooltip(AppKeys.openAppDrawer)); + await driver.tap(find.byValueKey(ClientKeys.drawer)); + await driver.waitFor(find.byType(ClientKeys.screen)); +} + +Future fillTextFields(FlutterDriver driver, Map values) async { + for (var entry in values.entries) { + await driver.tap(find.byValueKey(entry.key)); + await driver.enterText(entry.value); + } } \ No newline at end of file