Search code examples
mavenselenium-webdriverpom.xmlmaven-surefire-pluginparallel-execution

Parallel execution with maven-surefire-plugin is throwing PluginResolutionException


I am trying to execute my feature files via TestRunner.java files (by mentioning them in pom.xml) , in parallel using maven-surefire-plugin, for which i have set up pom.xml as below, but when i run pom.xml as maven test, its throwing PluginResolutionException when the version is 3.0.0-M3, when i have update the version to 2.19.1, the maven test is not running my feature files but the build is shown as successful

  • I have tried with different versions but not worked

  • Also I have tried replacing the configuration part with below changes

still my feature files are not executed but the build is successful

<configuration>
<forkCount>3</forkCount>
<reuseForks>true</reuseForks>
<!-- 
<parallel>classes</parallel>
<forkMode>perthread</forkMode>
<threadCount>3</threadCount>
-->
<argLine>-Xmx1024m -XX:MaxPermSize=256m</argLine>
<includes>
<include>**/*TestRunner.java</include>
</includes>
</configuration>

PS: After reading the below artical https://maven.apache.org/surefire/maven-surefire-plugin/examples/junit.html#Running_tests_in_parallel

I understand that there is link between the Junit version and surefireflugin i use in my project, bow one thing is for sure, the correct combination of Junit and maven-surefire-plugin is very much necessary, i have tried with below combinations

JUnit 4.7
plugin 3.0.0-M3

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>3.0.0-M3</version>
</dependency>
</dependencies>
</plugin> 

JUnit 4.12
plugin 2.20

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
<configuration>
<parallel>classes</parallel>
<threadCount>3</threadCount>
<argLine>-Xmx1024m -XX:MaxPermSize=256m</argLine>
<includes>
<include>**/*TestRunner.java</include>
</includes>
</configuration>
</plugin>

but its not helpful, I suppose i am doing mistake in choosing this versions and the config of plugin with proper parameters, please help me

My complete pom is as below

        <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.practise.raja</groupId>
            <artifactId>SeleniumConcepts</artifactId>
            <version>0.0.1-SNAPSHOT</version>
            <dependencies>
                    <dependency>
                    <groupId>junit</groupId>
                    <artifactId>junit</artifactId>
                    <version>4.12</version>
                </dependency>

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

                <dependency>
                    <groupId>io.cucumber</groupId>
                    <artifactId>cucumber-picocontainer</artifactId>
                    <version>4.7.1</version>
                </dependency>
                <dependency>
                    <groupId>org.seleniumhq.selenium</groupId>
                    <artifactId>selenium-java</artifactId>
                    <version>3.5.3</version>
                </dependency>

            </dependencies>

            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <version>3.1</version>
                        <configuration>
                            <source>1.8</source>
                            <target>1.8</target>
                            <fork>true</fork>
                            <executable>C:\Program Files (x86)\Java\jdk1.8.0_211\bin\javac</executable>
                        </configuration>
                    </plugin>

                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <version>3.0.0-M3</version>
                        <configuration>
                            <parallel>classes</parallel>
                            <forkMode>perthread</forkMode>
                            <threadCount>3</threadCount>
                            <argLine>-Xmx1024m -XX:MaxPermSize=256m</argLine>
                            <includes>
                                <include>**/*TestRunner.java</include>
                            </includes>
                        </configuration>
                    </plugin>

                </plugins>
            </build>
        </project>

Expected: My feature files should run in parallel Actual: My feature files are not executed

enter image description here

After changing the dependencies and plugin as suggested by sureshmani, this is how it looks enter image description here


Solution

  • Finally i am able to solve this, to my initial pom, have started doing below changes. Which ran my feature files in parallel

    Change 1: I happen to add the dependency for cucumber-jvm-parallel-plugin along with plugin ,so i have deleted the plugin

    Change 2: I have realized that the cucumber-jvm-parallel-plugin is not able to recognize the feature files when I have them placed src/main/java , some of the posts said i have to move all feature files to src/main/resources/feature , where features is package

    Change 3: I have realized that cucumber-jvm-parallel-plugin is not able to recognize the resources like step def's and drivers etc, so i have used build-helper-maven-plugin where i have declared the resources as below

    <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>
    <version>1.7</version>
    <executions>
    <execution>
    <id>add-source</id>
    <phase>generate-sources</phase>
    <goals>
    <goal>add-source</goal>
    </goals>
    <configuration>
    <sources>
    <source>src/main/java/</source>
    <source>src/main/resources/</source>
    <source>features</source>
    </sources>
    </configuration>
    </execution>
    </executions>
    </plugin>
    

    Change 4: cucumber-jvm-parallel-plugin in the maven life cycle in my IDE, because for some reason maven is not able to consider this plugin in it execution Eclipse --> Windoes --> Preferences --> Maven->LifeCycleMappings-> copy paste below code

    <pluginExecution>
    <pluginExecutionFilter>
    <groupId>com.github.temyers</groupId>
    <artifactId>cucumber-jvm-parallel-plugin</artifactId>
    <goals>
    <goal>generateRunners</goal>
    </goals>
    <versionRange>[4.2.0,)</versionRange>
    </pluginExecutionFilter>
    <action>
    <ignore/>
    </action>
    </pluginExecution>
    Then , click on "Reload workspace lifecycle mapping metadata" button in Preference 
    Maven modal
    
    My final pom looks like this
    <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.practise.raja</groupId>
    <artifactId>JUnitCucumberParallelExecutionPractise</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>JUnitCucumberParallelExecutionPractise</name>
    <description>JUnitCucumberParallelExecutionPractise</description>
    <dependencies>
    <!--        <dependency>
    <groupId>com.github.temyers</groupId>
    <artifactId>cucumber-jvm-parallel-plugin</artifactId>
    <version>5.0.0</version>
    </dependency>
    -->
    <dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.12</version>
    </dependency>
    <dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-junit</artifactId>
    <version>4.7.1</version>
    </dependency>
    <dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-picocontainer</artifactId>
    <version>4.7.1</version>
    </dependency>
    <dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>3.5.3</version>
    </dependency>
    </dependencies>
    <properties>
    <src.main.java>src/main/java</src.main.java>
    </properties>
    <build>
    <resources>
    <resource>
    <directory>${src.main.java}</directory>
    </resource>
    </resources>
    <plugins>
    <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>
    <version>1.7</version>
    <executions>
    <execution>
    <id>add-source</id>
    <phase>generate-sources</phase>
    <goals>
    <goal>add-source</goal>
    </goals>
    <configuration>
    <sources>
    <source>src/main/java/</source>
    <source>src/main/resources/</source>
    <source>features</source>
    </sources>
    </configuration>
    </execution>
    </executions>
    </plugin>
    <plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.1</version>
    <configuration>
    <source>1.8</source>
    <target>1.8</target>
    <fork>true</fork>
    <executable>C:\Program Files (x86)\Java\jdk1.8.0_211\bin\javac</executable>
    </configuration>
    </plugin>
    <plugin>
    <groupId>com.github.temyers</groupId>
    <artifactId>cucumber-jvm-parallel-plugin</artifactId>
    <version> 4.2.0</version>
    <executions>
    <execution>
    <id>generateRunners</id>
    <phase>generate-test-sources</phase>
    <goals>
    <goal>generateRunners</goal>
    </goals>
    <configuration>
    <featuresDirectory>src/main/resources/features</featuresDirectory>
    <glue>
    <package>com.qa.stepdef</package>
    </glue>
    <outputDirectory>${project.build.directory}/generated-test- 
    sources/cucumber</outputDirectory>
    <cucumberOutputDir>${project.build.directory}</cucumberOutputDir>
    <format> json </format>
    <strict>true</strict>
    <monochrome>false</monochrome>
    <useTestNG>false</useTestNG>
    <namingScheme>simple</namingScheme>
    <namingPattern>Parallel{c}IT</namingPattern>
    <parallelScheme>FEATURE</parallelScheme>
    </configuration>
    </execution>
    </executions>
    </plugin>
    <!-- Specify a custom template for the generated sources (this is a path 
    relative to the project base directory) -->
    <!-- <customVmTemplate>src/test/resources/custom-runner-template.java.vm 
    </customVmTemplate> -->
    <!-- Specify a custom package name for generated sources. Default is no 
    package. -->
    <!--<packageName></packageName> <plugins> <plugin> <name>json</name> 
    </plugin> 
    <plugin> <name>html</name> </plugin> <plugin> <name>pretty</name> </plugin> 
    </plugins> -->
    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.20</version>
    <configuration>
    <forkCount>3</forkCount>
    <reuseForks>true</reuseForks>
    <includes>
    <include>**/*IT.class</include>
    </includes>
    </configuration>
    </plugin>
    </plugins>
    </build>
    </project>
    
    Even after these changes, an error started showing at <execution> in pom, it says 
    Plugin execution not covered by lifecycle configuration: com.github.temyers:cucumber- 
    jvm-parallel-plugin:4.2.0:generateRunners (execution: generateRunners, phase: 
    generate-
    
    But, its fine, i am able to run the feature files in parallel even with this above 
    error
    

    test-sources)