Q5 of 21 · BDD / Cucumber
What is the difference between Scenario and Scenario Outline in Cucumber?
Short answer
Short answer: Scenario is a single, concrete test case. Scenario Outline is a template that runs once per row in an Examples table, with column values substituted into angle-bracket placeholders.
Detail
Scenario — a single, specific example with hardcoded values:
Scenario: User cannot log in with wrong password
Given the login page is open
When the user enters "alice@example.com" and "wrongpassword"
Then the error "Invalid credentials" is shown
Scenario Outline — runs once per row, substituting <placeholder> with each value:
Scenario Outline: Login fails for invalid credentials
Given the login page is open
When the user enters "<email>" and "<password>"
Then the error "<error>" is shown
Examples:
| email | password | error |
| alice@example.com | wrongpassword | Invalid credentials |
| notanemail | any | Invalid email format |
| alice@example.com | | Password cannot be empty |
This generates 3 separate test cases from one template — equivalent to a parameterised test in JUnit/TestNG.
When to use Scenario Outline:
- Boundary value testing (valid/invalid inputs)
- Same workflow with multiple data sets
- Equivalence classes that share the same steps
When NOT to: If the data sets require meaningfully different Given/Then context, force-fitting them into a single Outline creates a confusing template. Write separate Scenarios instead.
Multiple Examples tables: A Scenario Outline can have multiple Examples tables, each with a different tag, to separate positive and negative cases:
@positive
Examples:
| email | password |
| valid@example.com | correct |
@negative
Examples:
| email | password |
| valid@example.com | wrong |