Skip to main content

Cucumber Multiple Scenarios in One Feature File

Feature files can have more than one Scenario or Scenario Outline. You can write all your possible requirements or Scenarios for a particular feature in a Feature File.

One Scenario is separated from another using the "Scenario" or "Scenario Outline" keyword. When you comment Scenario, don't forget to comment complete Scenario. Otherwise, your remaining lines of Scenario that are not commented on will be considered part of the previous Scenario.

A feature file can have any number of Scenarios but do remember one feature file focuses on only one functionality. For example, the Search feature will contain all search-related scenarios. So, it's better to put related Scenarios in one feature file.

However, when the application size is large, you can divide your feature into sub-feature and have more than one file since it is not a good idea to group hundreds of test Scenarios in a single feature file.

Each Scenario should be independent of another scenario. The result of one Scenario or Feature should not affect the other Scenario.

Cucumber Multiple Scenarios in Single Feature File

Check below a feature file with multiple scenarios:

Feature: Registration, Login and MyAccount

    Given I am on the homepage
    And I follow "Sign in"

  @regression @smoke
  Scenario: Verify Login Functionality
    And I fill "email address" with ""
    And I fill "password" with "Test@1234"
    And I click "sign in"
    Then I should see "MY ACCOUNT" heading

  Scenario: Create New User
    When I fill "registration email textbox" with ""
    Then I click "create an account button"
    And I enter following details
      | First Name | Tarun    |
      | Last Name  | Goswami  |
      | Password   | Test1234 |
      | Date       |       13 |
      | Year       |     1989 |
    And I click "register button"

How to Run Multiple Scenarios in Cucumber

You can execute multiple scenarios in a single or multiple feature file by tagging Scenarios with common tags or grouping them using the rule keyword and tags.

And Later, you can execute the scenarios by using that tag in the Cucumber Runner or Command line. 

Video Tutorial: Multiple Scenarios in Feature File

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.