How does BDD Framework work in Automation?

– Behavior Driven Development (BDD) Framework provides testers a platform to automate manual test cases/scenarios and develop their scripting in plain English – which can be understood across different teams.

– BDD focuses mainly on the behavior of the product and user acceptance criteria

– BDD uses a software tool as Cucumber to write and execute the tests.

– Cucumber is a software testing tool extensively used in helping to build the BDD framework and it works on many different programming languages such as Java, Python etc.

In Behavior driven Framework, there is a certain process and detailed steps that have to be practiced and followed to write and develop the test scenarios and test cases such that every team is aware of the nature of tests performed.

– it’s written in Gherkin language, a simple language with little or no jargon and can be read or understood by almost anyone

Gherkin language uses a GIVEN ->WHEN->THEN approach

Given – The given conditions/ scenario – ex- generating a report

When – Performing some action – setting date, type of report and time

And – Adding another condition along with the existing condition – like generate only if reports page is visible

Then – Expected Result – report generated with the conditions set by user

You can find the sample design for BDD framework  below – 

The different steps/components in a BDD framework pattern –

  • Feature File –

A feature file contains the scenarios which the tester wants to perform

Ex – Scenario – User is searching for a product name in the Search page

Given – User has a search field to search for the product name

When – User starts searching for the product name in the product search bar

And – The products page is visible

Then – The product with the name and details should be visible in the products page

  • Step Definition – It’s an approach which is performed step by step where the feature functionality is mentioned in the annotations and the logic to perform the action is written as a program step by step using methods/ functions for each action performed.

Ex- in the above scenario taking example of searching for a product in the Products page

@Given – (“The user is logging in to the Homepage”)

// code will be written using java and Selenium for performing the above action

// the code will cover the steps of user logging in to the webpage with their credentials.

@When(“The user searches for the product name in the search bar”)

// Code will be written to enter the device name is search field using Java and Selenium

// This code will enter the product name in search box and wait for product details to appear

@And(“The products page is visible”)

// code to check if products page is visible

@Then(“The name of product searched by user and details of the product will be displayed to the user in the Search page successfully”)

//The code will be written to check whether the searched device is displayed correctly in the device grid

// The code will validate whether the product name is correct and the product name entered is displayed correctly.

  • The Test Runner

The runner class is used to execute the feature files mapped with the step definition in Junit or TestNG so that the execution of the scenario is completed.

It will parse the steps written using Gherkin in step definition and parse the feature file to print out the desired output.

After completing the execution, the output would look something like this – 

Test Output :

Feature – User is searching for a product in the Products Page 

Given – The user is logging in to the Homepage

When – The user searches for the product name in the search bar 

And – The products page is visible 

Then – The name of product searched by user and details of the product will be displayed to the user in the Search page successfully

1 Scenario ( 1 passed)  

3 Steps ( 3 passed).

Benefits of Behavior Driven Framework

  1. Gives the automation testers a clear idea of how to automate the scenario and achieve the expected result.
  2. Helps all the teams understand the tests performed as the output statements are in plain English – This reduces the communication gap between the teams and everybody is on the same page.
  3. The clear demarcation and classification of the step definitions and the code helps the automation tester to keep his code untouched, which helps in the easy maintenance of the scripts. 
  4. Given → When →Then approach gives liberty to the testers to use the same steps as many times as they wish which gradually helps in saving time on the overall testing coverage of the product and also helps to identify bugs quicker and stabilize the product for the customer.

Leave A Comment

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