Forum Discussion

jurec17's avatar
jurec17
New Contributor
3 years ago

Looking for help with Serenity Cucumber 7 Maven Java project to run in Parallel

looking for help to execute cucumber 7 in parallel. My project is serenity with cucumber, maven and java. In this link https://johnfergusonsmart.com/parallel-test-execution-with-cucumber-and-serenity-bdd/ it is showing that it is possible to run but tried different combination and looks like I missed something. Also, read all posts from Cucumber documentation that were posted here, but looks like missing something.

 

Here is my POM.xml file:

 

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.d</groupId>
    <artifactId>Automation</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <serenity.version>3.2.0</serenity.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <encoding>UTF-8</encoding>
        <tags></tags>
        <parallel.tests>4</parallel.tests>
        <webdriver.base.url></webdriver.base.url>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
        <java.version>11</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>net.serenity-bdd</groupId>
            <artifactId>serenity-rest-assured</artifactId>
            <version>${serenity.version}</version>
        </dependency>
        <dependency>
            <groupId>net.serenity-bdd</groupId>
            <artifactId>serenity-cucumber</artifactId>
            <version>${serenity.version}</version>
        </dependency>
        <dependency>
            <groupId>org.junit.platform</groupId>
            <artifactId>junit-platform-launcher</artifactId>
            <version>1.8.1</version>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>5.8.2</version>
        </dependency>
        <dependency>
            <groupId>org.junit.vintage</groupId>
            <artifactId>junit-vintage-engine</artifactId>
            <version>5.8.2</version>
        </dependency>
        <dependency>
            <groupId>com.googlecode.lambdaj</groupId>
            <artifactId>lambdaj</artifactId>
            <version>2.3.3</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.12.4</version>
        </dependency>
        <dependency>
            <groupId>javax.ws.rs</groupId>
            <artifactId>javax.ws.rs-api</artifactId>
            <version>2.1.1</version>
        </dependency>
        <dependency>
            <groupId>org.codehaus.jettison</groupId>
            <artifactId>jettison</artifactId>
            <version>1.4.1</version>
        </dependency>
        <dependency>
            <groupId>commons-dbutils</groupId>
            <artifactId>commons-dbutils</artifactId>
            <version>1.7</version>
        </dependency>
        <dependency>
            <groupId>com.microsoft.sqlserver</groupId>
            <artifactId>mssql-jdbc</artifactId>
            <version>9.4.0.jre11</version>
        </dependency>
        <dependency>
            <groupId>com.jayway.jsonpath</groupId>
            <artifactId>json-path</artifactId>
            <version>2.6.0</version>
        </dependency>
        <dependency>
            <groupId>com.github.javafaker</groupId>
            <artifactId>javafaker</artifactId>
            <version>1.0.2</version>
        </dependency>
        <dependency>
            <groupId>org.awaitility</groupId>
            <artifactId>awaitility</artifactId>
            <version>4.1.1</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.0.0-M5</version>
                <configuration>
                    <skip>true</skip>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>3.0.0-M5</version>
                <configuration>
                    <includes>
                        <include>**/*Runner.java</include>
                    </includes>
                    <systemPropertyVariables>
                        <webdriver.base.url>${webdriver.base.url}</webdriver.base.url>
                    </systemPropertyVariables>
                    <parallel>methods</parallel>
                    <!--                    <threadCount>${parallel.tests}</threadCount>-->
                    <!--                    <forkCount>${parallel.tests}</forkCount>-->
                    <useUnlimitedThreads>true</useUnlimitedThreads>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.7.0</version>
                <configuration>
                    <source>11</source>
                    <target>11</target>
                    <compilerArgs>
                        <arg>-parameters</arg>
                    </compilerArgs>
                </configuration>
            </plugin>
            <plugin>
                <groupId>net.serenity-bdd.maven.plugins</groupId>
                <artifactId>serenity-maven-plugin</artifactId>
                <version>${serenity.version}</version>
                <configuration>
                    <tags>${tags}</tags>
                    <reports>single-page-html</reports>
                </configuration>
                <executions>
                    <execution>
                        <id>serenity-reports</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>aggregate</goal>
                        </goals>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>net.serenity-bdd</groupId>
                        <artifactId>serenity-single-page-report</artifactId>
                        <version>${serenity.version}</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>
</project>

 

 

Here is the struckture of my project in general:

src

    - main

       - java

             - actiona

             - pages

    - test

       - java

           - runner

           - steps

      - resources

          - features

 

Execution:

I add to multiple feature files the same tag and execute through command line mvn clean verify -Dtags="@regression"

 

Issue:

Only opens one browser at a time, not like in parallel some browsers at one time.

 

  • Find the solution for parallel execution with cucumber 7. Below pom.xml is tested and working to execute parallel. According to this pom.xml to execute two ways:

    1) locally add to your runner in tags tag you want to run and then execute this command mvn clean verify

    2) mvn clean verify -Dtags="@yourtagHere"

     

    Working pom.xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
    
        <groupId>com.d</groupId>
        <artifactId>Automation</artifactId>
        <version>1.0-SNAPSHOT</version>
    
        <properties>
            <serenity.version>3.2.0</serenity.version>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <encoding>UTF-8</encoding>
            <tags></tags>
            <parallel.tests>5</parallel.tests>
            <webdriver.base.url></webdriver.base.url>
            <maven.compiler.source>11</maven.compiler.source>
            <maven.compiler.target>11</maven.compiler.target>
            <java.version>11</java.version>
        </properties>
        <dependencies>
            <dependency>
                <groupId>net.serenity-bdd</groupId>
                <artifactId>serenity-rest-assured</artifactId>
                <version>${serenity.version}</version>
            </dependency>
            <dependency>
                <groupId>net.serenity-bdd</groupId>
                <artifactId>serenity-cucumber</artifactId>
                <version>${serenity.version}</version>
            </dependency>
            <dependency>
                <groupId>net.serenity-bdd</groupId>
                <artifactId>serenity-junit</artifactId>
                <version>${serenity.version}</version>
            </dependency>
            <dependency>
                <groupId>com.googlecode.lambdaj</groupId>
                <artifactId>lambdaj</artifactId>
                <version>2.3.3</version>
            </dependency>
            <dependency>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-databind</artifactId>
                <version>2.12.4</version>
            </dependency>
            <dependency>
                <groupId>javax.ws.rs</groupId>
                <artifactId>javax.ws.rs-api</artifactId>
                <version>2.1.1</version>
            </dependency>
            <dependency>
                <groupId>org.codehaus.jettison</groupId>
                <artifactId>jettison</artifactId>
                <version>1.4.1</version>
            </dependency>
            <dependency>
                <groupId>commons-dbutils</groupId>
                <artifactId>commons-dbutils</artifactId>
                <version>1.7</version>
            </dependency>
            <dependency>
                <groupId>com.microsoft.sqlserver</groupId>
                <artifactId>mssql-jdbc</artifactId>
                <version>9.4.0.jre11</version>
            </dependency>
            <dependency>
                <groupId>com.jayway.jsonpath</groupId>
                <artifactId>json-path</artifactId>
                <version>2.6.0</version>
            </dependency>
            <dependency>
                <groupId>com.github.javafaker</groupId>
                <artifactId>javafaker</artifactId>
                <version>1.0.2</version>
            </dependency>
            <dependency>
                <groupId>org.awaitility</groupId>
                <artifactId>awaitility</artifactId>
                <version>4.1.1</version>
            </dependency>
        </dependencies>
    
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>3.0.0-M5</version>
                    <configuration>
                        <skip>true</skip>
                    </configuration>
                </plugin>
                <plugin>
                    <artifactId>maven-failsafe-plugin</artifactId>
                    <version>3.0.0-M5</version>
                    <configuration>
                        <includes>
                            <include>**/*Runner.java</include>
                        </includes>
                        <systemPropertyVariables>
                            <webdriver.base.url>${webdriver.base.url}</webdriver.base.url>
                        </systemPropertyVariables>
                        <parallel>methods</parallel>
                        <threadCount>${parallel.tests}</threadCount>
                        <!-- <forkCount>${parallel.tests}</forkCount>-->
                        <!--<useUnlimitedThreads>true</useUnlimitedThreads>-->
                    </configuration>
                    <executions>
                        <execution>
                            <goals>
                                <goal>integration-test</goal>
                                <goal>verify</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.10.0</version>
                    <configuration>
                        <source>11</source>
                        <target>11</target>
                        <compilerArgs>
                            <arg>-parameters</arg>
                        </compilerArgs>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>net.serenity-bdd.maven.plugins</groupId>
                    <artifactId>serenity-maven-plugin</artifactId>
                    <version>${serenity.version}</version>
                    <configuration>
                        <tags>${tags}</tags>
                        <reports>single-page-html</reports>
                    </configuration>
                    <executions>
                        <execution>
                            <id>serenity-reports</id>
                            <phase>post-integration-test</phase>
                            <goals>
                                <goal>aggregate</goal>
                            </goals>
                        </execution>
                    </executions>
                    <dependencies>
                        <dependency>
                            <groupId>net.serenity-bdd</groupId>
                            <artifactId>serenity-single-page-report</artifactId>
                            <version>${serenity.version}</version>
                        </dependency>
                    </dependencies>
                </plugin>
            </plugins>
        </build>
    </project>
  • jurec17's avatar
    jurec17
    New Contributor

    Find the solution for parallel execution with cucumber 7. Below pom.xml is tested and working to execute parallel. According to this pom.xml to execute two ways:

    1) locally add to your runner in tags tag you want to run and then execute this command mvn clean verify

    2) mvn clean verify -Dtags="@yourtagHere"

     

    Working pom.xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
    
        <groupId>com.d</groupId>
        <artifactId>Automation</artifactId>
        <version>1.0-SNAPSHOT</version>
    
        <properties>
            <serenity.version>3.2.0</serenity.version>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <encoding>UTF-8</encoding>
            <tags></tags>
            <parallel.tests>5</parallel.tests>
            <webdriver.base.url></webdriver.base.url>
            <maven.compiler.source>11</maven.compiler.source>
            <maven.compiler.target>11</maven.compiler.target>
            <java.version>11</java.version>
        </properties>
        <dependencies>
            <dependency>
                <groupId>net.serenity-bdd</groupId>
                <artifactId>serenity-rest-assured</artifactId>
                <version>${serenity.version}</version>
            </dependency>
            <dependency>
                <groupId>net.serenity-bdd</groupId>
                <artifactId>serenity-cucumber</artifactId>
                <version>${serenity.version}</version>
            </dependency>
            <dependency>
                <groupId>net.serenity-bdd</groupId>
                <artifactId>serenity-junit</artifactId>
                <version>${serenity.version}</version>
            </dependency>
            <dependency>
                <groupId>com.googlecode.lambdaj</groupId>
                <artifactId>lambdaj</artifactId>
                <version>2.3.3</version>
            </dependency>
            <dependency>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-databind</artifactId>
                <version>2.12.4</version>
            </dependency>
            <dependency>
                <groupId>javax.ws.rs</groupId>
                <artifactId>javax.ws.rs-api</artifactId>
                <version>2.1.1</version>
            </dependency>
            <dependency>
                <groupId>org.codehaus.jettison</groupId>
                <artifactId>jettison</artifactId>
                <version>1.4.1</version>
            </dependency>
            <dependency>
                <groupId>commons-dbutils</groupId>
                <artifactId>commons-dbutils</artifactId>
                <version>1.7</version>
            </dependency>
            <dependency>
                <groupId>com.microsoft.sqlserver</groupId>
                <artifactId>mssql-jdbc</artifactId>
                <version>9.4.0.jre11</version>
            </dependency>
            <dependency>
                <groupId>com.jayway.jsonpath</groupId>
                <artifactId>json-path</artifactId>
                <version>2.6.0</version>
            </dependency>
            <dependency>
                <groupId>com.github.javafaker</groupId>
                <artifactId>javafaker</artifactId>
                <version>1.0.2</version>
            </dependency>
            <dependency>
                <groupId>org.awaitility</groupId>
                <artifactId>awaitility</artifactId>
                <version>4.1.1</version>
            </dependency>
        </dependencies>
    
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>3.0.0-M5</version>
                    <configuration>
                        <skip>true</skip>
                    </configuration>
                </plugin>
                <plugin>
                    <artifactId>maven-failsafe-plugin</artifactId>
                    <version>3.0.0-M5</version>
                    <configuration>
                        <includes>
                            <include>**/*Runner.java</include>
                        </includes>
                        <systemPropertyVariables>
                            <webdriver.base.url>${webdriver.base.url}</webdriver.base.url>
                        </systemPropertyVariables>
                        <parallel>methods</parallel>
                        <threadCount>${parallel.tests}</threadCount>
                        <!-- <forkCount>${parallel.tests}</forkCount>-->
                        <!--<useUnlimitedThreads>true</useUnlimitedThreads>-->
                    </configuration>
                    <executions>
                        <execution>
                            <goals>
                                <goal>integration-test</goal>
                                <goal>verify</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.10.0</version>
                    <configuration>
                        <source>11</source>
                        <target>11</target>
                        <compilerArgs>
                            <arg>-parameters</arg>
                        </compilerArgs>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>net.serenity-bdd.maven.plugins</groupId>
                    <artifactId>serenity-maven-plugin</artifactId>
                    <version>${serenity.version}</version>
                    <configuration>
                        <tags>${tags}</tags>
                        <reports>single-page-html</reports>
                    </configuration>
                    <executions>
                        <execution>
                            <id>serenity-reports</id>
                            <phase>post-integration-test</phase>
                            <goals>
                                <goal>aggregate</goal>
                            </goals>
                        </execution>
                    </executions>
                    <dependencies>
                        <dependency>
                            <groupId>net.serenity-bdd</groupId>
                            <artifactId>serenity-single-page-report</artifactId>
                            <version>${serenity.version}</version>
                        </dependency>
                    </dependencies>
                </plugin>
            </plugins>
        </build>
    </project>