Gherkin Language: Format, Syntax and Examples

Mini Vasudeva
5 min readApr 8, 2021

--

What is Gherkin Language?

Gherkin is a business decipherable language which assists you with depicting business conduct without going into subtleties of execution. It is a space explicit language for characterizing tests in Cucumber design for details. It utilizes plain language to portray use cases and permits clients to eliminate rationale subtleties from conduct tests.

Gherkin Syntax

Gherkin is line-situated language . Each line called step and starts with catchphrase and end of the terminals with a stop. Tab or space are utilized for the space.

Gherkin Syntax look like this:

Feature : Title of the Scenario

Given [precondition]

when[event]

Then [Expected output]

The main keywords in Gherkin are:

  • feature
  • Background
  • Scenario
  • Given
  • When
  • Then
  • And/But
  • Scenario Outline Examples

Now, lets talk about each keyword form the Gherkin syntax.

Feature:

The record ought to have augmentation .highlight and each element document ought to have just one component. The component catchphrase being with the Feature: and after that add, a space and name of the element will be composed.

Background: Foundation watchword assists you with adding some setting to the situation. It can contain a few stages of the situation, however the lone distinction is that it ought to be run before every situation.

Given: The utilization of Given catchphrase is to placed the framework in a natural state before the client begins cooperating with the framework. Notwithstanding, you can preclude composing client associations in Given advances whenever Given in the “Precondition” step.

When: At the point when the progression is to characterize activity performed by the client.

Then: The use of ‘then’ keyword is to see the outcome after the action in when step. However, you can only verify noticeable changes.

And/But: You may have multiple given when or Then.

Scenario: Each element record may have various situations, and every situation begins with Scenario: trailed by situation name.

Examples:

Function : Buy a product from Amazon shopping

1 Scenario: open a amazon website

Given i m on a homepage

When click on search page

Then write the product on search page

2 Scenario : find a product

Given: search a product

When : I need the product

Then: product is on the page

3 Scenario : check the reviews

Then : read the reviews

4 Scenario : Add to the cart

Given : I am on the product page

When :click on the add to cart button

Then: product add in the cart

5 Scenario : check the address

Given : product is in cart

When : write the address

Then : display the address

6 Scenario : address not correct

Given : product is in the cart

When : wrong address

Then : not received a product

7 Scenario: go to the payment option

Given: product is in the cart

When: click to the payment option

Then : payment page display

8 Scenario : valid payment information

Given : product is in the cart

When : submit valid information

Then : payment information show

9 scenario: not valid payment information

Given : product is in the cart

When : put invalid information

Then : invalid information display

10 scenario : submit payment information

Given : on the payment page with product

When: submit payment information

Then : display message “ Thanks for ordering”

11 Scenario : submit invalid payment information

Given : payment page with product

When : Invalid payment information

Then : display message “ order now confirmed”

— — — — — — — — — — — — — — — — — — — — — — — — — — — — —

2 Function : why buy a new laptop or used laptop

  1. Scenario: when to buy a new laptop

Given : search a new laptop

when: laptop not starting

Then : Buy a new laptop

2 Scenario: attend the training

Given : attend online training

when : need laptop to attend the training

Then : Buy new laptop or used laptop

3 Scenario : For Kids online school

Given : choose a laptop

When : kids join online school

Then :kid start online school

4 Scenario : laptop is outdated

Given: search a new advance laptop

When : laptop is not perform well then :

buy a new laptop

5 Scenario : For home use

Given : search a new laptop

when : need a laptop for browsing

Then : browsing start

6 Scenario : for business use

Given :search a laptop

when : need in my business

Then business start

7 Scenario : for my employee

Given search a laptop

when: give laptop to my employee for work

then : employee start working

8 scenario : give gift to my son new laptop

Given : something special

When: his birthday

Then : he is ☺

9 Scenario : buy a old laptop

Given :check a old laptop

‘when :not afford a new laptop

then : buy old laptop

— — — — — — — — — — — — — — — — — — — — — — — — — — — — — —

3 Function : Planning vacation

1 scenario: choose place were kids want to go for vacations

Given : search a place

when : kids want to go for vacation

then: decide a place

2 Scenario : Plan a road trip

Given : check the best route

when : air tickets not affordable

Then : plan the road trip

3 Scenario : plan to go in cruise

Given : find the best cruise

when : want water travel

then: enjoy and fun in cruise

4 Scenario : plan to go by air

Given: choose a best airline

when : save some time

then : spend more time in vacations

5 Scenario : plan to go Disneyland

Given : choose a theme parks

when: kids wants to go Disneyland

then : kids enjoy rides

6 scenario : time period for vacation

Given: Decide a date And days for vacation

when: in holidays

Then: fix days

7 Scenario : Book a Ticket

Given : check a ticket

when: have a money

Then: book a ticket

8 Scenario : Book a hotel or Resort

Given: check available hotels

when: need hotel

Then: finalize a hotel

9 Scenario : train travel

Given : check train travel

when : cant afford air price

Then : finalize a best train

— — — — — — — — — — — — — — — — — — — — — — — — — — — — — —

4 Function :login a facebook

1 scenario: login a facebook

Given : I m on home page

when: want to enter my credantials

then: login into the facebook

2. Scenario: not login into facebook

Given : I m on homepage when: put a wrong userid

Then: show ‘user id is wrong’

3 Scenario : login a facebook

Given : I m on facebbok page

When :I want to check the reviews

when : put a correct password then: page open

4 Scenario: Forgot userid

Given: I m on facebook website

when : click forgot userid

then : sent to email

5 scenario : forgot password

given : open a favebook website

when: click forgot password

then: password sent to email

6 Scenario : not login facebook

Given : open a facebook page

when: put a wrong password

then :show ‘password is not correct’

Originally published at https://www.numpyninja.com on April 8, 2021.

--

--