简体   繁体   English

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

[英]TestNG+Cucumber parallel tests run on same chrome instance

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. 每当我们使用TestNG xml文件将测试套件作为“测试”并行运行时,它都会打开chrome驱动程序的两个实例,但是会在chrome的同一窗口中中间执行两个黄瓜功能。

Gives us some result like this: Searches two times in the search bar 给我们这样的结果: 在搜索栏中搜索两次

This are Maven dependencies we have: 这是我们的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>

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: 这是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>

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 我们已经对导致此行为的原因进行了大量研究,但直到现在我们还无法确定导致此行为的原因

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. 您是否尝试过“ cucumber-jvm-parallel-plugin”来运行这些功能。 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 首先,尝试上面的链接,同时让我在新的自动化框架中实现并行执行,并将代码粘贴到此处

To take maximum advantage of TestNG you should use Testng's QAF framework. 为了最大程度地利用TestNG,您应该使用Testng的QAF框架。 It supports multiple bdd syntax including gherkin using GherkinFactory . 它使用GherkinFactory支持多种bdd语法,包括gherkin

QAF considers each scenario as TestNG test and Scenario Outline as TestNG data-driven test. QAF将每个方案视为TestNG测试,并将方案大纲视为TestNG数据驱动测试。 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. 由于qaf提供内置的驱动程序管理和资源管理,因此您无需编写任何代码即可进行驱动程序管理或资源管理。 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. 您所需要做的就是根据您的要求创建TestNG xml配置文件,以在一个或多个浏览器上运行并行方法(场景)或组或xml测试。

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. 您可以将每个浏览器的线程数配置为标准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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM