slarge
slarge

Reputation: 644

Run scenarios in a cucumber feature file in parallel, one feature file at a time

I am using Maven SureFire, TestNG (extending AbstractTestNGCucumberTests) and Cucumber and have several feature files which each have several scenarios. I want to be able to run each scenario in a feature file in parallel but only one feature file at a time. Is this possible?

So to give an example:

Feature file 1
  Scenario 1a
  Scenario 1b
  Scenario 1c

Feature file 2
  Scenario 2a
  Scenario 2b

Feature file 3
  Scenario 3a
  Scenario 3b
  Scenario 3c
  Scenario 3d

I want Scenarios 1a, 1b and 1c to run in parallel in feature file 1. Once those are complete run Scenarios 2a and 2b from feature 2 etc.

This is the test class that runs all scenarios from all features files at once currently.

@CucumberOptions (
    plugin = {
        "html:target/cucumber-reports",
        "json:target/cucumber.json",
        "usage:target/cucumber-usage.json"
    },
    tags = "not @disabled",
    monochrome = true,
    features = {
         "src/test/resources/features/feature1.feature",
         "src/test/resources/features/feature2.feature",
         "src/test/resources/features/feature3.feature",
    })
public class AllTests extends AbstractTestNGCucumberTests {

    @Override
    @DataProvider(parallel = true)
    public Object[][] scenarios() {
        return super.scenarios();
    }
}

Is this possible using configuration

Thanks, Scott.

Upvotes: 1

Views: 1601

Answers (1)

Krishnan Mahadevan
Krishnan Mahadevan

Reputation: 14746

This is not possible merely with configurations. The reason I say this is because you are expecting a multi level parallel execution strategy from within just a @DataProvider which is NOT possible in TestNG as of today. You would need to leverage a suite xml file for controlling the parallel execution strategy at a higher level, which can then be tweaked at a lower level by leveraging a @DataProvider coupled with a parallel attribute.

The easiest way of getting this done is to do the following:

  1. Create one Java class per feature file.
  2. Create a suite file with "n" classes and define your parallel strategy as "none" (This would force TestNG to pick up each of the classes and run them in sequential manner)
  3. Don't forget to set a desirable data provider thread count (default value is 10) and set the attribute parallel = true in your @DataProvider

Upvotes: 3

Related Questions