Skip to content

Commit

Permalink
- Fix #235 - fix issue taking a screenshot on an Android device
Browse files Browse the repository at this point in the history
  - Resolved #170: Added example code to ensure json report is save to disk even when the test run fails. Also added script to generate a HTML report from a JSON report
  • Loading branch information
jonsamwell committed Jun 27, 2022
1 parent 6736af3 commit 9667db0
Show file tree
Hide file tree
Showing 19 changed files with 275 additions and 1,302 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [3.0.0-rc.13] - 27/06/2022
- Fix #235 - fix issue taking a screenshot on an Android device
- Resolved #170: Added example code to ensure json report is save to disk even when the test run fails. Also added script to generate a HTML report from a JSON report

## [3.0.0-rc.12] - 24/06/2022
- Fix #222 - escape single quotation marks in data tables

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Feature: Creating todos
Then I expect the todo list
| Todo |
| Buy spinach |
When I take a screenshot called 'Johnson'

Scenario: User can create multiple new todo items
Given I fill the "todo" field with "Buy carrots"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ FlutterTestConfiguration gherkinTestConfiguration = FlutterTestConfiguration(
],
hooks: [
ResetAppHook(),
// AttachScreenshotAfterStepHook(),
],
reporters: [
StdoutReporter(MessageLevel.error)
Expand All @@ -33,6 +34,9 @@ FlutterTestConfiguration gherkinTestConfiguration = FlutterTestConfiguration(
TestRunSummaryReporter()
..setWriteLineFn(print)
..setWriteFn(print),
JsonReporter(
writeReport: (_, __) => Future<void>.value(),
),
],
createWorld: (config) => Future.value(CustomWorld()),
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import 'dart:convert';

import 'package:flutter_gherkin/flutter_gherkin.dart';
import 'package:gherkin/gherkin.dart';

class AttachScreenshotAfterStepHook extends Hook {
@override
Future<void> onAfterStep(
World world,
String step,
StepResult stepResult,
) async {
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);
}

return super.onAfterStep(world, step, stepResult);
}
}

Future<String> takeScreenshot(World world) async {
final bytes = await (world as FlutterWorld).appDriver.screenshot();

return base64Encode(bytes);
}
Loading

0 comments on commit 9667db0

Please sign in to comment.