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
* 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

View File

@ -40,6 +40,8 @@ Available as a Dart package https://pub.dartlang.org/packages/flutter_gherkin
- [hooks](#hooks)
- [reporters](#reporters)
- [createWorld](#createworld)
- [logFlutterProcessOutput](#logFlutterProcessOutput)
- [flutterBuildTimeout](#flutterBuildTimeout)
- [exitAfterTestRun](#exitaftertestrun)
- [Flutter specific configuration options](#flutter-specific-configuration-options)
- [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
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
// ..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
// ..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
return GherkinRunner().execute(config);
}

View File

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

View File

@ -44,6 +44,11 @@ class FlutterTestConfiguration extends TestConfiguration {
/// The output may contain build and run information
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;
Future<FlutterDriver> createFlutterDriver([String dartVmServiceUrl]) async {

View File

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

View File

@ -1,6 +1,6 @@
name: flutter_gherkin
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>
homepage: https://github.com/jonsamwell/flutter_gherkin