Answer
Gherkin — The Language of Cucumber
Cucumber uses Gherkin as its language. Gherkin is a simple, plain-English representation of application behavior that can be understood by both technical and non-technical stakeholders.
Key Characteristics
- ✓Human-readable, plain text format
- ✓Structured around business behavior (not implementation)
- ✓Understood by Business Analysts, Developers, and QA
- ✓Each
.featurefile is written in Gherkin
Core Gherkin Keywords
| Keyword | Purpose |
|---|---|
Feature | High-level description of the feature under test |
Scenario | A specific test case |
Scenario Outline | Parameterized scenario for multiple data sets |
Given | Precondition / initial state |
When | Action performed by the user |
Then | Expected outcome / assertion |
And | Continues a Given/When/Then step |
But | Negative continuation |
Background | Common steps that run before each scenario |
Examples | Data table for Scenario Outline |
Example Feature File
Gherkin
Feature: User Login
Scenario: Successful login with valid credentials
Given the user is on the login page
When the user enters username "admin" and password "Admin@123"
And the user clicks the Login button
Then the user should be redirected to the dashboard
And the welcome message "Welcome, Admin" should be displayed
Why Gherkin?
- ✓Collaboration: Non-technical stakeholders write/review tests
- ✓Living documentation: Feature files serve as up-to-date docs
- ✓BDD bridge: Links business requirements to automated tests
