BEHAVIOR DRIVEN DEVELOPMENT WITH GHERKIN

Behavior Driven Development(BDD) is a software development approach that has emerged from Test Driven Development. Both approaches create tests before the coding begins.


Test Driven Development(TDD), focuses more on implementation of the feature, which follows a simple five step process.


  1. Write a test

  2. Run the test and show its fails (red)

  3. Write the code that meets the need of test

  4. Run the test till it passes(green)

  5. Refactor



TDD Cycle



Whereas Behavior Driven Test(BDD),focuses more on systems behavior through examples in simple domain specific language. It is more of an agile ‘as a user’ approach. It improves the communication between tech, non-tech and stakeholders as it uses plain text language called Gherkin.



BDD-Gherkin


Gherkin is a domain specific language which helps to describe business behavior without going into implementation details. Gherkin is designed in such a way even a non programmer can follow.


Gherkin Keywords:


Features: describes the feature

Scenarios: describes the behavior of the system

Steps : Given -> sets up initial state

When -> performs an action

Then -> verify outcomes

You can add And,But to any type of steps as needed.


Here goes some examples using Gherkin,


Feature: Shopping in Amazon


Scenario: login Amazon with valid credentials

Given the user is on amazon login page

When the user entered valid email address and password

And press enter

Then it shows “Hello, Your name” in the top of the home page.


Scenario: invalid username

Given the user wants to sign in to amazon

When the user enter invalid email address and press enter

Then it should pop up “There was a problem We cannot find an account with that email address”


Scenario: invalid password

Given the user wants to sign in to amazon

When the user enter valid email address and invalid password and press enter

Then it should pop up “There was a problem Your password is incorrect ”


Scenario: forgot password

Given the user wants to sign in to amazon

When the user enter valid email address and press enter

And clicks the “forgot your password”

Then it should pop up “Password assistance” window

And ask the user to enter email id or phone number and press continue


Scenario: change the user name before entering the password

Given the user wants to sign in to amazon

And the user entered valid email address and press enter

When the user wants to sign in using different email id

Then the user should click on “change” near the given email id


Scenario: Search for an item

Given the user in amazon website

When the user enter the item, you want to search in the search bar and press enter

Then the user should see products related to the search made.


Scenario: add product to the cart

Given the user is in the product page that he want to buy

When the user click "add to cart"

Then the item should be added to the cart


Scenario: not logged in and trying to place an order

Given the user have added items without logging in

When the user click “Proceed to checkout”

Then it should redirect to login page


Scenario: get a free shipping without prime membership

Given the user logged in and added items to the cart

When the user’s cart subtotal is more than $25

And the items are shipped and sold by amazon

Then the user is qualified for free shipping


Scenario: looking for products which are only prime

Given the user has a prime membership

When the user search for a particular product

And the user selected the prime checkbox

Then users search results should only show prime products


Scenario: deleting items from the cart

Given the user have added some items in the cart

When the user click delete the item in the shopping cart

Then the item is deleted and not showing in the cart again


Scenario: increasing the quantity in the shopping cart

Given user have added some items in the cart

When the user increase the quantity of the item in the shopping cart

Then it should show the selected quantity in the field

And the price should change accordingly


Scenario: to see prime videos in your prime account

Given the user have prime account and logged in

When the user click on “Prime Video” tab on the home page

<