top of page
hand-businesswoman-touching-hand-artificial-intelligence-meaning-technology-connection-go-

How to glue a Feature file to specific Step Definition file in cucumber

In order to automate any application in Cucumber tool, we need to create 3 files

  1. Feature file

  2. Step Definition file

  3. Runner file


When i was working on my first cucumber project, i have a faced an issue where my feature file is getting glued to incorrect Step Definition file. Here is the issue.


https://numpyninjaworkspace.slack.com/files/U028E01TPHA/F02F01C11B7/video.mov



Initially I thought we need to have only one feature file with distinct gherkins. We can't re-use the gherkins in other feature files. But you can re-use gherkins . You have to create a runner file and glue the specific step to specific feature file. We have to create runner file under src/tst/java/StepDefinition. Here is the syntax.


package StepDefinition;

import org.junit.runner.RunWith;

import io.cucumber.junit.Cucumber;

import io.cucumber.junit.CucumberOptions;


@RunWith(Cucumber. Class)

@CucumberOptions(features="src/test/resources/features", glue={"StepDefinition"},

plugin = {"pretty","html:target/HtmlReports1/report.html",

"json:target/JSONReports/report.json",

"junit:target/JUnitReports/report.xml"}

)

public class Runner {

}


This way we can have feature file connected to appropriate step definition file.


539 views0 comments

Recent Posts

See All
bottom of page