每当我们使用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>
我们已经对导致此行为的原因进行了大量研究,但直到现在我们仍无法确定导致此行为的原因
答案 0 :(得分:0)
为每个功能创建单独的运行程序文件对我来说没有意义。您是否尝试过“ cucumber-jvm-parallel-plugin”来运行这些功能。请检查以下答案: How to execute cucumber feature file parallel
此外,根据我的经验,这是您要实例化的驱动程序的问题,它是静态的还是未正确管理。首先,尝试上面的链接,与此同时,让我在新的自动化框架中实现并行执行,并将代码粘贴到此处
答案 1 :(得分:0)
要充分利用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>