Basic of The Gherkin Language

Hello Everyone ,

In this blog we will discuss about Gherkin Language  which we used in BDD for writing test cases.we will take a look on below topic.

Introduction:

Gherkin’s grammar is defined in the parsing expression grammars. It is Business Readable, DSL created specifically for behavior descriptions without explaining how that behaviour is implemented. Gherkin is a plain English text language.

Gherkin serves two purposes — documentation and automated tests. It is a whitespace-oriented language that uses indentation to define structure.

The Gherkin includes 60 different spoken languages so that we can easily use our own language.The parser divides the input into features, scenarios and steps.

Here is a simple example of Gherkin:

Screenshot from 2017-04-18 11-31-45

When we run this feature this gives us a step definition.In Gherkin, each line is start with a Gherkin keyword, followed by any text you like.

The main keywords are:

  • Feature
  • Scenario
  • Given
  • When
  • Then

Feature:

This keyword refers to description of the functionality of application for which feature file is written.it defines the single feature and we can add multiple scenarios under this.

In this example we added multiple scenario under single feature

Screenshot from 2017-04-18 22-49-12

Scenario:

A Scenario constituting an actual thing.It consists of a list of different steps which are group by Given,When,Then ,And.

We can include numbers of scenario in one feature.

Scenarios follow the same pattern which followed in BDD like

Firstly we go through an initial context, then an event and after that get the outcome.

Steps:

Steps are starting with Given- When- Then with this we can also use And and But. it is our responsibility we should make our steps readable because system does not differentiate between the keywords.

Screenshot from 2017-04-18 13-51-25

Given: Describes the initial context of the system—the scene of the scenario i.e. configures the system to be in a well-defined state.

When: It is used to describe an event, or an action on the Given context, if any.

Then: It is used to describe an expected outcome, or result. We should use assertion to validate whether the actual result matches the expected result.

Hope the blog helps you.

Written by 

Principal Architect at Knoldus Inc

3 thoughts on “Basic of The Gherkin Language

Leave a Reply

%d bloggers like this: