Welcome back to the Cucumber tutorial series. In the last tutorial of this series, we discussed about BDD frameworks, Cucumber, problems solved by Cucumber, etc.
To know more details, please refer to the following link:
So far, we know what Cucumber is and what it does. It executes the test scripts, which are defined in the feature file (to be covered in subsequent tutorials). This executable feature file is written in a language known as Gherkin. Gherkin is a plain English text language that helps Cucumber interpret and run test scripts.
Gherkin is a plain English text language, but we need to follow its syntax to write a feature file. And this is something we are going to explain in this tutorial.
You will learn the following points in this tutorial:
What is the Gherkin syntax?
The Gherkin language is a simple but powerful way to describe the details within your User Stories. It is meant to be easy enough for people who don’t know how to program but organized enough to show business principles in most real-world areas. Product teams use Gherkin to design tests that help them express their requirements for new products.
Important Terms used in Gherkin
Given - a test step that defines the context Given I am on "/."
A When - a test step that tells you when the "action" performed. When I perform "Sign In."
And & But
A But - additional test step which defines the 'action' 'outcome.' But I should see "Welcome user."
And - additional test step that defines the 'action' performed And I write "Email" with "firstname.lastname@example.org."
Given, When, Then, and, but are test steps. It is possible for you to use them interchangeably. The interpreter doesn’t show any error messages. However, they will hardly make sense when read.
Best practices for using Gherkin
- Each scenario should be executed independently.
- Every feature should be executed.
- The steps information should be shown in a different way.
- Make sure your scenarios match your requirements.
- Maintain a complete list of scenarios that should be included in a requirement document.
- Create simple, easy-to-understand steps.
- Make sure you check all your common scenarios.
Advantages of Gherkin
- It is easy for non-programmers to understand.
- For programmers, it can be a very solid base for starting their tests.
- It makes User Stories easier to understand and understand.
- The Gherkin script is easily understood by business executives and developers.
- The goal of Gherkin Testing is to meet the business requirements.
- many more
Disadvantages of Gherkin
- It requires a lot of business involvement and collaboration.
- It may not work in all scenarios.
- Tests that are poorly written can easily increase the cost of testing.