SpecFlow - Gherkin



A Gherkin is a group of important keywords to build a meaningful architecture for specifications. Every keyword is converted to plain spoken languages like English.

Rules in Gherkin

Some of the rules in Gherkin are listed below −

  • A document in Gherkin begins with keywords.

  • Comments can be added at the beginning of the new line in the Feature File. They start with or without spaces followed by # symbol and text. However, block comments cannot be added till now in SpecFlow.

  • To indent the code, spaces or tabs can be used. It is recommended to have two spaces for indentation.

  • The content after the keyword for each step has a corresponding block of code. This is known as the Step Definition.

Gherkin Example

Following is the Gherkin example −

Feature: Payment Functionality

# Example 1
   Scenario: Member Payment Method
      When a member is on Payment screen
      Then the payment amount is displayed.

# Example 2
   Scenario: Member Payment Dues
      When a member is on Payment Due screen
      Then the payable amount is displayed.

In the above example, Feature, Scenario, Given, When, and Then are known as the Gherkin keywords.

Advertisements