diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d4209f..7d0f6ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ -## [1.1.4] - 26/09/2019 -* Added configuration parameter `flutterBuildTimeout` to allow setting the app build wait timeout. Slower machine may need longer to build and start a Flutter app under test. +## [1.1.4] - 27/09/2019 +* Added configuration parameter `flutterBuildTimeout` to allow setting the app build wait timeout. Slower machines may need longer to build and start the Flutter app under test. * Now logging the flutter driver command used when the configuration setting `logFlutterProcessOutput` is true +* Verbose logging for the underlying Flutter process can be enabled via the configuration setting `verboseFlutterProcessLogs` +* Added `waitUntil` helper method to the `FlutterDriverUtils` class that waits until a certain provided condition is true ## [1.1.3] - 25/09/2019 * Added Flutter driver reporter - the Flutter Driver logs all messages (even non-error ones) to stderr and will cause the process to be marked as failed by a CI server becuase of this. So this reporter redirects the messages to the appropiate output stream (stdout / stderr). diff --git a/README.md b/README.md index 63ed7dd..75106af 100644 --- a/README.md +++ b/README.md @@ -927,7 +927,7 @@ For convenience the library defines a number of pre-defined steps so you can get #### Flutter Driver Utilities -For convenience the library provides a static `FlutterDriverUtils` class that abstracts away some common Flutter driver functionality like tapping a button, getting and entering text, checking if an element is present or absent. See [lib/src/flutter/utils/driver_utils.dart](lib/src/flutter/utils/driver_utils.dart). +For convenience the library provides a static `FlutterDriverUtils` class that abstracts away some common Flutter driver functionality like tapping a button, getting and entering text, checking if an element is present or absent, waiting for a condition to become true. See [lib/src/flutter/utils/driver_utils.dart](lib/src/flutter/utils/driver_utils.dart). ### Debugging diff --git a/lib/src/flutter/utils/driver_utils.dart b/lib/src/flutter/utils/driver_utils.dart index 32a0e25..eeecae0 100644 --- a/lib/src/flutter/utils/driver_utils.dart +++ b/lib/src/flutter/utils/driver_utils.dart @@ -1,3 +1,5 @@ +import 'dart:async'; + import 'package:flutter_driver/flutter_driver.dart'; class FlutterDriverUtils { @@ -50,4 +52,31 @@ class FlutterDriverUtils { await driver.tap(finder, timeout: timeout); await FlutterDriverUtils.waitForFlutter(driver, timeout: timeout); } + + /// Waits until the [condition] returns true + /// Will raise a complete with a [TimeoutException] if the + /// condition does not return true with the timeout period. + static Future waitUntil( + FlutterDriver driver, + Future condition(), { + Duration timeout = const Duration(seconds: 10), + Duration pollInterval = const Duration(milliseconds: 500), + }) async { + return Future.microtask(() async { + final completer = Completer(); + int maxAttempts = + (timeout.inMilliseconds / pollInterval.inMilliseconds).round(); + int attempts = 0; + + while (attempts < maxAttempts) { + final result = await condition(); + if (result) { + completer.complete(); + break; + } else { + await Future.delayed(pollInterval); + } + } + }).timeout(timeout); + } } diff --git a/pubspec.lock b/pubspec.lock index b92d200..36fe02f 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -104,7 +104,7 @@ packages: name: gherkin url: "https://pub.dartlang.org" source: hosted - version: "1.1.2" + version: "1.1.3" glob: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index d16e16e..c174fbe 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,7 +16,7 @@ dependencies: sdk: flutter glob: ^1.1.7 meta: ">=1.1.6 <2.0.0" - gherkin: ^1.1.2 + gherkin: ^1.1.3 dev_dependencies: test: ">=1.6.1 <1.7.0"