Gherkin Language Keywords

Gherkin has its own set of keywords, and each keyword has some meaning. To learn how to write steps in the Gherkin language, you must be familiar with its keyword. 

If you are using any editor, these keywords are highlighted with some color. Each keyword is translated into many spoken languages; we’ll use English in this article.

Categories of Gherkin Keywords

We can divide Gherkin Keywords into two categories:

  1. Primary Keywords: Feature, Rule, Scenario, Example, Given, When, Then, And, But, Background, Scenario Outline, Examples
  2. Secondary Keyword: Doc String("""), Data Tables(I), @(Tags), #(Comment) 

Each step starts with Given, When, Then, And, or But.

List of Gherkin Primary Keywords and their synonyms

You can replace each Keyword with its Synonyms in your Gherkin File.

Keyword Synonyms Description
Feature Business Need, Ability Feature provides a high level description of a software feature. It is used to group related scenarios.
Background   Runs steps before Scenario
Scenario Example Starts a new scenario
Scenario Outline Scenario Template Starts a new scenario with multiple examples
Given *, And, But Puts the system in a predefined state or specify your pre conditions in it
When *, And, But Use when, to describe an event or action
Then *, And, But Use Then, to describe an expected outcome or result
Examples Scenarios List examples for Scenario Outline
Rule   Represent one business rule that should be implemented. It grouped together several scenarios that belongs to same rule.

Note: And is used for statements that are an addition to the previous steps and represent positive statements. But are used for statements that are an addition to the previous step and represent negative statements.

This is an overview of Gherkin Keywords; we will discuss each keyword in detail with examples while working on our BDD tools like Cucumber, Behat, etc.

Wed, 12/21/2016 - 05:08
Tarun Goswami is a highly experienced professional, currently serving as Technical Lead at a well-established IT services company. With over 12 years of experience across multiple domains, he demonstrates his expertise and passion for the industry through his engaging and informative blog writing in his spare time.

Gherkin Keywords List