Skip to content

Commit

Permalink
fix(#231): Exposed frameBindingPolicy on the test runner when runni…
Browse files Browse the repository at this point in the history
…ng 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
  • Loading branch information
jonsamwell committed Jun 29, 2022
1 parent 66919d6 commit b73da40
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 12 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## [3.0.0-rc.15] - 28/06/2022
- 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.0.0-rc.14] - 28/06/2022
- Fix #237 - Ensure everything works on the web

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:flutter_gherkin/flutter_gherkin.dart';
import 'package:flutter_simple_dependency_injection/injector.dart';
import 'package:gherkin/gherkin.dart';

import 'hooks/attach_screenshot_after_step_hook.dart';
import 'hooks/reset_app_hook.dart';
import 'steps/expect_todos_step.dart';
import 'steps/multiline_string_with_formatted_json.dart';
Expand All @@ -22,7 +23,7 @@ FlutterTestConfiguration gherkinTestConfiguration = FlutterTestConfiguration(
],
hooks: [
ResetAppHook(),
// AttachScreenshotAfterStepHook(),
AttachScreenshotAfterStepHook(),
],
reporters: [
StdoutReporter(MessageLevel.error)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion example_with_integration_test/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ packages:
path: ".."
relative: true
source: path
version: "3.0.0-rc.13"
version: "3.0.0-rc.14"
flutter_simple_dependency_injection:
dependency: "direct main"
description:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Future<void> writeGherkinReports(List<dynamic> reports) async {
File file = File(
'${integration_test_driver.testOutputsDirectory}/'
'$filenamePrefix'
'v${i + 1}.json',
'-v${i + 1}.json',
);

await file.writeAsString(json.encode(reportData));
Expand Down
18 changes: 13 additions & 5 deletions lib/src/flutter/adapters/widget_tester_app_driver_adapter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ class WidgetTesterAppDriverAdapter
Duration? duration = const Duration(milliseconds: 100),
Duration? timeout = const Duration(seconds: 30),
}) async {
return _implicitWait(
final result = await _implicitWait(
duration: duration,
timeout: timeout,
force: true,
);

return result;
}

Future<int> _implicitWait({
Expand All @@ -39,11 +41,13 @@ class WidgetTesterAppDriverAdapter
}) async {
if (waitImplicitlyAfterAction || force == true) {
try {
return await nativeDriver.pumpAndSettle(
final result = await nativeDriver.pumpAndSettle(
duration ?? const Duration(milliseconds: 100),
EnginePhase.sendSemanticsUpdate,
timeout ?? const Duration(seconds: 30),
);

return result;
} catch (_) {
return 0;
}
Expand All @@ -68,17 +72,21 @@ class WidgetTesterAppDriverAdapter
}
}

Future<List<int>> screenshotOnAndroid() {
Future<List<int>> screenshotOnAndroid() async {
RenderObject? renderObject = binding.renderViewElement?.renderObject;
if (renderObject != null) {
while (!renderObject!.isRepaintBoundary) {
renderObject = renderObject.parent as RenderObject?;
assert(renderObject != null);
}

if (renderObject.debugNeedsPaint) {
await Future.delayed(const Duration(milliseconds: 100));
}

final layer = renderObject.debugLayer as OffsetLayer;

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

return await screenshotOnAndroid();
} else {
return binding.takeScreenshot(name);
return await binding.takeScreenshot(name);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ class _CustomGherkinIntegrationTestRunner extends GherkinIntegrationTestRunner {
required StartAppFn appMainFunction,
required Timeout scenarioExecutionTimeout,
AppLifecyclePumpHandlerFn? appLifecyclePumpHandler,
LiveTestWidgetsFlutterBindingFramePolicy? framePolicy,
}) : super(
configuration: configuration,
appMainFunction: appMainFunction,
scenarioExecutionTimeout: scenarioExecutionTimeout,
appLifecyclePumpHandler: appLifecyclePumpHandler,
framePolicy: framePolicy,
);
@override
Expand All @@ -54,12 +56,14 @@ void executeTestSuite({
required StartAppFn appMainFunction,
Timeout scenarioExecutionTimeout = const Timeout(const Duration(minutes: 10)),
AppLifecyclePumpHandlerFn? appLifecyclePumpHandler,
LiveTestWidgetsFlutterBindingFramePolicy? framePolicy,
}) {
_CustomGherkinIntegrationTestRunner(
configuration: configuration,
appMainFunction: appMainFunction,
appLifecyclePumpHandler: appLifecyclePumpHandler,
scenarioExecutionTimeout: scenarioExecutionTimeout,
framePolicy: framePolicy,
).run();
}
''';
Expand Down
6 changes: 3 additions & 3 deletions lib/src/flutter/runners/gherkin_integration_test_runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ abstract class GherkinIntegrationTestRunner {
final StartAppFn appMainFunction;
final AppLifecyclePumpHandlerFn? appLifecyclePumpHandler;
final Timeout scenarioExecutionTimeout;
final LiveTestWidgetsFlutterBindingFramePolicy? framePolicy;
final AggregatedReporter _reporter = AggregatedReporter();

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

AggregatedReporter get reporter => _reporter;
Hook get hook => _hook!;
LiveTestWidgetsFlutterBindingFramePolicy? get framePolicy => null;

/// A Gherkin test runner that uses [WidgetTester] to instrument the app under test.
///
Expand All @@ -64,6 +64,7 @@ abstract class GherkinIntegrationTestRunner {
required this.appMainFunction,
required this.scenarioExecutionTimeout,
this.appLifecyclePumpHandler,
this.framePolicy,
}) {
configuration.prepare();
_registerReporters(configuration.reporters);
Expand All @@ -79,8 +80,7 @@ abstract class GherkinIntegrationTestRunner {
Future<void> run() async {
_binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized();

_binding.framePolicy =
framePolicy ?? LiveTestWidgetsFlutterBindingFramePolicy.benchmarkLive;
_binding.framePolicy = framePolicy ?? _binding.framePolicy;

tearDownAll(
() {
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_gherkin
description: A Gherkin / Cucumber parser and test runner for Dart and Flutter
version: 3.0.0-rc.14
version: 3.0.0-rc.15
homepage: https://github.com/jonsamwell/flutter_gherkin

environment:
Expand Down

0 comments on commit b73da40

Please sign in to comment.