Specify the feature file location in cucumber

40,133

Solution 1

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

Solution 2

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"

Share:
40,133
lanoxx
Author by

lanoxx

I am software developer with focus on web technologies and internet computing. My skills are in Java and the Web stack including HTML5, CSS and Javascript. I also love to program in C in my free time, where I spend time developing applications for Linux using the GTK+ libraries from the Gnome project. Currently I am the maintainer and developer of the tilda terminal. I have a big interest for everything that is open source, especially when it runs on Linux.

Updated on October 10, 2020

Comments

  • lanoxx
    lanoxx over 3 years

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

    • Anjani Kumar
      Anjani Kumar about 4 years
      How to specify the path of multiple feature files in CucumberOptions
  • Eldad Assis
    Eldad Assis over 10 years
    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...
  • Larry Cai
    Larry Cai over 8 years
    @EldadAK -D"cucumber.options=/features"
  • markdsievers
    markdsievers over 7 years
    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.
  • Anjani Kumar
    Anjani Kumar about 4 years
    How to specify the path of multiple feature files in CucumberOptions
  • Anjani Kumar
    Anjani Kumar about 4 years
    How to specify the path of multiple feature files in CucumberOptions
  • Anjani Kumar
    Anjani Kumar about 4 years
    How to specify the path of multiple feature files in CucumberOptions
  • Anjani Kumar
    Anjani Kumar about 4 years
    How to specify the path of multiple feature files in CucumberOptions
  • Majid Roustaei
    Majid Roustaei almost 4 years
    Link is returning 404 (not found) error. @markdsievers
  • markdsievers
    markdsievers almost 4 years
    @MajidRoustaei Spent a few minutes trying to find the equivalent docs with no success I'm afraid.
  • DiZzZz
    DiZzZz over 3 years
    = { "feature1", "feature2"}