Skip to content

Commit 9667db0

Browse files
committed
- 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
1 parent 6736af3 commit 9667db0

19 files changed

+275
-1302
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## [3.0.0-rc.13] - 27/06/2022
2+
- Fix #235 - fix issue taking a screenshot on an Android device
3+
- 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
4+
15
## [3.0.0-rc.12] - 24/06/2022
26
- Fix #222 - escape single quotation marks in data tables
37

example_with_integration_test/integration_test/features/create.feature

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Feature: Creating todos
77
Then I expect the todo list
88
| Todo |
99
| Buy spinach |
10+
When I take a screenshot called 'Johnson'
1011

1112
Scenario: User can create multiple new todo items
1213
Given I fill the "todo" field with "Buy carrots"

example_with_integration_test/integration_test/gherkin/configuration.dart

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ FlutterTestConfiguration gherkinTestConfiguration = FlutterTestConfiguration(
2222
],
2323
hooks: [
2424
ResetAppHook(),
25+
// AttachScreenshotAfterStepHook(),
2526
],
2627
reporters: [
2728
StdoutReporter(MessageLevel.error)
@@ -33,6 +34,9 @@ FlutterTestConfiguration gherkinTestConfiguration = FlutterTestConfiguration(
3334
TestRunSummaryReporter()
3435
..setWriteLineFn(print)
3536
..setWriteFn(print),
37+
JsonReporter(
38+
writeReport: (_, __) => Future<void>.value(),
39+
),
3640
],
3741
createWorld: (config) => Future.value(CustomWorld()),
3842
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import 'dart:convert';
2+
3+
import 'package:flutter_gherkin/flutter_gherkin.dart';
4+
import 'package:gherkin/gherkin.dart';
5+
6+
class AttachScreenshotAfterStepHook extends Hook {
7+
@override
8+
Future<void> onAfterStep(
9+
World world,
10+
String step,
11+
StepResult stepResult,
12+
) async {
13+
try {
14+
final screenshotData = await takeScreenshot(world);
15+
world.attach(screenshotData, 'image/png', step);
16+
} catch (e, st) {
17+
world.attach('Failed to take screenshot\n$e\n$st', 'text/plain', step);
18+
}
19+
20+
return super.onAfterStep(world, step, stepResult);
21+
}
22+
}
23+
24+
Future<String> takeScreenshot(World world) async {
25+
final bytes = await (world as FlutterWorld).appDriver.screenshot();
26+
27+
return base64Encode(bytes);
28+
}

0 commit comments

Comments
 (0)