In Cucumber, How to pass the location of the file path such that it works for both Windows and MAC

Viewed 1749

In Cucumber(mvn based java project) we need to specify the location of files (e.g) feature file location in the TestRunner as below

@CucumberOptions(features=("src\\test\\resources\\features"),
                 glue= {"com.testing.stepdefinitions"},
                 strict = true,
                 plugin= {"pretty","html:target/cucumber",
                         "com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter:"}
                 )

public class MyRunner extends BaseClass{
}

How to specific the file path such that it works properly in Windows and MAC ?

2 Answers

Please try the following instead of src\\test\\resources\\features. This will work in both windows and Mac.

@CucumberOptions(features=("./src/test/resources/features"),

For the feature attribute, replace \\ by / such as : src/test/resources/features.
It works in applications on which I use Cucumber (Windows and Unix based OS).
Note that the atrribute javadoc states :

Returns:

the uris to the feature(s)

An uri is composed of slashes, not of backslashes.

As a side note, the backslash is a windows specific way to express a path delimiter. The standard JDK classes that rely on the "path" concept such as File or Path will cope with with slashes on Linux and likewise on Windows. But the reverse is not true.

Related