Introduction
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.
Key Features of Scenario Outline
- Parameterization: Variables are defined in angle brackets (< >) and replaced with values from the Examples table during execution.
- Reusability: Instead of writing separate scenarios for each data set, a single scenario outline can handle all cases.
- Clarity: The Examples table makes it easy to understand the different input combinations.
Structure of a Scenario Outline
A Scenario Outline consists of:
- Scenario Outline: The generic scenario definition.
- Steps: Regular Gherkin steps with placeholders (e.g., <username>, <password>).
- Examples Table: A table listing the values for placeholders.
Example:
Feature: Login Functionality
Scenario Outline: Verify login with. different credentials
Given The user is on the login page
When The user enters "<username>" and ". <password>"
Then The user should see the "<result>" message
Examples:
| username | password | result |
| admin | admin123 | Login Successful |
| user | user123 | Login Successful |
| invalidUser | invalidPass | Login Failed |
Difference between Scenario and Scenario Outline
Scenario:
- Definition: Represents a single concrete example of a functionality to be tested.
- Purpose: Used for testing a specific situation with fixed input data.
- Data Handling: Input data is written directly in the steps.
- Reusability: Not reusable for multiple data sets. Separate scenarios are needed for each set of data.
- Keyword: Defined using the Scenario keyword.
- Examples Table: Does not use an Examples table.
Example
Scenario: Login with valid credentials
Given the user is on the login page
When the user enters "testuser" and "password123"
Then the user should be redirected to the homepage
Scenario Outline:
- Definition: Represents a template that can run the same scenario multiple times with different sets of input data.
- Purpose: Used for testing the same functionality with multiple data sets.
- Data Handling: Input data is provided through an Examples table.
- Reusability: Highly reusable as it iterates through all the rows in the Examples table.
- Keyword: Defined using the Scenario Outline keyword.
- Examples Table: Uses an Examples table to provide multiple sets of data.
Example
Scenario Outline: Login with multiple credentials
Given the user is on the login page
When the user enters "<username>" and ". <password>"
Then the user should be redirected to the homepage
Examples:
| username | password |
| testuser1 | password123 |
| testuser2 | pass456 |
Comments
Post a Comment