playwright-bdd
playwright-bdd copied to clipboard
[Feature]: Implement chaining of feature files in native Playwright BDD (not using Cucumber js)
The Problem
I am having an issue where I need to implement chaining of feature files in native Playwright BDD (not using Cucumber js) for a following scenario, can you help with this implementation.
Proposed Solution
A working feature would be able to chain the features from inside of a Scenario outline of a parent feature file. e.g.
Feature: Loan Workflow - Parent Feature
Scenario Outline: Run child feature files for different loan flows
Given I execute the feature "childFeature"
Examples:
| childFeature |
| loan-setup.feature |
| funding-review.feature |
Additional Context
No response
Priority Level
Medium
Hi! Currently, this is not possible. Features are flat list, no parent-child dependencies.
Could you share more details on your ultimate goal? For example, if you want to always run both child features together, it can be achieved by tags.
I suppose keeping features as a flat list is better for simplicity and reporting.
@vitalets Let me give a bit more context for my colleague @Ashkum3010
We are working on a very large, very long automation project based around a complicated workflow. Specifically, there are interchangable parts that we want to be able to write once and reuse at the Gherkin level.
Structure
Loan - has many -> Objectives - has many -> Tasks
There are many different kinds of loans. The Objectives are shared and reused between different loan types.
What are are trying to achieve is nested gherkin. A parent Gherkin can have a step in JS/TS that can call another gherkin .feature file and they are all executed as part of the same test context.
# loan.feature
Feature: [Loan] - Parent Feature
Scenario Outline: Run child feature files for different loan flows
Given I execute the objective feature file <childFeature>
Examples:
| childFeatureFile |
|------------------------|
| loan-setup.feature |
| funding-review.feature |
// loan.steps.ts
import { createBdd } from 'playwright-bdd';
Given("I execute the objective feature file {string}", async (childFeatureFile) => {
// Code here to load loan-setup.feature and funding-review.feature
loadFeature(childFeatureFile)
}
// loan-setup.feature
Feature: [Objective] - Loan Setup
- Both a child of Loan.feature and a parent to various tasks
Scenario Outline: Run child feature files for different loan flows
Given I execute the task feature file <childFeature>
Examples:
| childFeatureFile |
|------------------------|
| task1.feature |
| task2.feature |
// loan-setup.steps.ts
import { createBdd } from 'playwright-bdd';
Given("I execute the task feature file {string}", async (childFeatureFile) => {
// Code here to load loan-setup.feature and funding-review.feature
loadFeature(childFeatureFile)
}
Expected:
loan.feature runs and the test steps can load and execute other feature files and keep them in the same test context.
I get the idea. I've collected a few links on re-using gherkin code:
- good summarizing comment https://github.com/cucumber/godog/issues/110#issuecomment-350339592
- SO: Is it possible to reuse a feature as the "Given" for another feature?
- SO: How to use common/shared "blocks" between cucumber features?
At early days of Cucumber, there was GivenScenario keyword, that allowed to re-use scenarios from the same file, but it was discarded.
I would say that calling features from steps is something inverse from the BDD standpoint.
Most of the solutions suggest to re-use code on step definition level.
Two follow up questions:
- Maybe you need re-use of particular scenario not a whole feature (as there can be several scenarios in a feature)?
- Could you show the full minimal example? Now it's not clear enough, what is the reason of calling
loan.featureandload-setup.featurebefore actualtask1.feature / task2.feature. Do they perform some setup or provide some parameters?
@cloudbring
There is high chance it can lead to circular dependency and the execution can forever be stuck in loop.
feature 1 invokes feature 2 and vice versa