Skip to content

feat: Add Background keyword support for scenarios#10

Open
Kahoulam wants to merge 3 commits intomarcglasberg:mainfrom
Kahoulam:feature/gherkin-background
Open

feat: Add Background keyword support for scenarios#10
Kahoulam wants to merge 3 commits intomarcglasberg:mainfrom
Kahoulam:feature/gherkin-background

Conversation

@Kahoulam
Copy link

@Kahoulam Kahoulam commented Mar 2, 2026

Overview

This PR introduces support for the Gherkin Background keyword in the bdd_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

  • Added BddBackground: Introduced a dedicated class in the core module to encapsulate background logic.
  • Extended BddFeature: Added support for the initialization and execution of the Background context.
  • Updated Test Engine: Modified BddEngine._runTheTest to sequentially run background steps before scenario steps, seamlessly supporting all test runners.
  • Fixed Formatting: Refactored output generation in BddFeature.toString() to properly align generated .feature files to standard Gherkin indentation.
  • Fixed Duplication Bug: Resolved a pre-existing issue that caused duplicate scenarios in .feature outputs when multiple reporters are set up simultaneously.
  • Refactored Examples: Updated bdd_buy_and_sell.dart and bdd_average_price.dart examples to demonstrate the new Background usage effectively.

Closes #6

Kahoulam added 3 commits March 2, 2026 07:58
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request] Support "Background" keyword in Gherkin output

1 participant