LambdaTest Community

Find answers, support, and inspiration from other users

LambdaTest Community

How can I run parallel tests with Cucumber?

I want somebody's guidance on running parallel tests with cucumber. Can anyone please guide me onto that.

Up Vote Down Vote 0 Votes
Posted 4 months ago


You can use opensource plugin cucumber-jvm-parallel-plugin which has many advantages over existing solutions. Available at maven repository

  1. First you need to add this plugin with required configuration in your project pom file.
         <!-- Mandatory -->
         <!-- comma separated list of package names to scan for glue code -->
         <glue>foo, bar</glue>
          <!-- The directory, which must be in the root of the runtime classpath, containing your feature files.  -->
          <!-- Directory where the cucumber report files shall be written  -->
          <!-- comma separated list of output formats json,html,rerun.txt -->
          <!-- CucumberOptions.strict property -->
          <!-- CucumberOptions.monochrome property -->
          <!-- The tags to run, maps to CucumberOptions.tags property you can pass ANDed tags like "@tag1","@tag2" and ORed tags like "@tag1,@tag2,@tag3" -->
         <!-- If set to true, only feature files containing the required tags shall be generated. -->
         <!-- Generate TestNG runners instead of default JUnit ones. --> 
         <!-- The naming scheme to use for the generated test classes.  One of 'simple' or 'feature-title' --> 
        <!-- The class naming pattern to use.  Only required/used if naming scheme is 'pattern'.-->
        <!-- One of [SCENARIO, FEATURE]. SCENARIO generates one runner per scenario.  FEATURE generates a runner per feature. -->
        <!-- This is optional, required only if you want to specify a custom template for the generated sources (this is a relative path) -->
  1. Now add below plugin just below above plugin which will invoke runner classes generated by above plugin
  1. Above two plugins will do magic for cucumber test running in parallel (provided you machine also have advanced hardware support).

  2. Strictly provided <forkCount>n</forkCount> here 'n' is directly proportional to 1) Advanced Hardware support and 2) you available nodes i.e. registered browser instances to HUB.

  3. One major and most important changes is your WebDriver class must be SHARED and you should not implement driver.quit() method, as closing is take care by shutdown hook.

import cucumber.api.Scenario;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.firefox.FirefoxDriver;

public class SharedDriver extends EventFiringWebDriver {
    private static WebDriver REAL_DRIVER = null;

    private static final Thread CLOSE_THREAD = new Thread() {
        public void run() {

    static {

    public SharedDriver() {

    public static WebDriver CreateDriver() {
        WebDriver webDriver;
        if (REAL_DRIVER == null)
            webDriver = new FirefoxDriver();
        return webDriver;

    public static void setWebDriver(WebDriver webDriver) {
        this.REAL_DRIVER = webDriver;

    public static WebDriver getWebDriver() {
        return this.REAL_DRIVER;

    public void close() {
        if (Thread.currentThread() != CLOSE_THREAD) {
            throw new UnsupportedOperationException("You shouldn't close this WebDriver. It's shared and will close when the JVM exits.");

    public void deleteAllCookies() {

    public void embedScreenshot(Scenario scenario) {
        try {
            byte[] screenshot = getScreenshotAs(OutputType.BYTES);
            scenario.embed(screenshot, "image/png");
        } catch (WebDriverException somePlatformsDontSupportScreenshots) {
  1. Considering you want to execute more than 50 threads i.e. same no of browser instances are registered to HUB but Hub will die if it doesn't get enough memory therefore to avoid this critical situation you should start hub with -DPOOL_MAX=512 (or larger) as stated in grid2 documentation.
Really large (>50 node) Hub installations may need to increase the jetty threads by setting -DPOOL_MAX=512 (or larger) on the java command line.

java -jar selenium-server-standalone-<version>.jar -role hub -DPOOL_MAX=512
Up Vote Down Vote 0 Votes
Posted 2 months ago