Specify the feature file location in cucumber
Asked Answered
I

5

12

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

Immunoreaction answered 13/12, 2012 at 13:40 Comment(1)
How to specify the path of multiple feature files in CucumberOptionsClinical
I
12

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/"
)
Immunoreaction answered 13/12, 2012 at 22:45 Comment(4)
Do you have an idea on how to specify the feature files to run from maven command line? I'm unable to find any docs for this...Metope
@EldadAK -D"cucumber.options=/features"Filigree
How to specify the path of multiple feature files in CucumberOptionsClinical
= { "feature1", "feature2"}Kv
E
8

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"

Evolutionist answered 2/8, 2016 at 2:59 Comment(4)
The classpath option was one that assisted me in a Maven multi module project. I ended up finding this detail (as well as other location options) in the CLI interface documentation.Motorway
How to specify the path of multiple feature files in CucumberOptionsClinical
Link is returning 404 (not found) error. @MotorwayProfant
@MajidRoustaei Spent a few minutes trying to find the equivalent docs with no success I'm afraid.Motorway
T
0

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"})
Translocate answered 14/4, 2014 at 19:37 Comment(1)
How to specify the path of multiple feature files in CucumberOptionsClinical
G
0

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 {  }
Grindlay answered 20/7, 2014 at 16:58 Comment(0)
S
0

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 {

}
Situate answered 10/2, 2017 at 20:10 Comment(1)
How to specify the path of multiple feature files in CucumberOptionsClinical

© 2022 - 2024 — McMap. All rights reserved.