fix(hook): ensured `AttachScreenshotOnFailedStepHook` cannot throw an unhandled exception causing the test run to stop

This commit is contained in:
Jon Samwell 2020-01-08 09:14:35 +11:00
parent ff539c0a58
commit 32018a4cc8
2 changed files with 11 additions and 3 deletions

View File

@ -1,5 +1,6 @@
## [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
## [1.1.7+2] - 07/01/2019
* Increased the Flutter driver reconnection delay to try and overcome some driver to app connection issues on slower machines

View File

@ -7,12 +7,19 @@ import '../flutter_world.dart';
class AttachScreenshotOnFailedStepHook extends Hook {
@override
Future<void> onAfterStep(
World world, String step, StepResult stepResult) async {
World world,
String step,
StepResult stepResult,
) async {
if (stepResult.result == StepExecutionResult.fail ||
stepResult.result == StepExecutionResult.error ||
stepResult.result == StepExecutionResult.timeout) {
final screenshotData = await takeScreenshot(world);
world.attach(screenshotData, 'image/png', step);
try {
final screenshotData = await takeScreenshot(world);
world.attach(screenshotData, 'image/png', step);
} catch (e, st) {
world.attach('Failed to take screenshot\n$e\n$st', 'text/plain', step);
}
}
}