1

I've been reading a lot of documentations, posts, articles and it's said that out-of-box solution to run scenarios in a single feature file in parallel is impossible. We can use maven-surefire-plugin to run in parallel different feature files, but not scenarios.

For example there is a feature file with scenarios:

Feature: Parallel Scenarios

    Scenario: First
        ...

    Scenario: Second
        ...

    Scenario: Third
        ...

And I'd like to run all there scenarios concurrently in separated threads.

How can I achieve this?

Serhii Kachan
  • 345
  • 4
  • 13
  • This is a question I also have, and is driving me a little crazy trying to find the answer; the documentation doesn't make it at all clear if JUnit 5 can run same-file scenarios in parallel or not, just that JUnit 4 definitely can't. It looks like the courgette-jvm library mentioned below supports JUnit as well, so that's something. – quantumferret May 02 '22 at 08:30
  • @quantumferret I've recently switched to same setup but used TestNG rather than JUnit. Configuration was a lot easier than courgette-jvm. Also using a Spring Boot I'm pretty sure you face with single component among different thread issue. There you can register a scope provided by Spring SimpleThreadScope.class – Serhii Kachan May 04 '22 at 11:39

1 Answers1

1

I am using testNG with courgette-jvm to run parallel tests at scenario level . Here is runner file

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 {
}

and then use regular webdriver config, I use 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;
    }

you may have to utilize these dependencies

      <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>
user1207289
  • 3,060
  • 6
  • 30
  • 66