Gherkin Language Keywords

Profile picture for user devraj

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.

FeatureBusiness Need, AbilityFeature provides a high level description of a software feature. It is used to group related scenarios.
Background Runs steps before Scenario
ScenarioExampleStarts a new scenario
Scenario OutlineScenario TemplateStarts a new scenario with multiple examples
Given*, And, ButPuts the system in a predefined state or specify your pre conditions in it
When*, And, ButUse when, to describe an event or action
Then*, And, ButUse Then, to describe an expected outcome or result
ExamplesScenariosList 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.