Question

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 {
    //executs cucumber steps in the class FuelCarSteps
}

The Cucumber features files are now automatically loaded from the classpath location, src/main/resources/<package-name>/*.feature

I could like to know how I can tell cucumber the location of my feature files, because I need it to load them from a location outside the classpath (e.g. data//).

Was it helpful?

Solution

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/"
)

OTHER TIPS

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"

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"})

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 {

}

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top