TT_
TT_

Reputation: 385

How to order feature files in Cucumber test suite?

Currently, I have found that cucumber test suite runs the feature files alphabetically.

Please let me know if there is any option/configuration that I might be missing. Thanks.

Upvotes: 12

Views: 55089

Answers (6)

You can create a text file with the features and when executing the file it adds all the files in the order defined in the file. @order-execution.txt In this example, the file was created in the project root. file content

./features/records/country.feature
./features/records/company.feature
   "scripts": {
     "test:company": "cucumber-js @order-execution.txt --tags \"@company\" -f json:result/records/company.json",
   },

this is the same as riding this way

   "scripts": {
     "company": "cucumber-js ./features/records/country.feature ./features/records/company.feature --tags \"@company\" -f json:result/records/company.json",
   },

Upvotes: 0

yashodha_h
yashodha_h

Reputation: 1004

If you use Junit 5 with Cucumber you can order the feature files like this.

@Suite
@IncludeEngines("cucumber")
@SelectClasspathResource("this/is/number/one.feature")
@SelectClasspathResource("this/is/number/two.feature")
@SelectClasspathResource("this/is/number/three.feature")
public class RunCucumberTest {
}

Upvotes: 1

cecil tom
cecil tom

Reputation: 51

However, if you specifically specify features, they should be run in the order as declared. For example:

@Cucumber.Options(features={"automatedTestingServices.feature", "smoketest.feature"})

The above one is still in the alphabetical Order. So it wont make any difference

Upvotes: 5

LudmilaN
LudmilaN

Reputation: 124

In cucumber 4.2.0 added cli option --order, see changelog and this example.

Upvotes: 6

user6261348
user6261348

Reputation:

Cucumber features/scenarios are run in Alphabetical order by feature file name.

However, if you specifically specify features, they should be run in the order as declared. For example:

@Cucumber.Options(features={"automatedTestingServices.feature", "smoketest.feature"})

Upvotes: 14

zarak
zarak

Reputation: 3003

You can force cucumber to run the feature files in the order that you pass the filenames as arguments. For example,

$ cucumber file3.feature file2.feature file1.feature

will run the files in the order file3.feature, file2.feature, file1.feature.

You could also create a text file with the names of the feature files in the order that you want, with each name on its own line. For example, suppose the file is named feature_order.txt and it has the following contents:

file3.feature
file2.feature
file1.feature

You can then run the following command to run the files in the above order:

$ cucumber $(cat feature_order.txt)

Upvotes: 3

Related Questions