TestNG+Cucumber 在同一个 chrome 实例上并行测试 运行

TestNG+Cucumber parallel tests run on same chrome instance

每当我们 运行 我们的测试套件作为 "tests" 与 TestNG xml 文件并行时,它会打开 chrome 驱动程序的两个实例,但中间执行两个黄瓜功能与 chrome 相同 window。

给我们这样的结果: Searches two times in the search bar

这是我们拥有的 Maven 依赖项:

<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>

我们为每个测试使用一个测试 运行ner。所有的测试 运行ners 基本上是一样的。这是 运行ner 使用的测试:

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();
    }
}

这是 TestNG xml 套件:

<?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>

我们已经对可能导致此行为的原因进行了大量研究,但直到现在我们还无法确定是什么导致了此行为

为每个功能创建单独的 运行ner 文件对我来说没有意义。您是否尝试过 "cucumber-jvm-parallel-plugin" 到 运行 的功能。请检查以下答案:

此外,根据我的经验,这是您正在实例化的驱动程序的问题,它要么是静态的,要么没有得到正确管理。首先,尝试上面的link,同时让我在一个新的自动化框架中实现并行执行,我将把代码贴在这里

要最大限度地利用 TestNG,您应该使用 Testng 的 QAF framework. It supports multiple bdd syntax including gherkin using GherkinFactory

QAF 将每个场景视为 TestNG 测试,将场景大纲视为 TestNG 数据驱动测试。由于qaf内置了驱动管理和资源管理,你不需要为驱动管理和资源管理写一行代码。您需要做的就是根据您的要求创建 TestNG xml 配置文件,以 运行 并行方法(场景)或组或 xml 在一个或多个浏览器上进行测试。

下面的示例将 运行 个并行场景。

<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>

它实现了不同的可能configuration combinations。这是另一个示例,它将 运行 在两个浏览器中并行执行的场景。您可以为每个浏览器配置线程数作为标准 TestNG xml 配置。

<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>