Skip to content

Commit b73da40

Browse files
committed
fix(#231): Exposed frameBindingPolicy on the test runner when running tests which can affect how frames are painted and the speed of the test run, I've removed the default value which might be responsible for #231
1 parent 66919d6 commit b73da40

File tree

9 files changed

+32
-12
lines changed

9 files changed

+32
-12
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## [3.0.0-rc.15] - 28/06/2022
2+
- Exposed `frameBindingPolicy` on the test runner when running tests which can affect how frames are painted and the speed of the test run, I've removed the default value which might be responsible for #231
3+
14
## [3.0.0-rc.14] - 28/06/2022
25
- Fix #237 - Ensure everything works on the web
36

example_with_integration_test/integration_test/gherkin/configuration.dart

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import 'package:flutter_gherkin/flutter_gherkin.dart';
55
import 'package:flutter_simple_dependency_injection/injector.dart';
66
import 'package:gherkin/gherkin.dart';
77

8+
import 'hooks/attach_screenshot_after_step_hook.dart';
89
import 'hooks/reset_app_hook.dart';
910
import 'steps/expect_todos_step.dart';
1011
import 'steps/multiline_string_with_formatted_json.dart';
@@ -22,7 +23,7 @@ FlutterTestConfiguration gherkinTestConfiguration = FlutterTestConfiguration(
2223
],
2324
hooks: [
2425
ResetAppHook(),
25-
// AttachScreenshotAfterStepHook(),
26+
AttachScreenshotAfterStepHook(),
2627
],
2728
reporters: [
2829
StdoutReporter(MessageLevel.error)

example_with_integration_test/integration_test/gherkin_suite_test.g.dart

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example_with_integration_test/pubspec.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ packages:
213213
path: ".."
214214
relative: true
215215
source: path
216-
version: "3.0.0-rc.13"
216+
version: "3.0.0-rc.14"
217217
flutter_simple_dependency_injection:
218218
dependency: "direct main"
219219
description:

example_with_integration_test/test_driver/integration_test_driver.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ Future<void> writeGherkinReports(List<dynamic> reports) async {
6464
File file = File(
6565
'${integration_test_driver.testOutputsDirectory}/'
6666
'$filenamePrefix'
67-
'v${i + 1}.json',
67+
'-v${i + 1}.json',
6868
);
6969

7070
await file.writeAsString(json.encode(reportData));

lib/src/flutter/adapters/widget_tester_app_driver_adapter.dart

+13-5
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@ class WidgetTesterAppDriverAdapter
2525
Duration? duration = const Duration(milliseconds: 100),
2626
Duration? timeout = const Duration(seconds: 30),
2727
}) async {
28-
return _implicitWait(
28+
final result = await _implicitWait(
2929
duration: duration,
3030
timeout: timeout,
3131
force: true,
3232
);
33+
34+
return result;
3335
}
3436

3537
Future<int> _implicitWait({
@@ -39,11 +41,13 @@ class WidgetTesterAppDriverAdapter
3941
}) async {
4042
if (waitImplicitlyAfterAction || force == true) {
4143
try {
42-
return await nativeDriver.pumpAndSettle(
44+
final result = await nativeDriver.pumpAndSettle(
4345
duration ?? const Duration(milliseconds: 100),
4446
EnginePhase.sendSemanticsUpdate,
4547
timeout ?? const Duration(seconds: 30),
4648
);
49+
50+
return result;
4751
} catch (_) {
4852
return 0;
4953
}
@@ -68,17 +72,21 @@ class WidgetTesterAppDriverAdapter
6872
}
6973
}
7074

71-
Future<List<int>> screenshotOnAndroid() {
75+
Future<List<int>> screenshotOnAndroid() async {
7276
RenderObject? renderObject = binding.renderViewElement?.renderObject;
7377
if (renderObject != null) {
7478
while (!renderObject!.isRepaintBoundary) {
7579
renderObject = renderObject.parent as RenderObject?;
7680
assert(renderObject != null);
7781
}
7882

83+
if (renderObject.debugNeedsPaint) {
84+
await Future.delayed(const Duration(milliseconds: 100));
85+
}
86+
7987
final layer = renderObject.debugLayer as OffsetLayer;
8088

81-
return layer
89+
return await layer
8290
.toImage(renderObject.paintBounds)
8391
.then((value) => value.toByteData(format: ui.ImageByteFormat.png))
8492
.then((value) => value!.buffer.asUint8List());
@@ -105,7 +113,7 @@ class WidgetTesterAppDriverAdapter
105113

106114
return await screenshotOnAndroid();
107115
} else {
108-
return binding.takeScreenshot(name);
116+
return await binding.takeScreenshot(name);
109117
}
110118
}
111119
}

lib/src/flutter/code_generation/generators/gherkin_suite_test_generator.dart

+4
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,13 @@ class _CustomGherkinIntegrationTestRunner extends GherkinIntegrationTestRunner {
3434
required StartAppFn appMainFunction,
3535
required Timeout scenarioExecutionTimeout,
3636
AppLifecyclePumpHandlerFn? appLifecyclePumpHandler,
37+
LiveTestWidgetsFlutterBindingFramePolicy? framePolicy,
3738
}) : super(
3839
configuration: configuration,
3940
appMainFunction: appMainFunction,
4041
scenarioExecutionTimeout: scenarioExecutionTimeout,
4142
appLifecyclePumpHandler: appLifecyclePumpHandler,
43+
framePolicy: framePolicy,
4244
);
4345
4446
@override
@@ -54,12 +56,14 @@ void executeTestSuite({
5456
required StartAppFn appMainFunction,
5557
Timeout scenarioExecutionTimeout = const Timeout(const Duration(minutes: 10)),
5658
AppLifecyclePumpHandlerFn? appLifecyclePumpHandler,
59+
LiveTestWidgetsFlutterBindingFramePolicy? framePolicy,
5760
}) {
5861
_CustomGherkinIntegrationTestRunner(
5962
configuration: configuration,
6063
appMainFunction: appMainFunction,
6164
appLifecyclePumpHandler: appLifecyclePumpHandler,
6265
scenarioExecutionTimeout: scenarioExecutionTimeout,
66+
framePolicy: framePolicy,
6367
).run();
6468
}
6569
''';

lib/src/flutter/runners/gherkin_integration_test_runner.dart

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ abstract class GherkinIntegrationTestRunner {
3838
final StartAppFn appMainFunction;
3939
final AppLifecyclePumpHandlerFn? appLifecyclePumpHandler;
4040
final Timeout scenarioExecutionTimeout;
41+
final LiveTestWidgetsFlutterBindingFramePolicy? framePolicy;
4142
final AggregatedReporter _reporter = AggregatedReporter();
4243

4344
late final Iterable<ExecutableStep>? _executableSteps;
@@ -47,7 +48,6 @@ abstract class GherkinIntegrationTestRunner {
4748

4849
AggregatedReporter get reporter => _reporter;
4950
Hook get hook => _hook!;
50-
LiveTestWidgetsFlutterBindingFramePolicy? get framePolicy => null;
5151

5252
/// A Gherkin test runner that uses [WidgetTester] to instrument the app under test.
5353
///
@@ -64,6 +64,7 @@ abstract class GherkinIntegrationTestRunner {
6464
required this.appMainFunction,
6565
required this.scenarioExecutionTimeout,
6666
this.appLifecyclePumpHandler,
67+
this.framePolicy,
6768
}) {
6869
configuration.prepare();
6970
_registerReporters(configuration.reporters);
@@ -79,8 +80,7 @@ abstract class GherkinIntegrationTestRunner {
7980
Future<void> run() async {
8081
_binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized();
8182

82-
_binding.framePolicy =
83-
framePolicy ?? LiveTestWidgetsFlutterBindingFramePolicy.benchmarkLive;
83+
_binding.framePolicy = framePolicy ?? _binding.framePolicy;
8484

8585
tearDownAll(
8686
() {

pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: flutter_gherkin
22
description: A Gherkin / Cucumber parser and test runner for Dart and Flutter
3-
version: 3.0.0-rc.14
3+
version: 3.0.0-rc.15
44
homepage: https://github.com/jonsamwell/flutter_gherkin
55

66
environment:

0 commit comments

Comments
 (0)