Appearance
Scenario Inheritance
Scenario Inheritance in AireAssert allows you to reuse scenarios across multiple features, reducing duplication and making your Gherkin files easier to maintain.
Table of Contents
- Overview
- How It Works
- Referencing Another Scenario
- File Location Requirements
- Multiple Inheritance
- Step Files
Overview
One of the main goals of AireAssert is to eliminate boilerplate code so you can focus directly on testing.
However, we noticed that scenario writers were often duplicating large chunks of Gherkin. Scenario Inheritance solves this by allowing one scenario to run another scenario as part of its setup.
How It Works
Scenario inheritance lets a scenario include and run another scenario before adding its own steps.
For example, let’s say we have a feature file that completes Page One of a form:
gherkin
Feature: First Feature
Scenario: Complete Page One
Given we are completing the 'totally-fictional' eform
When we set 'First name' to 'Testy'
And we set 'Last name' to 'McTest'
And we move to the next page of the form
Then 'Page two' is shownReferencing Another Scenario
Now we want to test Page Two. Instead of duplicating the setup above, we can reference the first scenario:
gherkin
{ Import: 'FirstFeature.feature' }
Feature: Second Feature
Scenario: Complete Page Two
Given we have run scenario 'Complete Page One'
And we set 'Some field' to anything
And we move to the next page of the form
Then 'Page three' is shownWhen you run your test set, Complete Page Two will run all the steps from Complete Page One, then add its own steps. Multiple Inheritance
You can chain scenarios together with multiple layers of inheritance.
For example, we can add a third feature that inherits from the second:
gherkin
{ Import: 'SecondFeature.feature' }
Feature: Third Feature
Scenario: Complete Page Three
Given we have run scenario 'Complete Page Two'
And we set 'Another field' to anything
And we move to the next page of the form
Then 'Page four' is shownWhen this runs, all three scenarios will execute in sequence.
File Location Requirements
When using scenario inheritance, the imported file must be in the same folder as the file that references it.
This is because AireAssert resolves imports relative to the referencing file’s location.
✅ Correct Folder Structure
features/
FirstFeature.feature
SecondFeature.featureSecondFeature.feature can import FirstFeature.feature directly.
❌ Incorrect Folder Structure
features/
FirstFeature.feature
subfolder/
SecondFeature.featureSecondFeature.feature will not resolve FirstFeature.feature because they are in different folders.
Step Files
Sometimes you want to create a common block of steps for reuse without it ever being run alone.
In that case, name your file with the .steps extension instead of .feature. You can still import and reference it in other scenarios as normal.
gherkin
Scenario: Imported Step
Given we are completing the 'some-form' eform
When we set 'Field-1' to 'something'and then:
gherkin
{ Import: 'MyStepsForImport.steps' }
Feature: Inheriting Feature
Scenario: Example Scenario
Given we have run scenario 'Imported Step'
And we set 'Field-2' to 'another value'
Then 'Next page' is shown