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:

@sanity
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
  @scenariooutline
  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>"

    Examples: 
      | email                       | password | heading        |
      | goswami.tarun77+7@gmail.com | test1234 | My account     |
      | wrongusername@gmail.com     | test     | Authentication |

  #Scenario Example
  @singleargument
  Scenario: Verify Forgot Password Functionality
    When I follow "Forgot your password?" link
    And I fill in "input[id='email']" with "goswami.tarun77+7@gmail.com"
    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.

About

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.