I have created some cucumber test steps and a small Cucumber test case, which I run with JUnit like so:
@RunWith(Cucumber.class)
public class FuelCarTest {
I have placed all feature files in test/resources/features
and added my feature file location with class path. Here is my cucumber run file.
@RunWith(Cucumber.class)
@CucumberOptions(
monochrome = true,
features = "classpath:features",
plugin = {"pretty", "html:target/cucumber-reports",
"json:target/cucumber.json"
}
)
public class MyTests
{
}
This will pick all feature files inside the folder features. If you want to have a subfolders you can add that too by just replacing the line as shown below.
features = "classpath:features/DEV"
If only one particular feature file, it should be like this
features = "classpath:features/DEV/SmokeTests.feature"
I found the solution,
there is the @Cucumber.Options annotation, among setting the report output format and location, it also allows setting the location for the feature files.
@Cucumber.Options(
format = {
"pretty",
"html:target/cucumber-html-report",
"json-pretty:target/cucumber- report.json"
},
features="features/"
)
You can use @CucumberOptions instead of @Cucumber.Options
@RunWith(Cucumber.class)
@CucumberOptions(
format = "pretty",
tags = {"~@Ignore"},
features = "src/test/resources/com/" //refer to Feature file
)
public class CucumberIT { }
here feature keyword for path of your feature file folder example: my feature files folder located in desktop
so feature keyword value feature="C:\Users\sanjay\Desktop\features"
@RunWith(Cucumber.class)
@CucumberOptions(
features = "C:\\Users\\sanjay\\Desktop\\features"
,glue={"com.stepDefination"}
,monochrome = false,
format = {"pretty", "html:target/Destination"}
)
public class TestRunner {
}
Here you can specify feature file from a folder, tag name and test outputs.
@RunWith(Cucumber.class)
@CucumberOptions(features="src/Login.feature",
format = {"pretty", "html:target/report/",
"json:target/report/cucu_json_report.json",
"junit:target/report/cucumber_junit_report.xml",}
tags ={"@ra1, @ra2"})