• gurleengill2

Gherkin

Gherkin in BDD (Behavior Driven development)


What is Gherkin Language ?


Gherkin is a business readable language which helps you to describe business behavior without going into the details of implementation . It uses plain language and allows users to remove logic details for behavior tests .

The text in gherkin language acts as documentation and skeleton of your automated tests.


This script serves two primary purposes

1.Document User Scenarios

1.Writing an automated tests(BDD)


Gherkin Syntax

Gherkin is a line oriented language.Each line starts with a step and starts with a keyword and ends of the terminal with s


The format looks like follows.


1.Feature : Title of the scenario

2.Given [Precondition or Initial Context]

3.When [Event or Trigger]

4.Then [Expected Output]


Important terms used in Gherkin


  1. Feature

  2. Scenario

  3. Given

  4. When

  5. Then

  6. And

  7. But


Some examples in Gherkin Language


Example 1


Feature : Login Facebook account


Scenario 1

login with valid credential

Given : I am on the login page

When : enter valid username And I enter valid password

And I press “login”

Then I should be on the user's homepage.


Scenario 2

login with invalid username

Given I am on login page

When I enter invalid email and I enter valid password and I press login

Then I see an error message.


Scenario 3

login with invalid password

Given I am on the login page

When I enter valid email and I enter invalid password I and press login

Then I see an error message.


Scenario 4

login with valid phone number

Given I am on the login page

When I enter a valid phone number registered with my account and i enter valid password and I press login

Then I should be on the user's homepage.


Scenario 5

login with invalid phone number

Given I am on the login page and i enter a invalid phone number and i enter a valid password and I press login

Then I should see an error message .


Example 2


Feature: Buy Now Button on an online shopping site.


The user should be able to add one or more products to their online shopping cart by clicking on a button provided the user in on a valid product page and there are enough products in stock. The button should add the selected number of items in the cart.


Scenario 1 :User wants to add a product to his cart

Given : the user is on the product page And the product is in stock

When :he clicks the buy now button

Then : one of the products is added to the cart.


Scenario 2: User Wants to add two products to the cart

Given :the user is on product page and there are two or more products in stock

When: the user selects two products and clicks on the buy now button

Then : two products should be added to the cart.


Scenario 3 : user wants to add more than two products to the cart.

Given : the user is on the product page and there are no more then two products in the stock

When the user selects three products and clicks on the buy now button

Then a pop up appears warning that there are only two products in stock


Example 3


Feature : Making payment online for shopping


Scenario 1 :Valid Credit card number

Given : the user has items added on to his shopping cart and items are in stock

When the user add credit card number to make payment online and valid address associated with the credit card

Then : the payment should be made successfully


Scenario 2 : Valid Credit Card number but invalid address

Given : the user has items added onto his shopping cart and the items are available in stock

When the user enters valid credit card number but invalid address

Then the payment fails and error message pops up with invalid address.















19 views0 comments

Recent Posts

See All

BDD - GHERKIN FOR OCTOPARSE APPLICATION

Octoparse is a web scrapping tool used to extract web data without coding.You can use the free version where you can work up to ten task or paid subscription with more service included. Let's see some

 

© Numpy Ninja.