Answer
Scenario Outline in Cucumber
Scenario Outline is used for parameterization — running the same test scenario with multiple sets of input data. It eliminates duplication when the same test flow must be validated against different data.
Syntax
Gherkin
Scenario Outline: <description>
Given ...
When ... "<placeholder>"
Then ... "<placeholder>"
Examples:
| column1 | column2 |
| value1 | value2 |
| value3 | value4 |
Full Example — Login with Multiple Credentials
Gherkin
Feature: Login Validation
Scenario Outline: Login with different user roles
Given the user is on the login page
When the user enters username "<username>" and password "<password>"
And the user clicks Login
Then the user should see the "<dashboard>" page
Examples:
| username | password | dashboard |
| admin | Admin@123 | Admin Home |
| manager | Mgr@456 | Manager |
| testuser | Test@789 | User Home |
How It Works
- ✓Placeholders in
<angle brackets>are replaced with values from theExamplestable - ✓Each row in
Examples= one test execution - ✓3 rows in Examples = 3 separate test runs
- ✓Results appear individually in the report
When to Use
| Use Scenario Outline | Use Regular Scenario |
|---|---|
| Same flow, different data | Unique flow for each case |
| Boundary value testing | One-off edge case |
| Multiple user types | Single user journey |
| Form validation | Complex, branching logic |
Difference from Scenario
Gherkin
-- Without Scenario Outline (repetitive)
Scenario: Login as admin
Given ...
When the user enters "admin" and "Admin@123"
Then ...
Scenario: Login as manager
Given ...
When the user enters "manager" and "Mgr@456"
Then ...
-- With Scenario Outline (clean)
Scenario Outline: Login as <role>
Given ...
When the user enters "<username>" and "<password>"
Then ...
Examples:
| role | username | password |
| admin | admin | Admin@123 |
| manager | manager | Mgr@456 |
