1

I'm tryting to run our Cucumber JVM tests by few threads in parallel. I'm using standart TastNG approach to do it (via suite XML file) My xml file is:

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="BDD" parallel="methods" thread-count="3" data-provider-thread-count="3">
    <test name="BDD">
        <classes>
            <class name="com.tests.bdd.SimpleBDDTests"></class>
        </classes>
    </test>
</suite>

My test class is:

@CucumberOptions(features = "src/test/java/com/tests/bdd/simpleFeatures")
public class SimpleBDDTests {
private TestNGCucumberRunner tcr;
@BeforeClass(alwaysRun = true)
public void beforeClass() throws Exception {
    tcr = new TestNGCucumberRunner(this.getClass());
}

@AfterClass(alwaysRun = true)
public void afterClass() {
    tcr.finish();
}

@Test(dataProvider = "features")
public void feature(CucumberFeatureWrapper cucumberFeature) {
    tcr.runCucumber(cucumberFeature.getCucumberFeature());
}

@DataProvider(parallel = true)
public Object[][] features() {
    return tcr.provideFeatures();
}}

My feature files are like:

Feature: First test

  @sanity
  Scenario: First simple test
    Given Base check step

I have 4 feature files, which are defines the same scenarios with only one step - Given Base check step

When these features are executed one by one, it works fine, but when i try to run them in parallel, everything gets broken. Almost all of these featres marked as failed with the following exception:

A scoping block is already in progress
java.lang.IllegalStateException: A scoping block is already in progress
    at cucumber.runtime.java.guice.impl.SequentialScenarioScope.checkState(SequentialScenarioScope.java:64)
    at cucumber.runtime.java.guice.impl.SequentialScenarioScope.enterScope(SequentialScenarioScope.java:52)
    at cucumber.runtime.java.guice.impl.GuiceFactory.start(GuiceFactory.java:34)
    at cucumber.runtime.java.JavaBackend.buildWorld(JavaBackend.java:123)
    at cucumber.runtime.Runtime.buildBackendWorlds(Runtime.java:141)
    at cucumber.runtime.model.CucumberScenario.run(CucumberScenario.java:38)
    at cucumber.runtime.model.CucumberFeature.run(CucumberFeature.java:165)
    at cucumber.api.testng.TestNGCucumberRunner.runCucumber(TestNGCucumberRunner.java:63)

I understand that it might be happen because of multi-thread calls to the same step - Given Base check step

So my question is how can i fix that? How can i run these tests in parallel?

PS: I know that it should be possible to do it by JUnit + Maven surefire plugin, but it is not applicable for current project, we need to achieve that goal by TestNG.

Thanks.

  • You can try the link http://sahajamit.github.io/Cucumber-JVM-with-TestNG/. It may be useful. – Murthi Jul 07 '17 at 13:18
  • @Murthi thanks for reply! I already saw that article, but it doesn't work for me... i guess there are some mistakes in that article... – Anton Glushakov Jul 09 '17 at 19:31
  • Possible duplicate of [How to execute cucumber feature file parallel](https://stackoverflow.com/questions/41034116/how-to-execute-cucumber-feature-file-parallel) – Marit Jun 08 '19 at 11:17

0 Answers0