Maven/Junit Parallel Execution - Cucumber-JVM v4.0.0 - maven

I'm struggling to get the new parallel execution feature of Cucumber-JVM v4.0.0 working with JUnit/Maven.
As specified here, if you configure <parallel> and <threadCount> accordingly in your POM, and use dependency injection to share state (I'm using Pico Continer) then your Cucumber features should execute in parallel.
However, it is still only executing one feature at a time when i run Maven.
I've included my complete POM below - Can anybody help?
<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.softwareautomation</groupId>
<artifactId>selenium</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>selenium</name>
<url>http://maven.apache.org</url>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<parallel>both</parallel>
<threadCount>4</threadCount>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- AssertJ -->
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.11.1</version>
<scope>test</scope>
</dependency>
<!-- Cucumber -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>4.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>4.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<version>4.0.0</version>
<scope>test</scope>
</dependency>
<!-- JUnit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<!-- Selenium WebDriver -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.11.0</version>
</dependency>
</dependencies>
If it helps, below is my runner class (com.softwareautomation.world is the DI class)
package com.evasoftwareautomation.runners;
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
#RunWith(Cucumber.class)
#CucumberOptions(
plugin = {"pretty", "html:target/cucumber", "junit:target/cucumber.xml"},
features = "src/test/resources/com/softwareautomation/features",
glue = {"com.softwareautomation.stepdefs", "com.softwareautomation.world"},
junit ={ "--step-notifications"},
monochrome = true)
public class CucumberTest {
}
Please see failing stack trace when running from Maven below:
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Concurrency config is parallel='methods', perCoreThreadCount=true, threadCount=4, useUnlimitedThreads=false
org.apache.maven.surefire.util.SurefireReflectionException: java.lang.reflect.InvocationTargetException; nested exception is java.lang.reflect.InvocationTargetException: null
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
Caused by: java.lang.NullPointerException
at org.junit.runner.Description.createSuiteDescription(Description.java:124)
at org.apache.maven.surefire.common.junit48.FilterFactory$GroupMatcherCategoryFilter.shouldRun(FilterFactory.java:207)
at org.junit.runners.ParentRunner.shouldRun(ParentRunner.java:434)
at org.junit.runners.ParentRunner.filter(ParentRunner.java:382)
at org.junit.runner.manipulation.Filter.apply(Filter.java:97)
at org.junit.runners.ParentRunner.filter(ParentRunner.java:384)
at org.junit.runner.manipulation.Filter.apply(Filter.java:97)
at org.junit.runners.ParentRunner.filter(ParentRunner.java:384)
at org.junit.runner.manipulation.Filter.apply(Filter.java:97)
at org.junit.runners.ParentRunner.filter(ParentRunner.java:384)
at org.junit.runner.manipulation.Filter.apply(Filter.java:97)
at org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:37)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at org.apache.maven.surefire.junitcore.JUnitCoreWrapper.execute(JUnitCoreWrapper.java:62)
at org.apache.maven.surefire.junitcore.JUnitCoreProvider.invoke(JUnitCoreProvider.java:139)
... 9 more
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.709 s
[INFO] Finished at: 2018-10-25T23:36:01+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) on project selenium: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test failed: The forked VM terminated without saying properly goodbye. VM crash or System.exit called ? -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException

at org.apache.maven.surefire.common.junit48.FilterFactory$GroupMatcherCategoryFilter.shouldRun(FilterFactory.java:207)
You are using JUnit 4.12. However as noted above the stack trace tells us that surefire is trying to use an integration for JUnit 4.8. Your version of surefire was released in 2012, where as JUnit 4.12 was released in 2014. Have you considered updating your maven surefire plugin?

I managed to get it to work by explicitly adding the dependency of the testing framework:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>2.22.2</version>
</dependency>
</dependencies>
<configuration>
<parallel>all</parallel>
<threadCount>4</threadCount>
</configuration>
</plugin>

Leaving it here as it might help somebody else
In my case
maven was not picking up Junit 5 tests
cucumber tests were not running in parallel
Got it working by
adding junit-jupiter 5.5.2
adding maven-surefire-plugin 2.22.2 and explicitly adding
surefire-junit47 2.22.2
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>2.22.2</version>
</dependency>
</dependencies>
<configuration>
<parallel>both</parallel>
<threadCount>4</threadCount>
</configuration>
</plugin>

In my case, I was using surefire 2.12.4 and updating it to 2.22.2 did the trick

Related

how to fix the maven surefire plugin error [there was error in the forked process]?

I am trying to run my sample project which uses Maven- testNG-cucumber and deploy it using docker . here is my Dockerfile
FROM maven:3.6.0-jdk-8
RUN mkdir /docker
WORKDIR /docker
COPY pom.xml .
COPY testng.xml .
COPY src .
RUN mvn clean verify
POM.XML
<dependencies>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.2.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-jvm-deps</artifactId>
<version>1.0.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-testng</artifactId>
<version>1.2.5</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.9.8</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.masterthought</groupId>
<artifactId>cucumber-reporting</artifactId>
<version>3.8.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.44.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.4</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
<useSystemClassLoader>false</useSystemClassLoader>
</configuration>
</plugin>
<plugin>
<groupId>net.masterthought</groupId>
<artifactId>maven-cucumber-reporting</artifactId>
<version>3.8.0</version>
<executions>
<execution>
<id>execution</id>
<phase>verify</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<projectName>Sample</projectName>
<outputDirectory>target/cucumber-reports/advanced-reports</outputDirectory>
<cucumberOutput>target/cucumber-reports/CucumberTestReport.json</cucumberOutput>
<buildNumber>1</buildNumber>
<parallelTesting>false</parallelTesting>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
above scenario works completely fine when i run the project locally using mvn verify .Then i try to build the image using docker build -t sample . . this time i have got the following error .
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.20.1:test (default-test) on project Sample: There are test failures.
[ERROR] Please refer to /docker/target/surefire-reports for the individual test results.
[ERROR] Please refer to dump files (if any exist) [date]-jvmRun[N].dump, [date].dumpstream and [date]-jvmRun[N].dumpstream.
[ERROR] There was an error in the forked process
[ERROR] Cannot find class in classpath: TestRunner
[ERROR] org.apache.maven.surefire.booter.SurefireBooterForkException: There was an error in the forked process
[ERROR] Cannot find class in classpath: TestRunner
[ERROR] at org.apache.maven.plugin.surefire.booterclient.ForkStarter.fork
(ForkStarter.java:673)
[ERROR] at org.apache.maven.plugin.surefire.booterclient.ForkStarter.fork
(ForkStarter.java:535)
[ERROR] at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run
(ForkStarter.java:280)
[ERROR] at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run
(ForkStarter.java:245)
[ERROR] at
org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeProvider
(AbstractSurefireMojo.java:1124)
[ERROR] at
org.apache.maven.plugin.surefire.AbstractSurefireMojo.
executeAfterPreconditionsChecked(AbstractSurefireMojo.java:954)
Any help would be much appreciated
I had a similar issue and after using older version of maven-surefire-plugin solved my issue.
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<!-- latest version does not work well with JUnit5 -->
<version>2.19.1</version>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>1.0.3</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.0.3</version>
</dependency>
</dependencies>
</plugin>
I had the same issue, I just used the clean command for maven.
clean -f pom.xml
If you are working in IntelliJ you can use maven plugin instead.
On the right side click maven Tab -> plugins -> clean -> clean:clean
I faced the same issue but it got resolved with different solution, you can check below problems as well.
Actually i have given the wrong testNG.xml path in POM.XML that's why it was throwing me that error. Please cross verify your testNG.xml path.
The above exception log clearly states that it is unable to find the TestRunner class. Make sure your TestRunner class is on the classpath.
I was getting a similar exception due to there were few extra characters added in the Classes section of the TestNG XML file. Its worth checking TestNG XML file is correct and doesn't contain any extra chars than needed structure.
I faced the same issue. It got resolved after the maven clean build and then ran the test.

Maven returns exit 0 even though junit5 tests fail

I have setup Maven to trigger some junit5 tests.
When I run:
mvn clean integration-test
I see the project build and then it also runs the tests. I see a failure in one of the unit tests.
Further down in the console output, I see:
[INFO] BUILD SUCCESS
What am I doing wrong? My expectation is that a failed test run would stop a tool like maven and return exit code 1.
This is particularly frustrating in CI because it appears as the tests are healthy since exit code returns zero.
EDIT: Here's the POM XML:
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.(removedforstackoverflowpost)</groupId>
<artifactId>(removedforstackoverflowpost)</artifactId>
<packaging>jar</packaging>
<version>0.0.1</version>
<name>(removedforstackoverflowpost)</name>
<url>(removedforstackoverflowpost)</url>
<description>(removedforstackoverflowpost)</description>
<licenses>
<license>
<name>MIT License</name>
<url>http://www.opensource.org/licenses/mit-license.php</url>
</license>
</licenses>
<developers>
<developer>
<name>(removedforstackoverflowpost)</name>
<email>(removedforstackoverflowpost)</email>
<organization>(removedforstackoverflowpost)</organization>
<organizationUrl>(removedforstackoverflowpost)</organizationUrl>
</developer>
</developers>
<scm>
<connection>(removedforstackoverflowpost)</connection>
<developerConnection>(removedforstackoverflowpost)</developerConnection>
<url>(removedforstackoverflowpost)</url>
</scm>
<properties>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.3.1</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.12.1.GA</version>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-console-standalone</artifactId>
<version>1.3.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<!-- latest version (2.20.1) does not work well with JUnit5 -->
<version>2.19.1</version>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>1.0.3</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.0.3</version>
</dependency>
</dependencies>
<configuration>
<useSystemClassLoader>false</useSystemClassLoader>
<properties>
<configurationParameters>
junit.jupiter.extensions.autodetection.enabled = true
</configurationParameters>
</properties>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
<argLine>
--illegal-access=permit
</argLine>
</configuration>
</plugin>
</plugins>
</build>
</project>
I'm running java 11
When I enter this test command:
mvn -ff clean integration-test
I get this output that ends like this:
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.001 sec - in com.github.(removedforstackoverflowpost)
Results :
Failed tests:
SomeTest.testSomething1:13 expected: <1> but was: <2>
Tests run: 4, Failures: 1, Errors: 0, Skipped: 0
[ERROR] There are test failures.
Please refer to (removedforstackoverflowpost)/target/surefire-reports for the individual test results.
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) # (removedforstackoverflowpost) ---
[INFO] Building jar: (removedforstackoverflowpost)....-0.0.1.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.360 s
[INFO] Finished at: 2018-12-12T00:45:03-08:00
[INFO] ------------------------------------------------------------------------
I'm a total beginner so I apologize for asking an overly simplistic question. I am new to Java/Maven/JUnit5, but I'm just looking for what I should do to have the test cause a non zero exit code. This way, my CI run (I happen to use CircleCI but that doesnt matter) would show as failed when the tests fail.
I work on a Mac and the undesired behavior that I'm describing on this ticket happens the same way on both my local Mac workstation as well as in CircleCI.
Line 102 of your pom.xml is instructing Maven to ignore the failures. Just remove <testFailureIgnore>true</testFailureIgnore> and the build will fail.

Flyway and Maven integration - Cannot access s3://flyway-repo/release

I want to integrate flyway with maven and oracle db. At first I want to make a simple test if there are simple migrations possible, so I made a build part of pom file as the following (as described in flyway official page):
<build>
<plugins>
<plugin>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<version>4.2.0</version>
<configuration>
<url>jdbc:oracle:thin:#localhost:1521:XE</url>
<user>test</user>
<password>test</password>
<schemas>
<schema>TEST</schema>
</schemas>
</configuration>
<dependencies>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc14</artifactId>
<version>10.2.0.4.0</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
But when I'm trying to run flyway:migrate or flyway:info goal, I'm getting the following error, which I do not know with what is connected..
[ERROR] Failed to execute goal org.flywaydb:flyway-maven-plugin:4.2.0:info (default-cli) on project gwm-admin: Execution default-cli of goal org.flywaydb:flyway-maven-plugin:4.2.0:info failed: Plugin org.fl
ywaydb:flyway-maven-plugin:4.2.0 or one of its dependencies could not be resolved: Could not transfer artifact com.oracle:ojdbc14:jar:10.2.0.4.0 from/to flyway-repo-private (s3://flyway-repo/release): Canno
t access s3://flyway-repo/release with type default using the available connector factories: BasicRepositoryConnectorFactory: Cannot access s3://flyway-repo/release using the registered transporter factorie
s: WagonTransporterFactory: java.util.NoSuchElementException
[ERROR] role: org.apache.maven.wagon.Wagon
[ERROR] roleHint: s3
[ERROR] -> [Help 1]
As wrote #Arkadiusz Łukasiewicz in comment, oracle jdbc driver need to be added manually. More informations about could be found here : mkyong post
On the other hand, after the driver was added I got another error which can be resolved by moving a dependency out of plugin part into main dependencies of pom.xml file
use this code:
<properties>
<maven.compiler.source> java version </maven.compiler.source>
<maven.compiler.target> java version </maven.compiler.target>
</properties>
<dependencies>
<!-- Fly way -->
<dependency>
<groupId>com.googlecode.flyway</groupId>
<artifactId>flyway-core</artifactId>
<version>1.7</version>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc14</artifactId>
<version>10.2.0.4.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
(...)
</plugin>
</plugins>
</build>

Maven test, Jenkins Test Suite failure java.lang.NoClassDefFoundError -

I am attempting to run my tests through Maven however I am getting an error during the build process. I've tried for the last 2 days to resolve this but now running out of ideas. I have made sure my POM has the correct dependencies and that the tests work outside of Jenkins.
OS - Windows Server 2012 R2
Browser - firefox 50.1.0
Selenium Driver - 3.0.1
Jenkins Error Log
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running TestSuite
[AppClassLoader#18b4aac2] warning javax.* types are not being woven because the weaver option '-Xset:weaveJavaxPackages=true' has not been specified
09:48:46.025 [main] INFO - START com.Ceridian.tests.HB01.CD01
09:48:46.119 [main] WARN - SKIP com.Ceridian.tests.HB01.CD01
09:48:46.119 [main] ERROR - Unable to take screenshot - java.lang.NullPointerException
09:48:46.135 [main] INFO - START com.Ceridian.tests.HB01.CD02
09:48:46.150 [main] WARN - SKIP com.Ceridian.tests.HB01.CD02
09:48:46.150 [main] ERROR - Unable to take screenshot - java.lang.NullPointerException
Tests run: 4, Failures: 2, Errors: 0, Skipped: 2, Time elapsed: 2.688 sec <<< FAILURE! - in TestSuite
configureBrowserBeforeTest(com.Ceridian.tests.HB01) Time elapsed: 2 sec <<< FAILURE!
java.lang.NoClassDefFoundError: org/openqa/selenium/remote/SessionNotFoundException
Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.remote.SessionNotFoundException
configureBrowserBeforeTest(com.Ceridian.tests.HB01) Time elapsed: 0.093 sec <<< FAILURE!
java.lang.NoClassDefFoundError: org/openqa/selenium/remote/SessionNotFoundException
Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.remote.SessionNotFoundException
Results :
Failed tests:
com.Ceridian.tests.HB01.configureBrowserBeforeTest(com.Ceridian.tests.HB01)
Run 1: HB01>BaseTest.configureBrowserBeforeTest:102 » NoClassDefFound org/openqa/sele...
Run 2: HB01>BaseTest.configureBrowserBeforeTest:102 » NoClassDefFound org/openqa/sele...
Jenkins Build Failure
[JENKINS] Recording test results
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 37.354 s
[INFO] Finished at: 2017-01-06T09:48:52+00:00
[INFO] Final Memory: 34M/442M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.19.1:test (default-test) on project Frameworkium: There are test failures.
[ERROR]
[ERROR] Please refer to C:\Program Files (x86)\Jenkins\jobs\FirstAttempt\workspace\target\surefire-reports for the individual test results.
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.19.1:test (default-test) on project Frameworkium: There are test failures.
POM file
<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.frameworkium</groupId>
<artifactId>Frameworkium</artifactId>
<packaging>jar</packaging>
<version>2.0.5</version>
<name>Frameworkium</name>
<description>
A template designed to get up and running quickly with Selenium and Appium.
</description>
<url/>
<inceptionYear/>
<organization/>
<licenses/>
<developers/>
<contributors/>
<prerequisites>
<maven>3.1.1</maven>
</prerequisites>
<modules/>
<scm/>
<issueManagement/>
<ciManagement/>
<distributionManagement/>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<env.config>local</env.config>
<threads>1</threads>
<groups/>
<aspectj.version>1.8.9</aspectj.version>
</properties>
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.9.8</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.11</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.14</version>
</dependency>
<dependency>
<groupId>com.github.Frameworkium</groupId>
<artifactId>frameworkium-core</artifactId>
<version>2.0.5</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-remote-driver</artifactId>
<version>3.0.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.53.1</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server</artifactId>
<version>3.0.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
<testSourceDirectory>src/test/java</testSourceDirectory>
<resources>
<resource>
<directory>
src/main/resources
</directory>
</resource>
</resources>
</build>
<profiles>
<profile>
<id>tests</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<parallel>methods</parallel>
<threadCount>${threads}</threadCount>
<systemProperties>
<screenshotDirectory>
${project.build.directory}/screenshots
</screenshotDirectory>
<allure.issues.tracker.pattern>
/browse/%s
</allure.issues.tracker.pattern>
</systemProperties>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
<includes>
<include>**/Test*.java</include>
<include>**/*Tests*.java</include>
<include>**/*Tests.java</include>
<include>**/*Test.java</include>
<include>**/*TestCase.java</include>
</includes>
<groups>${groups}</groups>
<testFailureIgnore>false</testFailureIgnore>
<argLine>
-javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"
</argLine>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
The Jenkins Logs seem to mention my #BeforeMethod as a possible reason for failure so I'll just include that here
#BeforeMethod(
alwaysRun = true
)
public static void configureBrowserBeforeTest(Method testMethod) {
try {
((Driver)driver.get()).resetBrowser();
wait.set(newDefaultWait());
userAgent = determineUserAgent();
initialiseNewScreenshotCapture(testMethod);
} catch (Exception var2) {
logger.error("Failed to configure browser.", var2);
throw new RuntimeException("Failed to configure browser.", var2);
}
}
I've included my configuration screen of the build.
Apologies if I've missed something out.
Adding dependencies
Updated
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.0.1</version>
</dependency>
So it is also on 3.0.1 and the error went away. Thanks to #duffymo for the help.

Maven throws error while running testng test cases

I have steup Eclipse + Maven + TestNG and I intend to run Selenium Test cases.
This is my POM File:
<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>MyGroupId</groupId>
<artifactId>TestSuite</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.32.0</version>
</dependency>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-testng</artifactId>
<version>2.14.1</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Now when I try to run Maven test, I get following error:
-------------------------------------------------------
T E S T S
-------------------------------------------------------
org.apache.maven.surefire.util.SurefireReflectionException:
java.lang.reflect.InvocationTargetException; nested exception is
java.lang.reflect.InvocationTargetException: null
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
at org.apache.maven.surefire.util.ReflectionUtils.instantiateOneArg(ReflectionUtils.java:130)
at org.apache.maven.surefire.booter.SurefireReflector.instantiateProvider(SurefireReflector.java:247)
at org.apache.maven.surefire.booter.ProviderFactory.createProvider(ProviderFactory.java:81)
at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:171)
at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:107)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:68)
Caused by: java.lang.NoSuchMethodError: org.apache.maven.surefire.providerapi.ProviderParameters.getRunOrderCalculator()Lorg/apache/maven/surefire/util/RunOrderCalculator;
at org.apache.maven.surefire.testng.TestNGProvider.<init>(TestNGProvider.java:67)
... 10 more
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
Can someone suggest me what's that I am missing here.
Thanks in advance.
You have to define the maven-surefire-plugin in the pluginManagement section like the following:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.14.1</version>
</plugin>
</plugins>
</pluginManagement>
</build>
To use testng in relationship with the maven-surefire-plugin you usually only need to add testng as a dependency nothing more.
Furthermore remove the dependency you've given:
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-testng</artifactId>
<version>2.14.1</version>
</dependency>
Apart from the above this is looking more like an integration tests which is the job of maven-failsafe-plugin and not of maven-surefire-plugin.
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
This means your tests (presumably integration tests based on the selenium dependency) can be run by using:
mvn verify
Maybe will help somebody. Me helped - change version dependency of testng
It was:
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.11</version>
<scope>test</scope>
</dependency>
And has become:
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.10</version>
<scope>test</scope>
</dependency>
I also had an issue that resulted in this error, but for me it turned out to be missing file access rights for the account running the tests to the test folder.
Might be something to check out
changing the testNG dependency version in pom.xml from 6.14.3 to 6.10 will help out in avoiding the exception cases.
For me it got resolved after adding Surefire plugin in my Pom.XML as showed below:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.21.0</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
and you have to make sure that, testNG.xml must be created.
You need to give the exact file name of testng xml file inside "suiteXmlFile" tag of pom.xml.
As per my understanding, this error was generated because of TestNG not configured with the maven Surefire properly, surefire are used to run our Tests. Since I'm using TestNg it must be configured with surefire.

Resources