fix(process): updated no devices check

fix(process): update check to determine if the app is ready if flutter process has verbose output on
This commit is contained in:
Jon Samwell 2020-01-31 18:38:24 +11:00
parent af1a3c7ec8
commit 70c6eec25f
6 changed files with 55 additions and 32 deletions

View File

@ -1,3 +1,7 @@
## [1.1.7+4] - 31/01/2019
* Update check to determine if any devices are connected to run tests against
* When the flag `verboseFlutterProcessLogs` was true Flutter driver was preemptively connecting to the app when it was not ready
## [1.1.7+3] - 08/01/2019
* Added retry logic to the Futter driver connect call to handle the seemingly random connection failures
* Ensured `AttachScreenshotOnFailedStepHook` cannot throw an unhandled exception causing the test run to stop

View File

@ -21,8 +21,9 @@ Future<void> main() {
),
] // you can include the "StdoutReporter()" without the message level parameter for verbose log information
..hooks = [
HookExample()
] // you can include "AttachScreenshotOnFailedStepHook()" to take a screenshot of each step failure and attach it to the world object
HookExample(),
// AttachScreenshotOnFailedStepHook(), // takes a screenshot of each step failure and attaches it to the world object
]
..stepDefinitions = [
TapButtonNTimesStep(),
GivenIPickAColour(),
@ -36,7 +37,8 @@ Future<void> main() {
// ..buildFlavor = "staging" // uncomment when using build flavor and check android/ios flavor setup see android file android\app\build.gradle
// ..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
// ..logFlutterProcessOutput = true // uncomment to see command invoked to start the flutter test app
// ..verboseFlutterProcessLogs = true // uncomment to see the verbose 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);

File diff suppressed because one or more lines are too long

View File

@ -8,28 +8,37 @@ class FlutterRunProcessHandler extends ProcessHandler {
static const String WARN_COLOR = "\u001b[33;10m"; // yellow
static const String RESET_COLOR = "\u001b[33;0m";
// the flutter process usually outputs something like the below to indicate the app is ready to be connected to
// `An Observatory debugger and profiler on AOSP on IA Emulator is available at: http://127.0.0.1:51322/BI_fyYaeoCE=/`
static RegExp _observatoryDebuggerUriRegex = RegExp(
r"observatory (?:debugger|url) .*[:]? (http[s]?:.*\/).*",
caseSensitive: false,
multiLine: false);
r"observatory (?:debugger|url) .* available .*[:]? (http[s]?:.*\/).*",
caseSensitive: false,
multiLine: false,
);
static RegExp _noConnectedDeviceRegex =
RegExp(r"no connected device", caseSensitive: false, multiLine: false);
static RegExp _noConnectedDeviceRegex = RegExp(
r"no connected device|no supported devices connected",
caseSensitive: false,
multiLine: false,
);
static RegExp _moreThanOneDeviceConnectedDeviceRegex = RegExp(
r"more than one device connected",
caseSensitive: false,
multiLine: false);
r"more than one device connected",
caseSensitive: false,
multiLine: false,
);
static RegExp _errorMessageRegex = RegExp(
r"aborted|error|failure|unexpected|failed|exception",
caseSensitive: false,
multiLine: false);
r"aborted|error|failure|unexpected|failed|exception",
caseSensitive: false,
multiLine: false,
);
static RegExp _restartedApplicationSuccessRegex = RegExp(
r"Restarted application (.*)ms.",
caseSensitive: false,
multiLine: false);
r"Restarted application (.*)ms.",
caseSensitive: false,
multiLine: false,
);
Process _runningProcess;
Stream<String> _processStdoutStream;
@ -98,7 +107,8 @@ class FlutterRunProcessHandler extends ProcessHandler {
if (_logFlutterProcessOutput) {
stdout.writeln(
'Invoking from working directory `${_workingDirectory ?? './'}` command: `flutter ${arguments.join(' ')}`');
'Invoking from working directory `${_workingDirectory ?? './'}` command: `flutter ${arguments.join(' ')}`',
);
}
_runningProcess = await Process.start(
@ -156,8 +166,9 @@ class FlutterRunProcessHandler extends ProcessHandler {
return Future.value(true);
}
Future<String> waitForObservatoryDebuggerUri(
[Duration timeout = const Duration(seconds: 90)]) async {
Future<String> waitForObservatoryDebuggerUri([
Duration timeout = const Duration(seconds: 90),
]) async {
currentObservatoryUri = await _waitForStdOutMessage(
_observatoryDebuggerUriRegex,
"Timeout while waiting for observatory debugger uri",
@ -167,17 +178,23 @@ class FlutterRunProcessHandler extends ProcessHandler {
return currentObservatoryUri;
}
Future<String> _waitForStdOutMessage(RegExp matcher, String timeoutMessage,
[Duration timeout = const Duration(seconds: 90)]) {
Future<String> _waitForStdOutMessage(
RegExp matcher,
String timeoutMessage, [
Duration timeout = const Duration(seconds: 90),
]) {
_ensureRunningProcess();
final completer = Completer<String>();
StreamSubscription sub;
sub = _processStdoutStream.timeout(timeout, onTimeout: (_) {
sub?.cancel();
if (!completer.isCompleted) {
completer.completeError(TimeoutException(timeoutMessage, timeout));
}
}).listen(
sub = _processStdoutStream.timeout(
timeout,
onTimeout: (_) {
sub?.cancel();
if (!completer.isCompleted) {
completer.completeError(TimeoutException(timeoutMessage, timeout));
}
},
).listen(
(logLine) {
if (_logFlutterProcessOutput) {
stdout.write(logLine);

View File

@ -70,7 +70,7 @@ packages:
name: coverage
url: "https://pub.dartlang.org"
source: hosted
version: "0.13.3+3"
version: "0.13.4"
crypto:
dependency: transitive
description:
@ -195,7 +195,7 @@ packages:
name: logging
url: "https://pub.dartlang.org"
source: hosted
version: "0.11.3+2"
version: "0.11.4"
matcher:
dependency: transitive
description:

View File

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