How to run cucumber jvm test scenarios in parallel using Maven and courgette?

cucumber-jvm-parallel-plugin
running cucumber scenarios in parallel java
maven courgette-jvm

I am attempting to run a suite of Junit cucumber Features in Maven based on cucumber tags. I can get them to run sequentially but not in parallel. I found a package called Courgette that should eliminate this issue for me.

However I am unable to get the test to run I have looked at the example maven project at github It runs fine with Cucumber.class but throws an error with courgette.

Any help would be greatly appreciated.

I have included the following in the pom

<repositories>
        <repository>
            <id>jcenter</id>
            <url>https://jcenter.bintray.com/</url>
        </repository>
</repositories>
<dependency>
    <groupId>io.github.prashant-ramcharan</groupId>
    <artifactId>courgette-jvm</artifactId>
    <version>2.4.4</version>
    <type>jar</type>
</dependency>

I am invoking my runner as such.

import courgette.api.CourgetteOptions;
import courgette.api.CourgetteRunLevel;
import courgette.api.junit.Courgette;
import cucumber.api.CucumberOptions;
import org.junit.runner.RunWith;

@RunWith(Courgette.class)
@CourgetteOptions(
        threads = 1,
        runLevel = CourgetteRunLevel.FEATURE,
        rerunFailedScenarios = false,
        showTestOutput = true,
        cucumberOptions = @CucumberOptions(features="src/test/resources/Features/Online/Regression/",
        plugin={"html:target/OD.html","json:target/OD.json"
                },tags={"@Max"},
                glue="com.Online"
                ))
 public class ONLINE_Regression_RunnerTest {
}

I'm getting the following error.

java.lang.IncompatibleClassChangeError: Implementing class

    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at cucumber.runtime.io.ResourceLoaderClassFinder.loadClass(ResourceLoaderClassFinder.java:38)
    at cucumber.runtime.io.ResourceLoaderClassFinder.getDescendants(ResourceLoaderClassFinder.java:26)
    at cucumber.runtime.Reflections.instantiateSubclasses(Reflections.java:28)
    at cucumber.runtime.Runtime.loadBackends(Runtime.java:99)
    at cucumber.runtime.Runtime.<init>(Runtime.java:66)
    at courgette.runtime.CourgetteFeatureLoader.createRuntime(CourgetteFeatureLoader.java:60)
    at courgette.runtime.CourgetteFeatureLoader.<init>(CourgetteFeatureLoader.java:30)
    at courgette.api.junit.Courgette.<init>(Courgette.java:39)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)
    at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:49)
    at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

Note that Cucumber-jvm offers parallel options as of v4.x

GitHub, extension of Cucumber-JVM with added capabilities to run cucumber tests in parallel on a Supports JUnit and TestNG; Can be used with Gradle and Maven. Cucumber can be executed in parallel using TestNG and Maven test execution plugins by setting the dataprovider parallel option to true. In TestNG the scenarios and rows in a scenario outline are executed in multiple threads. One can use either Maven Surefire or Failsafe plugin for executing the runners.

By moving the dependency to the top of my pom I was able to eliminate the conflict. Seemed like there was a conflict with the test ng dependencies.

Courgette-JVM, to get the test to run I have looked at the example maven project at github It runs fine with Cucumber.class but throws an error with courgette. In JUnit, only the feature files run in parallel rather than the scenarios themself. So basically, all the scenarios in a single feature file will be executed by the same single thread. As a test runner, we can either use Maven Surefire or Failsafe plugin. TestNG. Execution of cucumber scenarios and the rows in scenario outlines is absolutely

There are N No of ways (mentioned below) in which parallel execution can be implemented and one of the most preferable way could be of using Cucumber starting from V 4.0.0 (Specially when we have to implement parallel execution only on multiple browsers not on multiple OS)

  1. Cucumber-JVM-Parallel-Plugin
  2. TestNG
  3. Selenium Grid
  4. Docker
  5. Courgette-JVM

In Order to implement 4.0.0, please use below set of cucumber dependencies along with Maven configuration and we shall implement dependency injection as well.

 <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>4.2.3</version>
        </dependency>

        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>4.2.3</version>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
        </dependency>

        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>datatable</artifactId>
            <version>1.1.12</version>
        </dependency>

        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-testng</artifactId>
            <version>4.2.3</version>
        </dependency>

        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-picocontainer</artifactId>
            <version>4.2.3</version>
        </dependency>

Maven Surefire Configuration -

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>${maven-surefire.plugin.version}</version>
        <configuration>
            <parallel>methods</parallel>
            <threadCount>1</threadCount>
            <reuserForks>false</reuserForks>
            <testFailureIgnore>true</testFailureIgnore>
            <redirectTestOutputToFile>true</redirectTestOutputToFile>
            <includes>
                <include>**/*RunCukeTest.java</include>
            </includes>
        </configuration>
    </plugin>   

Zucchini, Zucchini sits on top of cucumber-jvm and maven to provide higher testing as the cucumber feature files to execute and zucchini runs the tests in parallel with a​  Addressing slow test runs when using Cucumber JVM with web automation tools. UPDATE March 2016: While the content of this post still accurately describes an approach to running cucumber scenarios in parallel, the associated sample code is by now somewhat out of date.

io.github.prashant-ramcharan:courgette-jvm 2.4.0 on Maven , Courgette-JVM is an extension of Cucumber-JVM with added capabilities to run cucumber tests in parallel on a feature level or on a scenario  ----- T E S T S ----- Running Parallel01IT Running Parallel02IT Running Parallel03IT sample 1 500 20 20 480 sample 2 12345 - 500 20 20 480 sample 2 45678 - 510 20 20 490 sample 2 52345 - 500 20 20 480 sample 2 95678 - 510 20 20 490 1 Scenarios ([32m1 passed[0m) 4 Steps ([32m4 passed[0m) 0m0.431s Tests run: 5, Failures: 0, Errors: 0, Skipped: 0

courgette-jvm, Take a look at Courgette-JVM. You can execute this with a gradle task. It has added capabilities to run cucumber tests in parallel on a feature  Run Cucumber Test from Command Line / Terminal. There are different ways to run Cucumber Test from command line. Tests can be run by using JUnit and Maven as well. But maven is the most suggested way and has extra benefits to it. This is why we started this Project as Maven project.

Related tools, courgette-jvm extension of Cucumber-JVM with added capabilities to run cucumber tests in parallel on a feature level see this artifact on: search.maven.​org Running Cucumber JVM tests in parallel is essential for successful test automation. Better to start automation project with this thought in mind rather get disappointed at a later stage where tests get impossible to run in a feasible time span.

Comments
  • Thanks for this just worked that out my self now. Ah the joys of coding. So in order to get parallel test options with different browsers I can create a runner for each browser. With the cucumber tags I want to run?