[英]Cucumber 6 + JUnit 5 + Spring Parallel Scenarios Execution
我一直在閱讀大量文檔、帖子、文章,據說在單個功能文件中並行運行場景的開箱即用解決方案是不可能的。 我們可以使用maven-surefire-plugin並行運行不同的功能文件,但不是場景。
例如,有一個包含場景的功能文件:
Feature: Parallel Scenarios
Scenario: First
...
Scenario: Second
...
Scenario: Third
...
我想在單獨的線程中同時運行所有場景。
我怎樣才能做到這一點?
我正在使用testNG
和courgette-jvm
在場景級別運行並行測試。 這是跑步者文件
import courgette.api.CourgetteOptions;
import courgette.api.CourgetteRunLevel;
import courgette.api.CucumberOptions;
import courgette.api.testng.TestNGCourgette;
import org.testng.annotations.Test;
@Test
@CourgetteOptions(
threads = 10,
runLevel = CourgetteRunLevel.SCENARIO,
rerunFailedScenarios = true,
rerunAttempts = 1,
showTestOutput = true,
reportTitle = "Courgette-JVM Example",
reportTargetDir = "build",
environmentInfo = "browser=chrome; git_branch=master",
cucumberOptions = @CucumberOptions(
features = "src/test/resources/com/test/",
glue = "com.test.stepdefs",
publish = true,
plugin = {
"pretty",
"json:target/cucumber-report/cucumber.json",
"html:target/cucumber-report/cucumber.html"}
))
class AcceptanceIT extends TestNGCourgette {
}
然后使用常規的 webdriver 配置,我使用 RemoteWebDriver
protected RemoteWebDriver createDriver() throws MalformedURLException {
//wherever grid hub is pointing. it should work without grid too
String hubURL = "http://localhost:xxxx/wd/hub";
ChromeOptions options = new ChromeOptions();
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
return (RemoteWebDriver) (driver = new RemoteWebDriver(new URL(hubURL), capabilities));
}
public RemoteWebDriver getDriver() throws MalformedURLException {
if (driver == null) {
this.createDriver();
}
return (RemoteWebDriver) driver;
}
您可能必須利用這些依賴項
<dependency>
<groupId>io.github.prashant-ramcharan</groupId>
<artifactId>courgette-jvm</artifactId>
<version>5.11.0</version>
</dependency>
<dependency>
<!-- httpclient dpendendecy is to resolve courgette-jvm error - NoClassDefFoundError: org/apache/http/conn/ssl/TrustAllStrategy -->
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.10</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-testng</artifactId>
<version>6.9.1</version>
</dependency>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.