Help with Selenium Maven Cargo - maven-2

I am trying to use cargo to deploy and start my container (which works fine), and then use selenium to execute some UI tests.
Whenever I try to run (mvn clean integration-test), I get to the point where it says
Launching Selenium Server
Waiting for Selenium Server...
[INFO]Redirecting output to
[INFO]User extensions
But then my integration tests never get executed by surefire. Any help is much appreciated. It seems like the Selenium Server never gets started.
One quick note, I am using JUnit 4.4
I tried using ANT instead, to copy over the selenium-server and start selenium that way. When I do that, my integration tests run, but I got the following error, which is why I was trying to use the selenium-maven-plugin.
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.3 sec <<< FAILURE!
testAllCriticalPagesLoadWithoutError(com.adminserver.pas.test.SimpleSmokeTest) Time elapsed: 0.29 sec <<< ERROR!
java.lang.RuntimeException: Could not start Selenium session: NUL
at com.thoughtworks.selenium.DefaultSelenium.start(DefaultSelenium.java:89)
at com.thoughtworks.selenium.SeleneseTestBase.setUp(SeleneseTestBase.java:123)
at com.thoughtworks.selenium.SeleneseTestBase.setUp(SeleneseTestBase.java:104)
at com.thoughtworks.selenium.SeleneseTestCase.setUp(SeleneseTestCase.java:78)
at com.adminserver.pas.test.BaseSeleniumTest.setUp(BaseSeleniumTest.java:69)
at com.adminserver.pas.test.SimpleSmokeTest.setUp(SimpleSmokeTest.java:22)
at junit.framework.TestCase.runBare(TestCase.java:132)
at com.thoughtworks.selenium.SeleneseTestCase.runBare(SeleneseTestCase.java:212)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:81)
at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:62)
at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:140)
at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:127)
at org.apache.maven.surefire.Surefire.run(Surefire.java:177)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:338)
at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:997)
Here is the relevant snippets in my pom.xml
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>selenium-maven-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<id>start-selenium</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start-server</goal>
</goals>
</execution>
</executions>
<configuration>
<timeout>30</timeout>
<background>true</background>
<port>4444</port>
<logOutput>true</logOutput>
<verifyBrowser>*iexplore</verifyBrowser>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4.2</version>
<configuration>
<skip>true</skip>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
<executions>
<execution>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<skip>false</skip>
</configuration>
</execution>
</executions>
</plugin>
Here is the output from the selenium server.log file:
11:35:51,542 INFO [org.openqa.selenium.server.SeleniumServer] Java: Sun Microsystems Inc. 1.5.0_19-b02
11:35:51,542 INFO [org.openqa.selenium.server.SeleniumServer] OS: Windows 2003 5.2 x86
11:35:51,592 INFO [org.openqa.selenium.server.SeleniumServer] v1.0.1 [2697], with Core v#VERSION# [#REVISION#]
11:35:51,712 INFO [org.mortbay.http.HttpServer] Version Jetty/5.1.x
11:35:51,712 INFO [org.mortbay.util.Container] Started HttpContext[/,/]
11:35:51,722 INFO [org.mortbay.util.Container] Started HttpContext[/selenium-server,/selenium-server]
11:35:51,722 INFO [org.mortbay.util.Container] Started HttpContext[/selenium-server/driver,/selenium-server/driver]
11:35:51,732 INFO [org.mortbay.http.SocketListener] Started SocketListener on 0.0.0.0:4444
11:35:51,732 INFO [org.mortbay.util.Container] Started org.mortbay.jetty.Server#bf32c

I got this finally to work. Here are a couple of things that made this work:
JBOSS in the default startup started up its RMI Port on 4444 (that's the same one as Selenium ). Not sure why I this wasn't more blatant obvious, maybe the sequence of runs in the maven file. I added a port to the selenium-maven-plugin configuration, and added a system property of selenim.port to the surefire-plugin, PRESTO, it worked.
My plugin repository for Codehause (which publishes the selenium-maven-plugin) was set to snapshots (DOH). I changed it to the release repo, that seemed to get things moving.
I changed the type of the project to "pom", so it didn't attempt to create a JAR
I don't know if it mattered or not, but I moved the surefire plugin to be AFTER the selenium-maven-plugin

Related

Maven build fails with failsafe plugin

I am trying to build my project and run the test by using junit5 and maven failsafe plugin for integration tests.
If I run my test by using
mvn failsafe:integration-test
it runs all the integration tests.
When I run
maven install
failsafe plugin fails with integration tests with error. But surfire plugin works normally. I receive following error for failsafe plugin:
TestEngine with ID 'junit-jupiter' failed to discover tests
...
...
Caused by: java.lang.NoClassDefFoundError: com/mypackage/service/MyObject
My pom with failsafe plugin looks like:
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<useModulePath>false</useModulePath>
<includes>
<include>**/*IT.java</include>
</includes>
<excludes>
<exclude>**/*Test.java</exclude>
</excludes>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
I am using junit jupiter version 5.8.2. I tried to use older versions as it was suggested in other posts but it did not help. Any idea what can be wrong here ?

Selenium 4 no longer loading Firefox Driver

After updating a Java application based on Selenium to version 4, I found code packaged as an UberJar failed with the error:
Driver info: driver.version: FirefoxDriver
at java.base/java.util.Optional.orElseThrow(Optional.java:403)
at org.openqa.selenium.firefox.FirefoxDriver.toExecutor(FirefoxDriver.java:230)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:186)
at com.octopus.decorators.FirefoxDecorator.init(FirefoxDecorator.java:72)
Interestingly all tests passed though. How can I fix this?
The issue was because my application was packaged as an UberJAR with the Shade plugin. Selenium 4 must use a different service for locating dependencies based on service lookup, which requires META-INF/service files.
My configuration for building the UberJAR did not correctly capture these service files. The solution was to add the ServicesResourceTransformer to my Shade plugin configuration:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>${shade.version}</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
</transformers>
</configuration>
</plugin>

How To Build Child Modules In Tycho

I have a multi-module Tycho build with a target definition file. The target definition is defined in it's own project (ID: org.acme.project.target, packaging type: pom) like this:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<id>attach-artifacts</id>
<phase>package</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>platform_rcp.target</file>
<type>target</type>
<classifier>platform_rcp</classifier>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
And the Maven parent refers to this target platform like this:
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>target-platform-configuration</artifactId>
<configuration>
<resolver>p2</resolver>
<target>
<artifact>
<groupId>${project.groupId}</groupId>
<artifactId>org.acme.project.target</artifactId>
<version>${project.version}</version>
<classifier>platform_rcp</classifier>
</artifact>
</target>
</configuration>
</plugin>
This setup works as long as I build the parent project. When I build one of the child modules, even if this project duplicates the reference to the target platform OR even when I build the parent with mvn install -pl org.acme.project I get the following exception:
[ERROR] Internal error: java.lang.RuntimeException: Could not resolve target platform specification artifact myGroup:org.acme.project.target:target:platform_rcp:2.3.0-SNAPSHOT -> [Help 1]
org.apache.maven.InternalErrorException: Internal error: java.lang.RuntimeException: Could not resolve target platform specification artifact myGroup:org.acme.project.target:target:platform_rcp:2.3.0-SNAPSHOT
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:121)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:862)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:286)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:197)
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:483)
Even the Tycho example doesn't work for me, but brings the same error message (Could not resolve target platform specification artifact example.group:mars:target:1.0.0-SNAPSHOT).
I thought this question was similar, but my setup is exactly what is said to work in the answer.
What did I do wrong?
(The actual problem in question is that Eclipse Mars can't run integration tests, so I can only use Tycho to run them, which needs a long time when Tycho builds all modules.)
even when I build the parent with mvn install -pl org.acme.project I get the following exception:
Have you tried prepending the target platform project to the list of -pl arguments: mvn install -pl :mars,org.acme.project
I use this all the time.

Can't run and debug groovy tests under intellij idea

I try to embed groovy test to java project.
I start with spock examples - https://github.com/spockframework/spock-example
Examples is compile and execute by running maven goal test but if i try to run test under intellij idea (ctrl+F10 under test method) it failure with classpath error.
Error running HelloSpockSpec.length of Spock's and his friends' names:
Class 'HelloSpockSpec' not found in module 'spock-example'
I try to apply advices from IntelliJ + Groovy + Spock but it didn't help.
Don't forget to mark the folder as "Test Sources" in IntelliJ
Then it should work as expected :-)
Intellij can automatically add the groovy source as a source directory based on your pom. Add build-helper-maven-plugin config to your maven pom under plugins specifying ${basedir}/src/test/groovy as a source dir:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-groovy-test-source</id>
<phase>test</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>${basedir}/src/test/groovy</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>

install4j 5.1.5 - Signing: disable at command line or maven plugin not possible

Today I integrated the signing process to our project. It works fine. Now I tried to disable the signing process at the maven-plugin:
<plugin>
<groupId>org.sonatype.install4j</groupId>
<artifactId>install4j-maven-plugin</artifactId>
<version>1.0.5</version>
<executions>
<execution>
<id>build-installer</id>
<phase>prepare-package</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<projectFile>${project.build.outputDirectory}/${install4j.projectFile}</projectFile>
<destination>${project.build.directory}/installer</destination>
<disableSigning>${disableSigning}</disableSigning>
<!-- password for keystore has to be set as system property -->
<winKeystorePassword>${certificate.keystore.psw}</winKeystorePassword>
</configuration>
</execution>
</executions>
</plugin>
Then I was calling our maven build with the following command:
mvn clean prepare-package -DdisableSigning=true
and got the following error message:
[INFO] --- install4j-maven-plugin:1.0.5:compile (build-installer) # ForumViewerInstaller ---
[INFO] install4j: Unknown option '--disable-signing'
[INFO] Usage: install4jc [OPTIONS] [config file]
[INFO] Try 'install4jc --help for more information'
It looks like the maven-plugin is not compatible with install4j 5 anymore, is it? Or could it be a problem with my install4j configuration?
Thanks for any solution
Hardie
This is a bug that will be fixed in install4j 5.1.11. Currently only the short form -u works.