Force Cucumber to execute the scenarios in a particular order

sanaku picture sanaku · Apr 7, 2016 · Viewed 7k times · Source

I have a feature file with 5 scenarios :

@Scenario_1
@labelA
Given....

@Scenario_2
@labelB
Given....

@Scenario_3
@labelA
Given....

@Scenario_4
@labelA
Given...

@Scenario_5
@labelB
Given...

On my system, it executes in the same order in which it is present on the FF - 1,2,3,4,5. However, on a VM, it executes in any random order, like 4,1,5,3,2.

I need 1 to be compulsorily executed before 2, and 2 to be compulsorily executed before 3 and so on. Is there a way to force Cucumber to run the scenarios in the order in which they are present in the feature file ?

Answer

Bastien Gallienne picture Bastien Gallienne · Apr 5, 2019

to do this one way is : to order the features at the lauching of the cucumber executable :

i.e.

./cucumber.sh myfeatures\second\1.feature features\first\2.feature features

where will be executed in order:

  1. myfeatures\second\1.feature, then

  2. features\first\2.feature, then

  3. features.