From 32018a4cc8fcedeb4c1e0637735468ae0e946c43 Mon Sep 17 00:00:00 2001 From: Jon Samwell Date: Wed, 8 Jan 2020 09:14:35 +1100 Subject: [PATCH] fix(hook): ensured `AttachScreenshotOnFailedStepHook` cannot throw an unhandled exception causing the test run to stop --- CHANGELOG.md | 1 + .../attach_screenshot_on_failed_step_hook.dart | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f3ae176..0ad5704 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/src/flutter/hooks/attach_screenshot_on_failed_step_hook.dart b/lib/src/flutter/hooks/attach_screenshot_on_failed_step_hook.dart index b2b3918..a00b2c3 100644 --- a/lib/src/flutter/hooks/attach_screenshot_on_failed_step_hook.dart +++ b/lib/src/flutter/hooks/attach_screenshot_on_failed_step_hook.dart @@ -7,12 +7,19 @@ import '../flutter_world.dart'; class AttachScreenshotOnFailedStepHook extends Hook { @override Future 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); + } } }