how to control the number of threads for execution in cucumber testNG parallel

1.7k Views Asked by At

I'm trying to run 2 Cucumber tests in parallel and sequential using TestNG and SpringBootTest but when my tests execute the following happens

mvn test

2 browsers open and both navigate to the Wikipedia homepage.

if you add 2 more scenarios it opens those many threads per scenario, I don't have any control over the number of threads to execute.

How to control the number of threads and dataprovider count, any help is appreciated.

Repo : https://github.com/cmccarthyIrl/spring-cucumber-testng-parallel-test-harness

2

There are 2 best solutions below

11
user861594 On

The possible reason is, the runner you are using converts it into testng data driven test with single test with scenarios from each feature file supplied through data-provider. This is not a right approach. However, in testng there is separate property to set thread count for data driven test. You can set data-provider-thread-count in xml configuration file at suite lever or can pass command-line argument -dataproviderthreadcount to specify number of threads.


Better approach

You can look into another library qaf-cucumber with native testng implementation. It is considering each scenario as testng test method gives more control and utilization of each feature of testng. With this library, only scenario with examples are converted as testng data driven test.

You don't need to have additional class to run test. Just use factory available class to have different configuration combinations. Here is sample configuration file:

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="QAF Demo" verbose="1">
    <test name="Web-Suite"  enabled="true">
        <classes>
            <class name="com.qmetry.qaf.automation.cucumber.runner.CucumberScenarioFactory" />
        </classes>
    </test>
</suite>

Note: As of today qaf-cucumber supports cucumber 5.x

2
M.P. Korstanje On

TestNG runs dataproviders with a parallism of 10 by default. You can tell Maven to tell TestNG to use fewer threads.

https://github.com/cucumber/cucumber-jvm/tree/main/testng#parallel-execution

<plugins>
   <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-surefire-plugin</artifactId>
      <configuration>
         <properties>
            <property>
               <name>dataproviderthreadcount</name>
               <value>${threadcount}</value>
            </property>
         </properties>
      </configuration>
   </plugin>
</plugins>