playwright-bdd icon indicating copy to clipboard operation
playwright-bdd copied to clipboard

[Feature]: Implement chaining of feature files in native Playwright BDD (not using Cucumber js)

Open Ashkum3010 opened this issue 7 months ago • 4 comments

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

Ashkum3010 avatar Apr 30 '25 17:04 Ashkum3010

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 avatar May 01 '25 14:05 vitalets

@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.

cloudbring avatar May 02 '25 16:05 cloudbring

I get the idea. I've collected a few links on re-using gherkin code:

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:

  1. Maybe you need re-use of particular scenario not a whole feature (as there can be several scenarios in a feature)?
  2. Could you show the full minimal example? Now it's not clear enough, what is the reason of calling loan.feature and load-setup.feature before actual task1.feature / task2.feature. Do they perform some setup or provide some parameters?

vitalets avatar May 04 '25 11:05 vitalets

@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

thulasipavankumar avatar May 08 '25 10:05 thulasipavankumar