Reputation: 403
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?
Upvotes: 1
Views: 812
Reputation: 3253
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>
Upvotes: 1