Gherkin

Gherkin

Table of Contents

Gherkin is a domain particular language which helps you to describe business behaviour without any need for detail implementation. The text acts as documentation and skeleton of our automated tests.

This script has two main purposes:

  • Documents user scenarios
  • Writing automated tests (BDD)

Gherkin Syntax:

Gherkin is line-oriented language like YAML and Python. Here every line is called as step and starts with a keyword and end terminals with stop. In this syntax the comment can be added anywhere you want, but it will start with a # sign reads each line when gherkin’s keywords is removed as given, when, then etc.

Example the script is written as:

Feature: Title of the Scenario
Given [Preconditions or Initial Context]
When [Event or Trigger]
Then [Expected output]

The important terms of gherkin are:

Feature

  • Background
  • Scenario
  • Given
  • When
  • Then
  • And
  • But
  • Scenario outline examples

Feature:

The file has an extension .feature and each feature file must have only one feature the feature keyword starting with Feature and after that add, a space and name of the feature is written.

Scenario:

The feature file may have many scenarios will start with Scenario: followed by scenario name.

Background

Background keyword helps us to add some content to the scenario, but the scenario can be included in the background and the difference is that it should run before scenario.

Given:

The main usage of this keyword is to put the system in a familiar state before user interaction starts with the system. 

The syntax:

Given

Given - a test step that defines the 'content’
Given I am on "/."
When:

This step is to define action performed by user.

Syntax:

When I perform “Sign In.”

Then:

This keyword is to see the outcome after the action in when step.

Syntax:

Then
Then - test step that defines the 'outcome.'
Then I should see "Welcome Tom."

And and But:

Used when we use multiple given, then and when commands. All these are test steps and can be used interchangeably

Syntax

But

A But - additional test step which defines the 'action' 'outcome.'
But I should see "Welcome Tom."
And - additional test step that defines the 'action' performed
And I write "Email Address" with "[email protected]."

https://www.guru99.com/images/tensorflow/082918_1505_WhatisGherk3.png

Example of Gherkin is:

Feature: User Authentication Background:
Given the user is already registered to the website Scenario:
Given the user is on the login page
When the user inputs the correct email address
And the user inputs the correct password
And the user clicks the Login button
Then the user should be authenticated
And user should be redirected to their dashboard
And the user should be presented hit message

Advantages of Gherkin:

  1. Gherkin is simple easy for non-programmers to understand
  2. Programmers can use it as a solid base for starting their tests
  3. By using gherkin user stories can be digested easily.
  4. The scripts of gherkin can be easily understood by business executives and developers.
  5. It targets the business requirements.
  6. A significant proportion of the functional specifications are used as user stories.
  7. Expertise is not necessary to understand the small Gherkin command set
  8. The Gherkin language links acceptance tests directly to automated tests.
  9. Style of writing tests is easier for code reusability in other tests

Disadvantages:

1. It needs a high level business engagements and collaborations.

2. It is not good or works well with all scenarios.

3. Test maintenance costs is increased due to poorly written tests

7 Responses

  1. Gherkin is a domain particular language which helps you to describe business behaviour without any need for detail implementation. The text acts as documentation and skeleton of our automated tests.
    This script has two main purposes:
    1.Documents user scenarios
    2.Writing automated tests (BDD)

    Advantages of Gherkin:
    1.Gherkin is simple easy for non-programmers to understand
    2.Programmers can use it as a solid base for starting their tests
    3.By using gherkin user stories can be digested easily.
    4.The scripts of gherkin can be easily understood by business executives and developers.
    5.It targets the business requirements.
    6.A significant proportion of the functional specifications are used as user stories.
    7.Expertise is not necessary to understand the small Gherkin command set
    8.The Gherkin language links acceptance tests directly to automated tests.
    9.Style of writing tests is easier for code reusability in other tests

    Disadvantages:
    1. It needs a high level business engagements and collaborations.
    2. It is not good or works well with all scenarios.
    3. Test maintenance costs is increased due to poorly written tests

  2. Gherkin is a domain particular language which helps you to describe business behaviour without any need for detail implementation.

    This script has two main purposes:
    1. Documents user scenarios
    2. Writing automated tests (BDD)

    The important terms of gherkin are:
    *Feature
    *Background
    *Scenario
    *Given
    *When
    *Then
    *And
    *But

    The advantages of Gherkin are:

    1.Gherkin is simple easy for non-programmers to understand
    2.Programmers can use it as a solid base for starting their tests
    3.By using gherkin user stories can be digested easily.
    4.The scripts of gherkin can be easily understood by business executives and developers.
    5.It targets the business requirements.
    6.A significant proportion of the functional specifications are used as user stories.
    7.Expertise is not necessary to understand the small Gherkin command set
    8.The Gherkin language links acceptance tests directly to automated tests.
    9.Style of writing tests is easier for code reusability in other tests

    The disadvantages of gherkin are:

    1. It needs a high level business engagements and collaborations.
    2. It is not good or works well with all scenarios.

    3. Test maintenance costs is increased due to poorly written tests.

  3. Gherkin is a domain particular language which helps you to describe business behaviour without any need for detail implementation. The text acts as documentation and skeleton of our automated tests.
    This script has two main purposes:
    1.Documents user scenarios
    2.Writing automated tests (BDD)

    Advantages of Gherkin:
    1.Gherkin is simple easy for non-programmers to understand
    2.Programmers can use it as a solid base for starting their tests
    3.By using gherkin user stories can be digested easily.
    4.The scripts of gherkin can be easily understood by business executives and developers.
    5.It targets the business requirements.
    6.A significant proportion of the functional specifications are used as user stories.
    7.Expertise is not necessary to understand the small Gherkin command set
    8.The Gherkin language links acceptance tests directly to automated tests.
    9.Style of writing tests is easier for code reusability in other tests

    Disadvantages:
    1. It needs a high level business engagements and collaborations.
    2. It is not good or works well with all scenarios.
    3. Test maintenance costs is increased due to poorly written tests

  4. Gherkin is a domain particular language which helps you to describe business behaviour without any need for detail implementation. The text acts as documentation and skeleton of our automated tests.
    This script has two main purposes:
    1.Documents user scenarios
    2.Writing automated tests (BDD)
    Gherkin Syntax:
    Gherkin is line-oriented language like YAML and Python. Here every line is called as step and starts with a keyword and end terminals with stop. In this syntax the comment can be added anywhere you want, but it will start with a # sign reads each line when gherkin’s keywords is removed as given, when, then etc.
    The important terms of gherkin are:
    Feature
    Background
    Scenario
    Given
    When
    Then
    And
    But
    Scenario outline examples
    Advantages of Gherkin:
    *Gherkin is simple easy for non-programmers to understand
    *Programmers can use it as a solid base for starting their tests
    *By using gherkin user stories can be digested easily.
    *The scripts of gherkin can be easily understood by business executives and developers.
    *It targets the business requirements.
    *A significant proportion of the functional specifications are used as user stories.
    *Expertise is not necessary to understand the small Gherkin command set
    *The Gherkin language links acceptance tests directly to automated tests.
    *Style of writing tests is easier for code reusability in other tests
    Disadvantages:
    1. It needs a high level business engagements and collaborations.
    2. It is not good or works well with all scenarios.
    3. Test maintenance costs is increased due to poorly written tests

  5. Gherkin:
    Gherkin is a domain particular language which helps you to describe business behaviour without any need for detail implementation. The text acts as documentation and skeleton of our automated tests.
    This script has two main purposes:
    • Documents user scenarios
    • Writing automated tests (BDD)
    The important terms of gherkin are:
    • Feature
    • Background
    • Scenario
    • Given
    • When
    • Then
    • And
    • But
    • Scenario outline examples

  6. Gherkin is a domain particular language which helps you to describe business behaviour without any need for detail implementation. The text acts as documentation and skeleton of our automated tests.

    This script has two main purposes:

    Documents user scenarios
    Writing automated tests (BDD)
    Gherkin Syntax:
    Gherkin is line-oriented language like YAML and Python. Here every line is called as step and starts with a keyword and end terminals with stop. In this syntax the comment can be added anywhere you want, but it will start with a # sign reads each line when gherkin’s keywords is removed as given, when, then etc.

    Advantages of Gherkin:
    Gherkin is simple easy for non-programmers to understand
    Programmers can use it as a solid base for starting their tests
    By using gherkin user stories can be digested easily.
    The scripts of gherkin can be easily understood by business executives and developers.
    It targets the business requirements.
    A significant proportion of the functional specifications are used as user stories.
    Expertise is not necessary to understand the small Gherkin command set
    The Gherkin language links acceptance tests directly to automated tests.
    Style of writing tests is easier for code reusability in other tests
    Disadvantages:
    1. It needs a high level business engagements and collaborations.

    2. It is not good or works well with all scenarios.

    3. Test maintenance costs is increased due to poorly written tests

  7. Gherkin is a domain particular language that helps you to describe business behavior without any need for detailed implementation. The text acts as documentation and skeleton of our automated tests.This script has two main purposes:
    Documents user scenarios
    Writing automated tests (BDD)

    Advantages of Gherkin:
    1. It is simple and easy for non-programmers, business executives, and developers to understand.
    2. Programmers can use it as a solid base for starting their tests
    3. By using gherkin user stories can be digested easily.
    4. Style of writing tests is easier for code reusability in other tests
    Disadvantages of Gherkin:
    1. It needs a high-level business engagements and collaborations.
    2. It does not work well with all scenarios.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Share this article
Subscribe
By pressing the Subscribe button, you confirm that you have read our Privacy Policy.
Need a Free Demo Class?
Join H2K Infosys IT Online Training
Enroll Free demo class