Selenium: BDD- The Disruptive Framework
As we learnt about different selenium automation framework in last post, now it is time to focus on one particular framework which will shape the future of selenium automation testing and that is nothing but Behavior Driven Development (BDD) framework !
BDD serves as a bridge between tech and non-tech people which includes but not limited to developers, testers, clients and business analysts. In BDD, we can write our automation tests in general English like language which can be understand by all the stake holders and eventually it paves the way for smoother functioning and more productive environment. With the coming of agile model, concepts such as BDD has found more meaning and usage. The important feature of BDD is that it includes all the stake holders.
Features of BDD:
- Collaboration between developer team, QA team, client and business analysts.
- It uses plain English like language 'Gherkin' to describe tests.
- It augments business value by thinking in terms of behavior.
- It extends TDD by ubiquitous language gherkin which can be understand by non-tech people also.
- 'Cucumber' and 'JBehave' are two such popular BDD frameworks.
Feature File:
This is the main component of BDD framework as here we describe our test scenario in gherkin language. It follows some syntax as it is structured language. Generally, we use three main keywords 'Given', 'When' and 'Then' while writing one particular test automation scenario.
Let us see one example:
Feature: Login functionality on login page of Application
Scenario: Verification of login
Given Open the Firefox and launch the application
When Enter the Username and Password
Then Close the Browser
Steps:
This is the actual class where we write our code.
package StepDefination;
@SuppressWarnings("unused")
public class Steps {
@Given("^Open the Firefox and launch the application$")
public void open_the_Firefox_and_launch_the_application() throws Throwable
{
// need to write code here
}
@When("^Enter the Username and Password$")
public void enter_the_Username_and_Password() throws Throwable
{
// need to write code here
}
@Then("^Close the Browser$")
public void Reset_the_credential() throws Throwable
{
// need to write code here
}
}
Here, we are binding our features with the actual code.
Runner:
This one is the class from where we run our scripts.
package TestRunner;
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
@RunWith(Cucumber.class)
@CucumberOptions(features="Features",glue={"StepDefination"},monochrome=true)
public class Runner
{
}
This is one demo scenario which is implemented through BDD framework. We will see more such BDD functions and options in coming posts.
Cheers !
Good explanation. Keep it up Raj.
ReplyDeleteThank you. keep learning :)
Delete