【问题标题】:TestNG+Cucumber parallel tests run on same chrome instanceTestNG+Cucumber 并行测试在同一个 chrome 实例上运行
【发布时间】:2019-01-02 13:59:14
【问题描述】:

每当我们将测试套件作为“测试”与 TestNG xml 文件并行运行时,它都会打开 chrome 驱动程序的两个实例,但会在同一 chrome 窗口中中间执行两个黄瓜功能。

给我们一些这样的结果: 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>

我们为每个测试使用一个测试运行器。所有测试运行器基本相同。这是使用的测试运行器:

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>

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

【问题讨论】:

    标签: java maven selenium testng cucumber-java


    【解决方案1】:

    为每个功能创建单独的运行程序文件对我来说没有意义。您是否尝试过“cucumber-jvm-parallel-plugin”来运行这些功能。请检查以下答案: How to execute cucumber feature file parallel

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

    【讨论】:

    • 谢谢。我认为问题在于我们正在使用静态驱动程序并且会话处理变得混乱。但我们设法让它恢复运行
    • 太棒了.. 很高兴听到这个 ???.. 编码愉快
    【解决方案2】:

    为了最大限度地利用 TestNG,您应该使用 Testng 的 QAF 框架。它支持多个bdd syntax,包括使用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>
    

    【讨论】:

      猜你喜欢
      • 2021-03-06
      • 1970-01-01
      • 1970-01-01
      • 2017-01-09
      • 2021-02-20
      • 2022-08-11
      • 2018-09-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多