peter cooke
peter cooke

Reputation: 999

Java maven selenium webdriver not working in docker container

I have a maven build that is working on my mac but am trying to put into docker container. I am using the base maven:3.5-jdk-9-slim docker container.

mvn clean verify -Dbrowser.name=phantomjs -X -e

only recently , I upgraded to use java 9. I don't think I installed any thing specific for web driver so not sure why I would get this stack trace. I thought maven took care of it all. A Google search did not find any easy solution for me. Any thoughts on what would be missing in my container????

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.reflection.CachedClass$3$1 (file:/root/.m2/repository/org/codehaus/groovy/groovy/2.4.6/groovy-2.4.6.jar) to method java.lang.Object.finalize()
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.reflection.CachedClass$3$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
/atdd/src/test/resources/bin/mac/phantomjs: 1: /atdd/src/test/resources/bin/mac/phantomjs: Syntax error: Unterminated quoted string
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 23.673 sec <<< FAILURE! - in net.xeric.demos.DemoApplicationTests
contextLoads(net.xeric.demos.DemoApplicationTests)  Time elapsed: 0.019 sec  <<< ERROR!
java.lang.IllegalStateException: Failed to load ApplicationContext
    ......
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103)
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'demoPage' defined in file [/atdd/target/test-classes/net/xeric/demos/pages/DemoPage.class]: Unsatisfied dependency expressed through constructor argument with index 0 of type [org.openqa.selenium.WebDriver]: Error creating bean with name 'getWebDriver' defined in class path resource [net/xeric/demos/TestConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.openqa.selenium.WebDriver]: Factory method 'getWebDriver' threw exception; nested exception is org.openqa.selenium.WebDriverException: Timed out waiting for driver server to start.
Build info: version: '3.5.3', revision: 'a88d25fe6b', time: '2017-08-29T12:42:44.417Z'
System info: host: '1786321beb2b', ip: '172.17.0.2', os.name: 'Linux', os.arch: 'amd64', os.version: '4.9.60-linuxkit-aufs', java.version: '9.0.1'
Driver info: driver.version: PhantomJSDriver; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'getWebDriver' defined in class path resource [net/xeric/demos/TestConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.openqa.selenium.WebDriver]: Factory method 'getWebDriver' threw exception; nested exception is org.openqa.selenium.WebDriverException: Timed out waiting for driver server to start.
Build info: version: '3.5.3', revision: 'a88d25fe6b', time: '2017-08-29T12:42:44.417Z'
System info: host: '1786321beb2b', ip: '172.17.0.2', os.name: 'Linux', os.arch: 'amd64', os.version: '4.9.60-linuxkit-aufs', java.version: '9.0.1'
Driver info: driver.version: PhantomJSDriver
    at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:749)
    ......
    at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:155)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'getWebDriver' defined in class path resource [net/xeric/demos/TestConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.openqa.selenium.WebDriver]: Factory method 'getWebDriver' threw exception; nested exception is org.openqa.selenium.WebDriverException: Timed out waiting for driver server to start.
Build info: version: '3.5.3', revision: 'a88d25fe6b', time: '2017-08-29T12:42:44.417Z'
System info: host: '1786321beb2b', ip: '172.17.0.2', os.name: 'Linux', os.arch: 'amd64', os.version: '4.9.60-linuxkit-aufs', java.version: '9.0.1'
Driver info: driver.version: PhantomJSDriver
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599)
   ......
    at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:155)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103)
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.openqa.selenium.WebDriver]: Factory method 'getWebDriver' threw exception; nested exception is org.openqa.selenium.WebDriverException: Timed out waiting for driver server to start.
Build info: version: '3.5.3', revision: 'a88d25fe6b', time: '2017-08-29T12:42:44.417Z'
System info: host: '1786321beb2b', ip: '172.17.0.2', os.name: 'Linux', os.arch: 'amd64', os.version: '4.9.60-linuxkit-aufs', java.version: '9.0.1'
Driver info: driver.version: PhantomJSDriver
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
   ......
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103)
Caused by: org.openqa.selenium.WebDriverException: Timed out waiting for driver server to start.
Build info: version: '3.5.3', revision: 'a88d25fe6b', time: '2017-08-29T12:42:44.417Z'
System info: host: '1786321beb2b', ip: '172.17.0.2', os.name: 'Linux', os.arch: 'amd64', os.version: '4.9.60-linuxkit-aufs', java.version: '9.0.1'
Driver info: driver.version: PhantomJSDriver
    at org.openqa.selenium.remote.service.DriverService.waitUntilAvailable(DriverService.java:192)
    at org.openqa.selenium.remote.service.DriverService.start(DriverService.java:178)
    at org.openqa.selenium.phantomjs.PhantomJSCommandExecutor.execute(PhantomJSCommandExecutor.java:78)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:646)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:255)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:237)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:138)
    at org.openqa.selenium.phantomjs.PhantomJSDriver.<init>(PhantomJSDriver.java:116)
    at org.openqa.selenium.phantomjs.PhantomJSDriver.<init>(PhantomJSDriver.java:105)
    at org.openqa.selenium.phantomjs.PhantomJSDriver.<init>(PhantomJSDriver.java:95)
    at net.xeric.demos.TestConfig.getWebDriver(TestConfig.java:29)
    at net.xeric.demos.TestConfig$$EnhancerBySpringCGLIB$$7a81f897.CGLIB$getWebDriver$0(<generated>)
    at net.xeric.demos.TestConfig$$EnhancerBySpringCGLIB$$7a81f897$$FastClassBySpringCGLIB$$64edc4da.invoke(<generated>)
 .....      
    at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:155)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103)
Caused by: org.openqa.selenium.net.UrlChecker$TimeoutException: Timed out waiting for [http://localhost:3437/status] to be available after 20004 ms
    at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:102)
    at org.openqa.selenium.remote.service.DriverService.waitUntilAvailable(DriverService.java:187)
    ......
    at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:155)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103)
Caused by: java.util.concurrent.TimeoutException: null
at java.base/java.util.concurrent.FutureTask.get(FutureTask.java:204)
at com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter.java:147)
at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:77)
at org.openqa.selenium.remote.service.DriverService.waitUntilAvailable(DriverService.java:187)

Upvotes: 1

Views: 948

Answers (1)

David BARAN
David BARAN

Reputation: 26

I had the same issue in a similar context (GitLab, Jasmine tests launched by Maven via phantomjs-maven-plugin, docker image maven:3.6-jdk-8-slim). I had to use following commands in my docker image before running my tests:

apt-get update
apt-get install -y libfontconfig1 fontconfig libfontconfig1-dev libfreetype6-dev
export OPENSSL_CONF=/etc/ssl

sources:

Upvotes: 1

Related Questions