Beginner
Chapter 5 · 9 min read
Scenario Outline & Examples
Run the same scenario with multiple data sets using Scenario Outline and Examples tables — the BDD equivalent of data-driven testing.
Scenario Outline — Data-Driven BDD
A Scenario Outline is a template that runs multiple times with different data from an Examples table. It's the BDD way to do data-driven testing without duplicating scenarios.
How It Works
Placeholders in angle brackets (e.g., <username>) are replaced with values from each row of the Examples table. Cucumber generates one scenario per row automatically.
login_outline.feature
Feature: Login Validation
Validate login with multiple credential combinations
Scenario Outline: Login with various credentials
Given the user is on the login page
When the user enters username "<username>" and password "<password>"
And the user clicks the login button
Then the login result should be "<result>"
Examples: Valid users
| username | password | result |
| admin | admin123 | success |
| manager | mgr456 | success |
Examples: Invalid users
| username | password | result |
| wrong | wrong | invalid_creds |
| admin | | missing_pass |
| | admin123 | missing_user |
| locked | locked1 | account_locked|
Scenario Outline: Registration validation
When the user registers with email "<email>"
Then the validation result should be "<valid>"
Examples:
| email | valid |
| user@example.com | true |
| invalid-email | false |
| @nodomain | false |
| user@example.co.uk | true |
LoginOutlineSteps.java
package com.bdd.course.stepdefinitions;
import io.cucumber.java.en.*;
import org.testng.Assert;
public class LoginOutlineSteps {
private String loginResult;
@Then("the login result should be {string}")
public void theLoginResultShouldBe(String expectedResult) {
// In real tests, check actual result from the page
System.out.println("Expected result: " + expectedResult);
// Assert.assertEquals(loginResult, expectedResult);
}
@When("the user registers with email {string}")
public void registerWithEmail(String email) {
System.out.println("Registering with: " + email);
}
@Then("the validation result should be {string}")
public void validationResult(String expected) {
System.out.println("Validation: " + expected);
}
}
login_outline.feature
Feature: Login Validation
Validate login with multiple credential combinations
Scenario Outline: Login with various credentials
Given the user is on the login page
When the user enters username "<username>" and password "<password>"
And the user clicks the login button
Then the login result should be "<result>"
Examples: Valid users
| username | password | result |
| admin | admin123 | success |
| manager | mgr456 | success |
Examples: Invalid users
| username | password | result |
| wrong | wrong | invalid_creds |
| admin | | missing_pass |
| | admin123 | missing_user |
| locked | locked1 | account_locked|
login_outline_steps.py
# features/steps/login_outline_steps.py
from behave import then, when
@then('the login result should be "{expected_result}"')
def step_login_result(context, expected_result):
print(f"Expected result: {expected_result}")
# assert context.login_result == expected_result
@when('the user registers with email "{email}"')
def step_register_email(context, email):
print(f"Registering with: {email}")
@then('the validation result should be "{expected}"')
def step_validation_result(context, expected):
print(f"Validation: {expected}")
Cucumber BDD
Beginner
Scenario Outline & Examples
Written by PV
© 2026 All Rights Reserved