Reputation: 21
We are trying to run tests using WebDriverManager from inside our container.
The execution fails with the following
There was an error creating WebDriver object for Firefox
io.github.bonigarcia.wdm.config.WebDriverManagerException: There was an error creating WebDriver object for Firefox
at io.github.bonigarcia.wdm.WebDriverManager.instantiateDriver(WebDriverManager.java:1774)
at io.github.bonigarcia.wdm.WebDriverManager.create(WebDriverManager.java:424)
Caused by: io.github.bonigarcia.wdm.config.WebDriverManagerException: Timeout of 30 seconds creating WebDriver object
at io.github.bonigarcia.wdm.webdriver.WebDriverCreator.createRemoteWebDriver(WebDriverCreator.java:95)
at io.github.bonigarcia.wdm.WebDriverManager.createDockerWebDriver(WebDriverManager.java:1896)
at io.github.bonigarcia.wdm.WebDriverManager.instantiateDriver(WebDriverManager.java:1754)
... 32 more
Caused by: java.net.ConnectException: Connection refused (Connection refused)
at java.base/java.net.PlainSocketImpl.socketConnect(Native Method)
at java.base/java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:399)
at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:242)
at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:224)
at java.base/java.net.Socket.connect(Socket.java:609)
at java.base/java.net.Socket.connect(Socket.java:558)
at java.base/sun.net.NetworkClient.doConnect(NetworkClient.java:182)
at java.base/sun.net.www.http.HttpClient.openServer(HttpClient.java:474)
at java.base/sun.net.www.http.HttpClient.openServer(HttpClient.java:569)
at java.base/sun.net.www.http.HttpClient.<init>(HttpClient.java:242)
at java.base/sun.net.www.http.HttpClient.New(HttpClient.java:341)
at java.base/sun.net.www.http.HttpClient.New(HttpClient.java:362)
at java.base/sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:1253)
at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1187)
at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1081)
at java.base/sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:1015)
at io.github.bonigarcia.wdm.webdriver.WebDriverCreator.createRemoteWebDriver(WebDriverCreator.java:84)
... 34 more
Out of container, running on the local Host machine, it works. However, inside our container with java, maven and other stuff, they fail with the mentioned Connection refused (Connection refused) error.
in the console logs
[main] INFO io.github.bonigarcia.wdm.docker.DockerService - Pulling Docker image selenoid/vnc:firefox_106.0 (this might take some time, but only the first time)
[main] INFO io.github.bonigarcia.wdm.docker.DockerService - Starting Docker container selenoid/vnc:firefox_106.0
Both containers run in the same bridge network.
What can cause the this issue? Is there an idea how to solve or avoid it?
Thanks.
After enabling the debug logging and doing some set of tests I found out following:
This is the url which the WebDriver instance is trying to connect to when we do the execution from inside a container by using browserInDocker
Browser remote URL http://localhost:50967/wd/hub
It uses the mapped port 50967 from the browser container's server port 4444
.
Obviously, that localhost is not accessible from the first container but out of containers. From the first container the server is available through the internal docker network (port mapping is not needed) via
http://172.17.0.3:4444/wd/hub
but WebDriverManager is not using it, as it doesn't know that it was executed from a container and should treat the browser's container as a remote server. That means, when we tell the WebDriver to connect to the RemoteAddress http://172.17.0.3:4444/wd/hub
form the first container (without using browserInDocker), it works. But, as testing shows the RemoteAddress
is ignored when browserInDocker()
is used.
There are 2 limitation here, 1) we need to know the ip address for the browser container which was started when we called browserInDocker()
(WebDriverManager has the container ID, it can inspect it and get it, but probably this scenario wasn't considered), 2) we should tell the WebDriver to start the session with that address, actually with that RemoteAddress, but RemoteAddress is ignored when the browserInDocker()
is used, the wdm.remoteAddress(...) does nothing, we can't control the WebDriver sessions server address when browserInDocker()
.
Based on this testing, a question is rising, does WebDriverManager support a run from a container with browserInDocker()
.
Upvotes: 2
Views: 587