How to order feature files in Cucumber test suite?
Asked Answered
B

6

12

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.

Blanche answered 5/8, 2016 at 5:22 Comment(6)
Cucumber scenarios must be decoupled and independent of each other, hence it must make no difference in what order they will run. If you have scenarios that depend on previously executed ones, I suggest to review your design.Amber
I agree with you. However, I need a way to run them in a particular order. :)Blanche
Why do you need to run them in a specific order?Pome
If you have dependencies between scenarios then I hope this is a short term job because you will have a maintenance nightmare in the future.Ebony
I need to run them in some order so because: - It takes an hour to run the whole UI side feature files.Respiration
As @EugeneS suggests, Yes, it is true. Scenarios should be independent of each other. But there are some cases that we will not be able to separate scenarios without much overhead especially when writing complex features. It will be better if Cucumber provides a mechanism to mark dependent feature files and let the end-user manage the test execution flow. ( like JBehave supports dependant stories, Yes. stories and features are different but the flexibility JBehave provides is great )Driskell
A
6

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

Astrophysics answered 24/7, 2018 at 8:56 Comment(0)
A
14

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"})
Accountant answered 18/8, 2016 at 10:25 Comment(1)
do we have the same thing in behave? (for python)Rockefeller
A
6

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

Astrophysics answered 24/7, 2018 at 8:56 Comment(0)
P
5

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

Perfect answered 27/1, 2020 at 20:50 Comment(0)
H
3

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)
Hesione answered 5/8, 2016 at 5:41 Comment(0)
D
1

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 {
}
Driskell answered 12/11, 2021 at 7:43 Comment(0)
B
0

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",
   },
Banshee answered 5/7, 2022 at 4:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.