What Is the Gherkin Language?

by Viktoria Byk | April 12, 2017 8:29 am

Note: this article was updated in August 2019.

Gherkin is a line-oriented language such as Python. The language may serve as project documentation, e.i., describes business logic of the system, and as a basis for writing automated tests using the Cucumber tool.
Gherkin has the structure of the natural language and describes the object in a form of narration. Its main advantage is that the language is comprehensible to humans. Gherkin has 10 keywords: given, when, then, and, but, scenario, feature, background, outline, examples.

Gherkin keywords

  1. Feature – a short but full description of the functional.
  2. Scenario – a particular business situation or behavior (it can be reviewed as the steps to reproduce[1]).
  3. Scenario Outline helps to reduce the code and specify several parameters in one scenario.
  4. Background can be an attribute of Scenario (it should be brief and comprehensive).

Every feature includes several scenarios, while every scenario consists of the list of specified steps. At the beginning of every step, there is one keyword – Given, When, Then, But or And. For example, the input of invalid email by a user should be prevented. Within Gherkin syntax, the same requirement looks like this:

If a user inputs an email that does not include @, when he/she tries to submit the form, the error message with advice to enter valid email should be displayed.

As a result, you have a concrete requirement – acceptance criterion – that is easier to comprehend and that prevents the issue occurrence. Such criteria can be prepared by a Product Manager before the team starts working on a feature. As they are written in a human-understandable way, designers and other members of the project team can easily interpret a user flow.

As it’s been mentioned before, Gherkin is also used as a skeleton for automated tests. It can be implied for Agile projects[2]. Let’s review such cases in more details.

Automation testing with Gherkin in Agile teams

Rather often Agile teams apply BDD (Behavior-Driven Development) approach where software development starts with the preparation of user stories and acceptance criteria. And we’ve already known that these criteria can be written using Gherkin.

QA and BDD automation

For automation of acceptance criteria testing, Cucumber is used. It is a tool that runs automated acceptance tests[3] prepared in BDD format. Cucumber also enables the translation of plain-text descriptions written in Gherkin into automated tests. For example:

example of Gherkin language

To experience Gherkin advantages, you should keep in mind some principles while writing scripts.

Recommendations on preparing Gherkin scripts

Gherkin is a simple language that can be understood by non-programmers. It serves as a format for Cucumber specification and as a functional specification. However, to prepare Gherkin scripts, you should be deeply engaged in business logic.

Learn more from QATestLab

Related Posts:

Endnotes:
  1. the steps to reproduce: https://blog.qatestlab.com/2019/08/08/choose-project-methodology/
  2. Agile projects: https://blog.qatestlab.com/2019/06/27/agile-project-reporting/
  3. automated acceptance tests: https://qatestlab.com/services/test-automation/
  4. Software Development (Doesn’t) Need Independent QA: https://blog.qatestlab.com/2024/11/14/software-development-doesnt-need-independent-qa/
  5. Is Your E-commerce Ready for Black Friday & Cyber Monday? Let’s Check!: https://blog.qatestlab.com/2024/11/12/is-your-e-commerce-ready-for-black-friday-and-cyber-monday/
  6. Quality Assurance for Renewable Energy Software: How to Do It Right?: https://blog.qatestlab.com/2024/10/17/quality-assurance-for-renewable-energy-software-how-to-do-it-right/

Source URL: https://blog.qatestlab.com/2017/04/12/gherkin-language-notion/