Cucumber
01 / 02

Gherkin Syntax: Feature Files & Scenarios

Gherkin Syntax: Feature Files & Scenarios

A Basic Feature File

Feature: Shopping cart checkout
  As a customer
  I want to check out my cart
  So that I can complete my purchase

  Background:
    Given I am logged in as "ada@example.com"

  Scenario: Successful checkout with items in cart
    Given my cart contains 2 items
    When I proceed to checkout
    And I submit valid payment details
    Then I should see an order confirmation
    And my cart should be empty

Given sets up preconditions, When describes the action, Then specifies the expected outcome — mirroring Arrange/Act/Assert in narrative form. And/But inherit the role of the preceding keyword. Background runs its Given steps before every scenario in the file, like a shared beforeEach().

Scenario Outline — Data-Driven Scenarios

Scenario Outline: Discount applies above a spending threshold
  Given my cart total is <total>
  When I apply the discount code
  Then my final total should be <expected>

  Examples:
    | total | expected |
    | 100   | 90       |
    | 50    | 50       |
    | 200   | 180      |

Data Tables & Doc Strings

A Data Table attaches structured tabular data to a SINGLE step (e.g. a list of cart items) — distinct from Scenario Outline's Examples table, which re-runs the whole scenario per row. A Doc String passes a larger multi-line block (like a JSON payload) to one step using triple-quote delimiters.

Tags

@smoke
Scenario: Checkout with valid card
  ...

# run only smoke tests: cucumber --tags @smoke

Keep your own version of these notes — editable, searchable, and organised by your stack.

Start free