</>

Technology

Cucumber

Difficulty

Beginner

Interview Question

What is the purpose of a Scenario Outline in Cucumber?

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

  1. Placeholders in <angle brackets> are replaced with values from the Examples table
  2. Each row in Examples = one test execution
  3. 3 rows in Examples = 3 separate test runs
  4. Results appear individually in the report

When to Use

Use Scenario OutlineUse Regular Scenario
Same flow, different dataUnique flow for each case
Boundary value testingOne-off edge case
Multiple user typesSingle user journey
Form validationComplex, 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   |

Follow AutomateQA

Related Topics