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:
@userflow Feature: Registration, Login and MyAccount Background: Given I am on the homepage And I follow "Sign in" @regression @smoke Scenario: Verify Login Functionality And I fill "email address" with "firstname.lastname@example.org" And I fill "password" with "Test@1234" And I click "sign in" Then I should see "MY ACCOUNT" heading @regression Scenario: Create New User When I fill "registration email textbox" with "email@example.com" 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.