Generate Step Definition File In Cucumber BDD Framework

In this article, we will discuss how to generate Step Definition file in BDD cucumber Framework.

BDD Framework contains three components,

1. Feature File--> Feature file is written in Gherkin language.

2. Step Definition --> A step definition is a method in a java class with an annotation above it Step definition provides the actual implementation of code for the each gherkin step. Cucumber finds the stepdefinition file with the help of glue code in cucumber options.

3. Runner File.--> This is an important file that helps us to run the BDD Test based on the cucumber options provided.

We can generate step definition file in two way,

Step One - Run the Runner file.

Sample Runner file

package cucumberExample;
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
@RunWith(Cucumber.class)
@CucumberOptions(features = "Feature", glue = {
    "stepDefinition"
})
public class TestRunner {}

Once the runner file is run in the console window, cucumber will provide the step definition code snippets to be implemented in the step definition class

Step Two

In chrome web store we have an extension called Tidy Gherkin, Add the extension to your chrome. 

Launch the App.

Paste the gherkin file in the gherkin area,

Generate step definition file in Cucumber BDD Framework

Down below click the java steps button.

Generate step definition file in Cucumber BDD Framework

You will find the step definition file generated, we can just copy it and use it in our code.

Summary

In this article, I discussed how to generate Step Definition file in BDD cucumber Framework which speeds up the process of writing BDD test cases.

Thank you, Happy learning.....


Similar Articles