Gherkin is a domain-specific language (DSL) used in Cucumber to write test cases in a human-readable and structured format. It follows the Given-When-Then syntax, making it easy for both technical and non-technical stakeholders to understand test scenarios. Gherkin acts as a bridge between business requirements and automated tests by allowing behavior-driven development (BDD).

Key Features of Gherkin

βœ… Simple and Readable: Uses plain English syntax.
βœ… Executable by Cucumber: Serves as test automation input.
βœ… Reusable Steps: Common steps can be reused across scenarios.
βœ… Multi-Language Support: Over 70 languages supported.
βœ… Supports Data-Driven Testing: Using Scenario Outline with Examples.


Example Gherkin Scenario – Login Functionality

Feature: Login Functionality

  Scenario: Successful Login
    Given the user is on the login page
    When the user enters valid credentials
    Then the user should be redirected to the homepage

Here’s what each part does:

  • Feature: Describes the application functionality.
  • Scenario: Represents a single test case.
  • Given: Sets up preconditions (user is on login page).
  • When: Defines the action (user enters credentials).
  • Then: Specifies the expected outcome (user is redirected).