2
votes

Whenever we run our test suite in parallel as "tests" with the TestNG xml file, it opens both instances of a chrome driver, but intermediately executes both cucumber features in the same window of chrome.

Gives us some result like this: Searches two times in the search bar

This are Maven dependencies we have:

<dependency>
    <groupId>info.cukes</groupId>
    <artifactId>cucumber-java</artifactId>
    <version>1.2.5</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>info.cukes</groupId>
    <artifactId>cucumber-jvm-deps</artifactId>
    <version>1.0.5</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>info.cukes</groupId>
    <artifactId>cucumber-testng</artifactId>
    <version>1.2.5</version>
    <scope>compile</scope>
    <exclusions>
        <exclusion>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
        </exclusion>
    </exclusions>
</dependency>

We use a test runner for each test. All test runners are basically the same. Here is a test runner used:

package bdxReport.biAdsDashboard.AdvertisingPerformance.Content;

import cucumber.api.CucumberOptions;
import org.testng.annotations.Test;

@CucumberOptions(
        features = "src/test/resources/FeaturesAdsDashboard/FeaturesAdvertisingPerformance/Content/CheckContentAdvertisingByProduct.feature",
        glue = {"stepDefinitions"},

        format = {
                "pretty",
                "html:target/cucumber-reports/AdsDashboard/TestRunnerCheckContentAdvertisingByProduct-Reports",
                "json:target/cucumber-reports/AdsDashboard/TestRunnerCheckContentAdvertisingByProductReport.json",
                "rerun:target/cucumber-reports/AdsDashboard/TestRunnerCheckContentAdvertisingByProduct-Reports/rerun.txt"
        })
@Test
public class TestRunnerCheckContentAdvertisingByProduct {
    private TestNGCucumberRunner testNGCucumberRunner;

    @BeforeClass(alwaysRun = true)
    public void setUpClass() throws Exception {

        testNGCucumberRunner = new TestNGCucumberRunner(this.getClass());
    }

    @Test(groups = "cucumber", description = "Runs Cucumber Feature", dataProvider = "features")
    public void feature(CucumberFeatureWrapper cucumberFeature) {
        testNGCucumberRunner.runCucumber(cucumberFeature.getCucumberFeature());
    }

    @DataProvider
    public Object[][] features() {
        return testNGCucumberRunner.provideFeatures();
    }

    @AfterClass(alwaysRun = true)
    public void tearDownClass() throws Exception {
        testNGCucumberRunner.finish();
    }
}

And this is the TestNG xml suite:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="BDX Executive Summary Advertising Performance" parallel="tests" thread-count="20" preserve-order="true">
    <listeners>
        <listener class-name="common.testcases.TestCaseListener" />
        <listener class-name="common.testcases.CaptureScreenshotOnFailureListenerBDX"/>
    </listeners>
    <test name="01: Check Advertising Performance Section Data">
        <classes>
            <class name="bdxReport.biExecutiveSummary.AdvertisingPerformance.Data.TestRunnerAdvertisingSectionData" />
        </classes>
    </test>
    <test name="02: Check Advertising Performance Section Content">
        <classes>
            <class name="bdxReport.biExecutiveSummary.AdvertisingPerformance.Content.TestRunnerAdvertisingSectionContent" />
        </classes>
    </test>
</suite>

We have done a lot of research on what could be causing this behavior but until now we haven't been able to determine whats causing this behavior

2

2 Answers

0
votes

Creating a separate runner file for every feature does not make sense to me. Have you tried "cucumber-jvm-parallel-plugin" to run the features. Please check following answer: How to execute cucumber feature file parallel

Further, as per my experience this is the issue with the driver you are instantiating either it is static or it is not being managed properly. Firstly, try above link, in the meantime let me implement parallel execution in a fresh automation framework and I will paste the code here

0
votes

To take maximum advantage of TestNG you should use Testng's QAF framework. It supports multiple bdd syntax including gherkin using GherkinFactory.

QAF considers each scenario as TestNG test and Scenario Outline as TestNG data-driven test. As qaf provides driver management and resource management in-built, you don't need to write single line of code for driver management or resource management. All you need to do is create TestNG xml configuration file as per your requirement either to run parallel methods (scenarios) or groups or xml test on one or more browser.

Below example will run scenarios in parallel.

<test name="Gherkin-QAF-Test" parallel="methods">
   <parameter name="step.provider.pkg" value="com.qmetry.qaf.automation.impl.step.qaf" />
   <parameter name="scenario.file.loc" value="resources/features" />
   <classes>
      <class name="com.qmetry.qaf.automation.step.client.gherkin.GherkinScenarioFactory" />
   </classes>
</test>

It enables different possible configuration combinations. Here is another example where it will run scenarios in two browsers and in parallel. You can configure number of threads for each browser as standard TestNG xml configuration.

<suite name="AUT Test Automation" verbose="0"  parallel="tests">
<test name="Test-on-chrome" parallel="methods">
   <parameter name="step.provider.pkg" value="com.qmetry.qaf.automation.impl.step.qaf" />
   <parameter name="scenario.file.loc" value="resources/features" />
   <parameter name="driver.name" value="chromeDriver" />           
   <classes>
      <class name="com.qmetry.qaf.automation.step.client.gherkin.GherkinScenarioFactory" />
   </classes>
</test>

<test name="Test FF" parallel="methods">
   <parameter name="step.provider.pkg" value="com.qmetry.qaf.automation.impl.step.qaf" />
   <parameter name="scenario.file.loc" value="resources/features" />
   <parameter name="driver.name" value="firefoxDriver" />           
   <classes>
      <class name="com.qmetry.qaf.automation.step.client.gherkin.GherkinScenarioFactory" />
   </classes>
</test>
</suite>