feat(flutter): added ability to change flutter build timeout and now logging flutter command run

This commit is contained in:
Jon Samwell 2019-09-26 08:00:06 +10:00
parent 976579082b
commit 76e6a841e0
8 changed files with 56 additions and 12 deletions

View File

@ -1,3 +1,7 @@
## [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.
* Now logging the flutter driver command used when the configuration setting `logFlutterProcessOutput` is true
## [1.1.3] - 25/09/2019 ## [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). * 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).
* FlutterWorld - added missing `super.dispose()` call * FlutterWorld - added missing `super.dispose()` call

View File

@ -40,6 +40,8 @@ Available as a Dart package https://pub.dartlang.org/packages/flutter_gherkin
- [hooks](#hooks) - [hooks](#hooks)
- [reporters](#reporters) - [reporters](#reporters)
- [createWorld](#createworld) - [createWorld](#createworld)
- [logFlutterProcessOutput](#logFlutterProcessOutput)
- [flutterBuildTimeout](#flutterBuildTimeout)
- [exitAfterTestRun](#exitaftertestrun) - [exitAfterTestRun](#exitaftertestrun)
- [Flutter specific configuration options](#flutter-specific-configuration-options) - [Flutter specific configuration options](#flutter-specific-configuration-options)
- [restartAppBetweenScenarios](#restartappbetweenscenarios) - [restartAppBetweenScenarios](#restartappbetweenscenarios)
@ -432,6 +434,18 @@ Future<void> main() {
} }
``` ```
#### logFlutterProcessOutput
Defaults to `false`
If `true` the output from the flutter process is logged to the stdout / stderr streams. Useful when debugging app build or start failures
#### flutterBuildTimeout
Defaults to `90 seconds`
Specifies the period of time to wait for the Flutter build to complete and the app to be installed and in a state to be tested. Slower machines may need longer than the default 90 seconds to complete this process.
#### exitAfterTestRun #### exitAfterTestRun
Defaults to `true` Defaults to `true`

File diff suppressed because one or more lines are too long

View File

@ -32,6 +32,7 @@ Future<void> main() {
// ..targetDeviceId = "all" // uncomment to run tests on all connected devices or set specific device target id // ..targetDeviceId = "all" // uncomment to run tests on all connected devices or set specific device target id
// ..tagExpression = "@smoke" // uncomment to see an example of running scenarios based on tag expressions // ..tagExpression = "@smoke" // uncomment to see an example of running scenarios based on tag expressions
// ..logFlutterProcessOutput = true // uncomment to see the output from the Flutter process // ..logFlutterProcessOutput = true // uncomment to see the output from the Flutter process
// ..flutterBuildTimeout = Duration(minutes: 3) // uncomment to change the default period that flutter is expected to build and start the app within
..exitAfterTestRun = true; // set to false if debugging to exit cleanly ..exitAfterTestRun = true; // set to false if debugging to exit cleanly
return GherkinRunner().execute(config); return GherkinRunner().execute(config);
} }

View File

@ -72,8 +72,18 @@ class FlutterRunProcessHandler extends ProcessHandler {
arguments.add("--device-id=$_deviceTargetId"); arguments.add("--device-id=$_deviceTargetId");
} }
_runningProcess = await Process.start("flutter", arguments, if (_logFlutterProcessOutput) {
workingDirectory: _workingDirectory, runInShell: true); stdout.writeln(
'Invoking from working directory `${_workingDirectory ?? './'}` command: `flutter ${arguments.join(' ')}`');
}
_runningProcess = await Process.start(
"flutter",
arguments,
workingDirectory: _workingDirectory,
runInShell: true,
);
_processStdoutStream = _processStdoutStream =
_runningProcess.stdout.transform(utf8.decoder).asBroadcastStream(); _runningProcess.stdout.transform(utf8.decoder).asBroadcastStream();
@ -123,10 +133,13 @@ class FlutterRunProcessHandler extends ProcessHandler {
return Future.value(true); return Future.value(true);
} }
Future<String> waitForObservatoryDebuggerUri() async { Future<String> waitForObservatoryDebuggerUri(
[Duration timeout = const Duration(seconds: 90)]) async {
currentObservatoryUri = await _waitForStdOutMessage( currentObservatoryUri = await _waitForStdOutMessage(
_observatoryDebuggerUriRegex, _observatoryDebuggerUriRegex,
"Timeout while waiting for observatory debugger uri"); "Timeout while waiting for observatory debugger uri",
timeout,
);
return currentObservatoryUri; return currentObservatoryUri;
} }

View File

@ -44,6 +44,11 @@ class FlutterTestConfiguration extends TestConfiguration {
/// The output may contain build and run information /// The output may contain build and run information
bool logFlutterProcessOutput = false; bool logFlutterProcessOutput = false;
/// Duration to wait for Flutter to build and start the app on the target device
/// Slower machine may take longer to build and run a large app
/// Defaults to 90 seconds
Duration flutterBuildTimeout = Duration(seconds: 90);
void setObservatoryDebuggerUri(String uri) => _observatoryDebuggerUri = uri; void setObservatoryDebuggerUri(String uri) => _observatoryDebuggerUri = uri;
Future<FlutterDriver> createFlutterDriver([String dartVmServiceUrl]) async { Future<FlutterDriver> createFlutterDriver([String dartVmServiceUrl]) async {

View File

@ -25,7 +25,9 @@ class FlutterAppRunnerHook extends Hook {
@override @override
Future<void> onBeforeScenario( Future<void> onBeforeScenario(
TestConfiguration config, String scenario) async { TestConfiguration config,
String scenario,
) async {
final flutterConfig = _castConfig(config); final flutterConfig = _castConfig(config);
if (_flutterRunProcessHandler == null) { if (_flutterRunProcessHandler == null) {
await _runApp(flutterConfig); await _runApp(flutterConfig);
@ -34,7 +36,9 @@ class FlutterAppRunnerHook extends Hook {
@override @override
Future<void> onAfterScenario( Future<void> onAfterScenario(
TestConfiguration config, String scenario) async { TestConfiguration config,
String scenario,
) async {
final flutterConfig = _castConfig(config); final flutterConfig = _castConfig(config);
haveRunFirstScenario = true; haveRunFirstScenario = true;
if (_flutterRunProcessHandler != null && if (_flutterRunProcessHandler != null &&
@ -44,7 +48,10 @@ class FlutterAppRunnerHook extends Hook {
} }
@override @override
Future<void> onAfterScenarioWorldCreated(World world, String scenario) async { Future<void> onAfterScenarioWorldCreated(
World world,
String scenario,
) async {
if (world is FlutterWorld) { if (world is FlutterWorld) {
world.setFlutterProccessHandler(_flutterRunProcessHandler); world.setFlutterProccessHandler(_flutterRunProcessHandler);
} }
@ -64,8 +71,8 @@ class FlutterAppRunnerHook extends Hook {
stdout.writeln( stdout.writeln(
"Starting Flutter app under test '${config.targetAppPath}', this might take a few moments"); "Starting Flutter app under test '${config.targetAppPath}', this might take a few moments");
await _flutterRunProcessHandler.run(); await _flutterRunProcessHandler.run();
final observatoryUri = final observatoryUri = await _flutterRunProcessHandler
await _flutterRunProcessHandler.waitForObservatoryDebuggerUri(); .waitForObservatoryDebuggerUri(config.flutterBuildTimeout);
config.setObservatoryDebuggerUri(observatoryUri); config.setObservatoryDebuggerUri(observatoryUri);
} }

View File

@ -1,6 +1,6 @@
name: flutter_gherkin name: flutter_gherkin
description: A Gherkin / Cucumber parser and test runner for Dart and Flutter description: A Gherkin / Cucumber parser and test runner for Dart and Flutter
version: 1.1.3 version: 1.1.4
author: Jon Samwell <jonsamwell@gmail.com> author: Jon Samwell <jonsamwell@gmail.com>
homepage: https://github.com/jonsamwell/flutter_gherkin homepage: https://github.com/jonsamwell/flutter_gherkin