feat: Add Background keyword support for scenarios#10
Open
Kahoulam wants to merge 3 commits intomarcglasberg:mainfrom
Open
feat: Add Background keyword support for scenarios#10Kahoulam wants to merge 3 commits intomarcglasberg:mainfrom
Kahoulam wants to merge 3 commits intomarcglasberg:mainfrom
Conversation
This refactor enables `bdd_framework` to drive UI-based logic using Flutter's `testWidgets`. ### Problem Solved Previously, the framework was strictly tied to the standard `test()` function, making it impossible to: 1. Access the `WidgetTester` instance within Gherkin steps. 2. Handle the specific asynchronous zones required by Flutter UI tests. 3. Perform async operations like `await tester.pump()` in the Gherkin execution flow. ### Solutions - **Runner Decoupling**: Re-architected the execution flow to support framework-specific runners (Dart, Flutter, and Flutter Widget). - **Widget-Specifc API**: Introduced `package:bdd_framework/flutter_widget_test.dart` which provides the `.runTestWidgets()` extension to correctly bridge the BDD engine with Flutter's `testWidgets`. - **Tester Injection**: Steps executed via the widget runner now correctly receive the `WidgetTester` instance in their callback. - **Improved Context**: `BddContext` now handles both logic-only and UI-based scenarios. ### Other Improvements - Reorganized project structure for better maintainability (separate core vs. runners). - Isolated reporter exports into `lib/src/reporter.dart`. - Maintained 100% backward compatibility for existing pure-logic tests via `lib/bdd_framework.dart`. Closes marcglasberg#5
- Added patrol dependency to pubspec.yaml. - Implemented PatrolRunner with .run() and .code() extensions in lib/src/runners/patrol_runner.dart. - Added lib/patrol_test.dart as the public entry point for Patrol BDD tests. - Created patrol_test/patrol_runner_test.dart to verify PatrolIntegrationTester injection and UI interaction. - Updated .gitignore to exclude Patrol-generated files (test_bundle.dart, playwright-report/, test-results/). - Aligned API signature with FlutterWidgetTestRunner for consistency.
- Add BddBackground to core module - Extend BddFeature to support initialization and execution of Background context - Update inner test engine (BddEngine._runTheTest) to sequentially run background steps before scenario steps - Refactor output generation in BddFeature.toString() to properly align generated .feature files - Fix bug leading to duplicate scenarios in .feature output when multiple reporters are used - Refactor bdd_buy_and_sell.dart and bdd_average_price.dart examples to demonstrate Background usage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This PR introduces support for the Gherkin
Backgroundkeyword in thebdd_framework. This allows defining a common setup (e.g., Given steps) that runs before each Scenario in a Feature, significantly reducing duplication across test scenarios.Changes
BddBackground: Introduced a dedicated class in the core module to encapsulate background logic.BddFeature: Added support for the initialization and execution of theBackgroundcontext.BddEngine._runTheTestto sequentially run background steps before scenario steps, seamlessly supporting all test runners.BddFeature.toString()to properly align generated.featurefiles to standard Gherkin indentation..featureoutputs when multiple reporters are set up simultaneously.bdd_buy_and_sell.dartandbdd_average_price.dartexamples to demonstrate the newBackgroundusage effectively.Closes #6