Skip to main content

Cucumber Combining Scenarios, Background and Scenario Outlines

In most of the feature files, Scenario, Background, Data Tables and Scenario outlines are combined. 

There is nothing special you have to do to combine these all in a single feature file. Declare and use them like you do while declaring multiple scenarios in a feature file.

Background will be common for all scenarios and scenario outline. Also, Scenarios and Scenario Outline will be independent of each other. Similarly, two Scenarios will be independent to each other.

Check below feature file:

Feature: Registration, Login and MyAccount

  Background: Title of Background
    Given I am on the home page
    And I follow "Sign in" link

  #Scenario Outline Example
  Scenario Outline: Verify Login Functionality
    When I fill in "input[id='email']" with "<email>"
    And I fill in "input[id='passwd']" with "<password>"
    And I click on "button[id='SubmitLogin']"
    Then I should see heading "<heading>"

      | email                       | password | heading        |
      | | test1234 | My account     |
      |     | test     | Authentication |

  #Scenario Example
  Scenario: Verify Forgot Password Functionality
    When I follow "Forgot your password?" link
    And I fill in "input[id='email']" with ""
    And I click on "button[type='submit'] span i"

In above example,

  • Scenario and Scenario Outline are independent of each other.
  • Scenario and Scenario Outline both dependent upon Background because Background is common for both.

Submitted by tgoswami on August 30, 2020

Tarun has 11+ years of experience in Quality Assurance in different domains like Banking, E-commerce, Health and Education.


At ProgramsBuzz, you can learn, share and grow with millions of techie around the world from different domain like Data Science, Software Development, QA and Digital Marketing. You can ask doubt and get the answer for your queries from our experts.