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.




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.


1,452 views0 comments

+1 (302) 200-8320

NumPy_Ninja_Logo (1).png

Numpy Ninja Inc. 8 The Grn Ste A Dover, DE 19901

© Copyright 2022 by NumPy Ninja

  • Twitter
  • LinkedIn
bottom of page