What is Scenario in Cucumber Testing?
The scenario is one of the core structures of the Gherkin language. Scenario includes all the possible circumstances of the feature and test scripts for these circumstances.
The keyword "Scenario" represents a scenario in Gherkin language.
One feature can have multiple scenarios, and each scenario consists of one or more steps.
Let's understand the scenario through an example:
In order to ensure Feedback functionality of a web application, we are creating a cucumber test to verify whether it is working or not.
Scenario - Verification of Feedback Functionality Given the user navigates to JavaTpoint.com When the user clicks on Feedback, then the Feedback page opens And the user submits feedback message Then feedback should be received on the admin page And admin can reply to the user
Each scenario follows the Given, When, And, and Then format. This format comes under a particular language, called "Gherkin language".
In Gherkin language, scenario outline is the keyword which is used to run the same scenario multiple times.
It is also defined as "Scenario outlines are used when the same test is performed multiple times with a different combination of values."
The keyword scenario outline can also be used by the name Scenario Template. In other words, the keyword Scenario Template is a synonym of scenario outline.
Scenario outline is exactly similar to the scenario structure, but the only difference is the provision of multiple inputs. In order to use scenario outlines, we do not need any smart idea, we just need to copy the same steps and re-execute the code.
Let's understand the scenario outline through an example:
Suppose we need to test whether the login functionality for multiple users is working properly or not. This case requires the execution of the login functionality scenario multiple times. Hence, the scenario outline can be used for the testing of login functionality scenario with multiple usernames and passwords.
While mentioning variables such as "Username" and "Password" in gherkin statements, mention them with "<>". Consider the following test script:
Scenario: Successful Login with Valid entries Given user navigates to the website javatpoint.com When User Navigate to Login Page And user logs in through Login Window by using <Username> as "username1" And <Password> as "password1" Then login must be successful.
Let's take the above test script, in which we need to test login functionality with several different sets of username and password.
Feature: Login Functionality Scenario Outline: Login functionality Username | Password username1 | password1 username2 | password2 username3 | password3 username4 | password4
In the above example, we have provided multiple input values for the variables "Username" and "Password". While executing the actual test, Cucumber will replace the variables with the provided input values.
Once username1 has been executed with password1, the test will execute for the second iteration with another input value. Cucumber will follow this path until the completion of all provided values.
Note: A Scenario Outline must contain a Scenario section. Scenario steps are interpreted as a template and never executed directly.