Gherkin Syntax, Features, Scenarios, Given When Then, and Writing Clear Examples
Learn the language of Cucumber so you can write readable, useful, and maintainable behavior specifications.
Inside this chapter
- What Gherkin Is
- Simple Example
- How to Think About Given When Then
- Writing Good Scenarios
Series navigation
Study the chapters in order for the clearest path from beginner BDD concepts to advanced automation architecture. Use the navigation at the bottom of each page to move through the full tutorial series.
What Gherkin Is
Gherkin is the domain-specific language used by Cucumber to describe system behavior. It is intentionally simple and human-readable so stakeholders can discuss scenarios even if they do not write application code. The most common keywords are Feature, Scenario, Given, When, Then, And, and But.
Simple Example
Feature: Login
Scenario: Valid user signs in successfully
Given the user is on the login page
When the user enters valid credentials
Then the dashboard should be displayed
This format is small, but it already captures business intent in a way that both humans and automation can work with.
How to Think About Given When Then
- Given: the starting context or precondition
- When: the action or event
- Then: the expected outcome
Strong BDD writing keeps each scenario focused on one behavior. If the scenario becomes too long, it is often describing too much at once.
Writing Good Scenarios
Good scenarios are concrete, user-focused, and outcome-driven. They avoid implementation noise such as button IDs, CSS selectors, or internal system details unless those details are truly part of the business behavior. The scenario should communicate intent first, not automation mechanics.