Java Cucumber: Take @CucumberOptions from external source like a property file

iamkenos picture iamkenos · Jul 14, 2017 · Viewed 12.4k times · Source

Is it possible to take cucumber option values from a java .properties file?

In this SO post, it shows that it is being passed from CLI.

Here's my sample class:

@RunWith(Cucumber.class)
@CucumberOptions(
        features = {"resources/features/"},
        glue = {"classpath:com/"},
        tags = {"@foo, @bar"}
)
public class UITestRunner {

}

Instead of hardcoding the tags here, I'd like to take it from a property file. Any help is appreciated!

Answer

fg78nc picture fg78nc · Jul 14, 2017

Cucumber will initially look for arguments provided by cucumber.api.cli.Main or @CucumberOptions

But you can override them providing (in this particular order):

  1. The OS environment variable CUCUMBER_OPTIONS
  2. The Java system property cucumber.options
  3. The Java resource bundle cucumber.properties with a cucumber.options property

Once one of described above options is found, it will be used. Overrides are provided in a variable (or property) called cucumber.options or CUCUMBER_OPTIONS. All values, except plugin arguments will override values provided by cucumber.api.cli.Main or @CucumberOptions. Plugin option will add up to the plugins specified by cucumber.api.cli.Main or @CucumberOptions.