Search code examples
javacucumberappiumcucumber-java

cucumber feature file to run in order


Problem: I need to run my cucumber .feature file to execute in an order defined by me and rather not to run in the default order which is the folder structure.

I am running Appium for Android Native Apps built using cucumber .features file. on windows machine, running on actual devices.

Now my Runcuckes file looks like below:

package runner;

import org.junit.runner.RunWith;
import org.testng.annotations.Test;

 import cucumber.api.CucumberOptions;
 import cucumber.api.junit.Cucumber;
 import cucumber.api.testng.AbstractTestNGCucumberTests;

 //@RunWith(Cucumber.class)

 @CucumberOptions(features = { "src/test/java/features" }, 
             glue = { "Steps" }, 
             monochrome = true, 
             tags = {  "@CustomerInsightsSurveyPopupGiveFeedback,"
                     + "@TestAccountSceanrios"
                     + "@ShortlistPage,"
                     + "@SavedSearchesPage,"
                     + "@SearchResultPage,"
                     + "@Short,"
                     + "@SuggestedSearch" })

        // public class RunCucke {
         public class RunCucke extends AbstractTestNGCucumberTests {
           }

Solution

  • Running your features or scenarios in order is Cuking the WRONG way.

    In all testing linking one test to another is an anti-pattern. It makes your tests fragile and difficult to debug. Each test should be independent of every other test.

    In Cucumber you use Givens to setup the state of your scenario. When's to actually do something. Then's to check your results. Your scenarios Given's should include everything needed to setup your application so you can do your When.

    Cucumber encourages you to run your scenarios in a random order, and to reset just about everything between each scenario. Don't work against this, you will make things much more difficult if you do.