java - TestNG+Cucumber 并行测试在同一个 chrome 实例上运行
问题描述
每当我们将测试套件作为“测试”与 TestNG xml 文件并行运行时,它都会打开 chrome 驱动程序的两个实例,但会在同一 chrome 窗口中执行两个黄瓜功能。
给我们一些这样的结果: 在搜索栏中搜索两次
这是我们拥有的 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>
我们已经对可能导致这种行为的原因进行了大量研究,但直到现在我们还无法确定导致这种行为的原因
解决方案
为每个功能创建一个单独的运行器文件对我来说没有意义。您是否尝试过“cucumber-jvm-parallel-plugin”来运行这些功能。请检查以下答案: 如何并行执行黄瓜功能文件
此外,根据我的经验,这是您正在实例化的驱动程序的问题,它要么是静态的,要么没有得到正确管理。首先,尝试上面的链接,同时让我在一个新的自动化框架中实现并行执行,我将在这里粘贴代码
推荐阅读
- vb.net - 将 WHERE 子句添加到组连接
- firebase - 在 ionic 3 中使用 changes.map 从 firebase 获取数据时出错
- java - 将现有 Spring Boot 项目从 java 1.8 更新到 java 11
- batch-file - 使用重复命令时如何跳过批处理文件错误
- android - 如何在 Android 的启动画面中显示 Lottie 动画?
- reactjs - 我可以在没有 Node.js 服务器的情况下拥有一个多页面 React 应用程序吗?
- java - 添加 admob 活动后,Android 应用程序未启动
- aws-api-gateway - serverless-offline:如果指定了 http_proxy,自定义授权器将不起作用
- python - Counter() 并绘制文本中最常见的单词
- python - 有人向我解释如何用库解决这个问题?matplotlib