Add utility method to fill text fields in a form

This commit is contained in:
Efthymis Sarmpanis 2019-06-16 13:50:06 +03:00
parent 7536f2ab3e
commit e0fe5bb635
3 changed files with 33 additions and 20 deletions

0
android/gradlew vendored Normal file → Executable file
View File

View File

@ -51,12 +51,11 @@ void main() {
test('Add a new product', () async { test('Add a new product', () async {
await driver.tap(find.byValueKey(ProductKeys.fab)); await driver.tap(find.byValueKey(ProductKeys.fab));
await driver.tap(find.byValueKey(ProductKeys.productKey)); await fillTextFields(driver, <String, dynamic>{
await driver.enterText(productKey); ProductKeys.productKey: productKey,
await driver.tap(find.byValueKey(ProductKeys.notes)); ProductKeys.notes: notes,
await driver.enterText(notes); ProductKeys.cost: cost,
await driver.tap(find.byValueKey(ProductKeys.cost)); });
await driver.enterText(cost);
await driver.tap(find.byTooltip(localization.save)); await driver.tap(find.byTooltip(localization.save));
@ -79,12 +78,11 @@ void main() {
await driver.scrollUntilVisible(find.byType('ListView'), find.text(productKey)); await driver.scrollUntilVisible(find.byType('ListView'), find.text(productKey));
await driver.tap(find.text(productKey), timeout: Duration(seconds: 3)); await driver.tap(find.text(productKey), timeout: Duration(seconds: 3));
await driver.tap(find.byValueKey(ProductKeys.productKey)); await fillTextFields(driver, <String, dynamic>{
await driver.enterText(updatedProductKey); ProductKeys.productKey: updatedProductKey,
await driver.tap(find.byValueKey(ProductKeys.notes)); ProductKeys.notes: updatedNotes,
await driver.enterText(updatedNotes); ProductKeys.cost: updatedCost,
await driver.tap(find.byValueKey(ProductKeys.cost)); });
await driver.enterText(updatedCost);
await driver.tap(find.byTooltip(localization.save)); await driver.tap(find.byTooltip(localization.save));

View File

@ -17,16 +17,16 @@ Future<void> login(FlutterDriver driver,
await driver.tap(find.byValueKey(LoginKeys.loginSelfHost)); await driver.tap(find.byValueKey(LoginKeys.loginSelfHost));
} }
await driver.tap(find.byValueKey(LoginKeys.email)); await fillTextFields(driver, <String, dynamic>{
await driver.enterText(loginEmail); LoginKeys.email: loginEmail,
await driver.tap(find.byValueKey(LoginKeys.password)); LoginKeys.password: loginPassword,
await driver.enterText(loginPassword); });
if (selfHosted) { if (selfHosted) {
await driver.tap(find.byValueKey(LoginKeys.url)); await fillTextFields(driver, <String, dynamic>{
await driver.enterText(loginUrl); LoginKeys.url: loginUrl,
await driver.tap(find.byValueKey(LoginKeys.secret)); LoginKeys.secret: loginSecret,
await driver.enterText(loginSecret); });
} }
await driver.tap(find.text(LoginKeys.loginButton.toUpperCase())); await driver.tap(find.text(LoginKeys.loginButton.toUpperCase()));
@ -56,3 +56,18 @@ Future<void> loginAndOpenProducts(FlutterDriver driver) async {
await driver.tap(find.byValueKey(ProductKeys.drawer)); await driver.tap(find.byValueKey(ProductKeys.drawer));
await driver.waitFor(find.byType(ProductKeys.screen)); await driver.waitFor(find.byType(ProductKeys.screen));
} }
Future<void> 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<void> fillTextFields(FlutterDriver driver, Map<String, dynamic> values) async {
for (var entry in values.entries) {
await driver.tap(find.byValueKey(entry.key));
await driver.enterText(entry.value);
}
}