Saturday, April 22, 2023

 

What is BDD in selenium?

What is BDD

BDD (Behavior Driven Development) is software development approach that allows developer or tester to create the script base on the behavior or functionality of the application.

The steps of behavior or functionality, user write in feature file in plain English language which is called as “Gharkin” language. This help a common user understand the scenarios which are covered for specific functionality.

In BDD, user write scenario in feature file and the implementation of those scenarios will be mentioned in the form of code in step definition which is also called as glue code.

How to write BDD test cases in cucumber?

There are 3 important components for writing test case in cucumber.

Feature file:-

Feature file is used to write a scenarioes with its steps in plain English language. This file can be created with extension ".feature". User can write multiple scenarios and can pass multiple parameters to single scenario. There can be multiple feature file in one project based on the functionality.

Step definition:-

This is use to write the implementation of the steps mentioned in feature file. This is a java class where user writes the methods for each steps.

Runner Class:-

This class is used to execute a script. It has Junit annotations such as

@runwith, which is the starting point of execution.

@cucumberoptions, which is use to do required configuration such as path of feature file, path of glue code etc…

Step in Feature file

    Feature: This is my first feature
    Background:
    Given Launch the website
    @test
     Scenario Outline: I want to launch shoping url
    
    Given user logged in to website                     

Step definition

@Given("^user logged in to website$")
 
 public void already_login() 
 {
 System.out.println("Thisis Given");

 }

Test Runner Class

import org.junit.runner.RunWith;
import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;

@RunWith(Cucumber.class)
@CucumberOptions(
		features = {"src/test/java/org/feature"},
		glue = {"org.Teststep"}	,
		tags= "@test",
		monochrome = true
		)

Cucumber runner class maven dependency

    <dependency>
            <groupId>io.cucumber </groupId>
            <artifactId>cucumber-java </artifactId>
            <version>6.10.4 </version>
            <scope>test </scope>
     </dependency>

      <dependency>
            <groupId>io.cucumber </groupId>
            <artifactId>cucumber-junit </artifactId>
            <version>6.10.4 </version>
             <scope>test </scope>
      </dependency>

     <dependency>
            <groupId>junit </groupId>
            <artifactId>junit </artifactId>
            <version>4.13.2 </version>
             <scope>test </scope>
     </dependency>
        

1 comment:

Translate

Popular Posts

Total Pageviews