From b73da409b36a5a39ececae633b5c9bfd76e5af83 Mon Sep 17 00:00:00 2001 From: Jon Date: Wed, 29 Jun 2022 11:49:08 +1000 Subject: [PATCH] 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 --- CHANGELOG.md | 3 +++ .../gherkin/configuration.dart | 3 ++- .../integration_test/gherkin_suite_test.g.dart | 4 ++++ example_with_integration_test/pubspec.lock | 2 +- .../test_driver/integration_test_driver.dart | 2 +- .../widget_tester_app_driver_adapter.dart | 18 +++++++++++++----- .../gherkin_suite_test_generator.dart | 4 ++++ .../gherkin_integration_test_runner.dart | 6 +++--- pubspec.yaml | 2 +- 9 files changed, 32 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b7c7a46..62f73e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/example_with_integration_test/integration_test/gherkin/configuration.dart b/example_with_integration_test/integration_test/gherkin/configuration.dart index b8b4143..81c22e4 100644 --- a/example_with_integration_test/integration_test/gherkin/configuration.dart +++ b/example_with_integration_test/integration_test/gherkin/configuration.dart @@ -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'; @@ -22,7 +23,7 @@ FlutterTestConfiguration gherkinTestConfiguration = FlutterTestConfiguration( ], hooks: [ ResetAppHook(), - // AttachScreenshotAfterStepHook(), + AttachScreenshotAfterStepHook(), ], reporters: [ StdoutReporter(MessageLevel.error) diff --git a/example_with_integration_test/integration_test/gherkin_suite_test.g.dart b/example_with_integration_test/integration_test/gherkin_suite_test.g.dart index 70b5074..fd59239 100644 --- a/example_with_integration_test/integration_test/gherkin_suite_test.g.dart +++ b/example_with_integration_test/integration_test/gherkin_suite_test.g.dart @@ -12,11 +12,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 @@ -389,11 +391,13 @@ void executeTestSuite({ required StartAppFn appMainFunction, Timeout scenarioExecutionTimeout = const Timeout(Duration(minutes: 10)), AppLifecyclePumpHandlerFn? appLifecyclePumpHandler, + LiveTestWidgetsFlutterBindingFramePolicy? framePolicy, }) { _CustomGherkinIntegrationTestRunner( configuration: configuration, appMainFunction: appMainFunction, appLifecyclePumpHandler: appLifecyclePumpHandler, scenarioExecutionTimeout: scenarioExecutionTimeout, + framePolicy: framePolicy, ).run(); } diff --git a/example_with_integration_test/pubspec.lock b/example_with_integration_test/pubspec.lock index 3291425..2144582 100644 --- a/example_with_integration_test/pubspec.lock +++ b/example_with_integration_test/pubspec.lock @@ -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: diff --git a/example_with_integration_test/test_driver/integration_test_driver.dart b/example_with_integration_test/test_driver/integration_test_driver.dart index a32b54c..9981375 100644 --- a/example_with_integration_test/test_driver/integration_test_driver.dart +++ b/example_with_integration_test/test_driver/integration_test_driver.dart @@ -64,7 +64,7 @@ Future writeGherkinReports(List reports) async { File file = File( '${integration_test_driver.testOutputsDirectory}/' '$filenamePrefix' - 'v${i + 1}.json', + '-v${i + 1}.json', ); await file.writeAsString(json.encode(reportData)); diff --git a/lib/src/flutter/adapters/widget_tester_app_driver_adapter.dart b/lib/src/flutter/adapters/widget_tester_app_driver_adapter.dart index fff5939..6de1929 100644 --- a/lib/src/flutter/adapters/widget_tester_app_driver_adapter.dart +++ b/lib/src/flutter/adapters/widget_tester_app_driver_adapter.dart @@ -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 _implicitWait({ @@ -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; } @@ -68,7 +72,7 @@ class WidgetTesterAppDriverAdapter } } - Future> screenshotOnAndroid() { + Future> screenshotOnAndroid() async { RenderObject? renderObject = binding.renderViewElement?.renderObject; if (renderObject != null) { while (!renderObject!.isRepaintBoundary) { @@ -76,9 +80,13 @@ class WidgetTesterAppDriverAdapter 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()); @@ -105,7 +113,7 @@ class WidgetTesterAppDriverAdapter return await screenshotOnAndroid(); } else { - return binding.takeScreenshot(name); + return await binding.takeScreenshot(name); } } } diff --git a/lib/src/flutter/code_generation/generators/gherkin_suite_test_generator.dart b/lib/src/flutter/code_generation/generators/gherkin_suite_test_generator.dart index eaaa149..4f694ce 100644 --- a/lib/src/flutter/code_generation/generators/gherkin_suite_test_generator.dart +++ b/lib/src/flutter/code_generation/generators/gherkin_suite_test_generator.dart @@ -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 @@ -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(); } '''; diff --git a/lib/src/flutter/runners/gherkin_integration_test_runner.dart b/lib/src/flutter/runners/gherkin_integration_test_runner.dart index 2a86a21..e9eaf13 100644 --- a/lib/src/flutter/runners/gherkin_integration_test_runner.dart +++ b/lib/src/flutter/runners/gherkin_integration_test_runner.dart @@ -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? _executableSteps; @@ -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. /// @@ -64,6 +64,7 @@ abstract class GherkinIntegrationTestRunner { required this.appMainFunction, required this.scenarioExecutionTimeout, this.appLifecyclePumpHandler, + this.framePolicy, }) { configuration.prepare(); _registerReporters(configuration.reporters); @@ -79,8 +80,7 @@ abstract class GherkinIntegrationTestRunner { Future run() async { _binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized(); - _binding.framePolicy = - framePolicy ?? LiveTestWidgetsFlutterBindingFramePolicy.benchmarkLive; + _binding.framePolicy = framePolicy ?? _binding.framePolicy; tearDownAll( () { diff --git a/pubspec.yaml b/pubspec.yaml index 6be74d1..6115410 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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: