Parallel execution is not happening with Cucumber Junit

1.5k Views Asked by At

I made this configuration in POM.xml file to run the test in parallel. But when I call mvn verify using cmd only one browser is running with one feature and after completing execution of one feature file another feature is running. I am using cucumber & cucumber-junit 7.3.2 and particular junit version 4.13.2

Here is my pom.xml code:

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <encoding>UTF-8</encoding>
                    <fork>true</fork>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.0.0-M6</version>
            </plugin>
            
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>3.0.0-M6</version>
                <executions>
                    <execution>
                    <goals>
                    <goal>integration-test</goal>
                    </goals>
                    <configuration>
                            <includes>
                            <include>**/MyTestRunner.java</include>
                            </includes>
                            <parallel>methods</parallel>
                            <threadCount>4</threadCount>
                            <perCoreThreadCount>true</perCoreThreadCount>
                    </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
        </build>
1

There are 1 best solutions below

0
On

I solved it the following way:

  1. Added Junit-Jupiter dependency 5.8.2
  2. Added surefire-junit47 dependency 2.22.2 inside maven-surefire-plugin itself.

This is the latest configuration which I am doing on 13-june-2022. Below is my complete configuration:

<properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.target>1.8</maven.compiler.target>
        <maven.compiler.source>1.8</maven.compiler.source>
        <cucumber.version>7.3.2</cucumber.version>
        <selenium.version>4.1.4</selenium.version>
        <webdrivermanager.version>5.1.1</webdrivermanager.version>
        <org.apache.poi.version>5.2.2</org.apache.poi.version>
        <junit-jupiter-api>5.8.2</junit-jupiter-api>
        <java.version>1.8</java.version>
        <maven.compiler.version>3.8.1</maven.compiler.version>
        <maven.surefire.version>2.22.2</maven.surefire.version>
        <maven.failsafe.version>2.22.2</maven.failsafe.version>
    </properties>

    <dependencies>

        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-jvm</artifactId>
            <version>${cucumber.version}</version>
            <type>pom</type>
        </dependency>

        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>${cucumber.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-plugin</artifactId>
            <version>${cucumber.version}</version>
        </dependency>

        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>${cucumber.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>${cucumber.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>${selenium.version}</version>
        </dependency>

        <dependency>
            <groupId>io.github.bonigarcia</groupId>
            <artifactId>webdrivermanager</artifactId>
            <version>${webdrivermanager.version}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>${org.apache.poi.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>${org.apache.poi.version}</version>
            <scope>test</scope>
        </dependency>
        
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>${junit-jupiter-api}</version>
            <scope>test</scope>
         </dependency>

    </dependencies>
        <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${maven.compiler.version}</version>
                <configuration>
                    <encoding>UTF-8</encoding>
                    <fork>true</fork>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                </configuration>
            </plugin>
            
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>${maven.surefire.version}</version>
                <dependencies>
                      <dependency>
                           <groupId>org.apache.maven.surefire</groupId>
                           <artifactId>surefire-junit47</artifactId>
                           <version>${maven.surefire.version}</version>
                      </dependency>
                 </dependencies>
              </plugin>
            
              <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>${maven.failsafe.version}</version>
                <executions>
                    <execution>
                    <goals>
                    <goal>integration-test</goal>
                    </goals>
                    <configuration>

                            <includes>
                                <!-- UNCOMMENT BELOW LINE - To execute feature files with single runner -->
                                <include>**/MyTestRunner.java</include>
                            </includes>
                            <!-- UNCOMMENT BELOW 3 LINES - To execute using parallel or combination option -->
                            <parallel>methods</parallel>
                            <threadCount>4</threadCount>
                            <perCoreThreadCount>true</perCoreThreadCount>
                   
                    </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>