Cucumber 6 + JUnit 5 + Spring并行场景执行

9rnv2umw  于 2022-12-10  发布在  Spring
关注(0)|答案(1)|浏览(173)

我阅读了很多文档、帖子和文章,据说 * a在一个特性文件中并行运行场景的开箱即用解决方案是不可能的**。我们可以使用 maven-surefire-plugin 并行运行不同的特性文件,但不能并行运行场景。
例如,有一个包含场景的功能文件:

Feature: Parallel Scenarios

    Scenario: First
        ...

    Scenario: Second
        ...

    Scenario: Third
        ...

我希望在单独的线程中同时运行所有这些场景。
我如何才能做到这一点?

ru9i0ody

ru9i0ody1#

我使用testNGcourgette-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>

相关问题