Reputation: 108
I am trying to run my automation GUI test suites which is located in my automation container.
I seperately downloaded standalone selenium-firefox image and running as container running on port 4444. which is running on
localhost:4444/wd/hub
Now, I am trying to run the test suites which is in my automation container, i am using below code to run in headless mode to reach the firefox version of selenium in my robotframework test suite.
Open Browser http://www.youtube.com headlessfirefox remote_url=http://localhost:4444/wd/hub
This approach is working fine when i run my test suite from my machine, it fails when i run it inside the automation container.
is there any way that my automation container can reach the selenium-firefox container to use the browser.
Error:
C: 10: Open Chrome headless
/usr/local/lib/python3.6/site-packages/requests/__init__.py:91:
RequestsDependencyWarning: urllib3 (1.26.3) or chardet (3.0.4) doesn't
match a supported version!
RequestsDependencyWarning)
[ WARN ] Retrying (Retry(total=2, connect=None, read=None, redirect=None,
status=None)) after connection broken by
'NewConnectionError('<urllib3.connection.HTTPConnection object at
0x7f4a322440b8>: Failed to establish a
[ WARN ] Retrying (Retry(total=1, connect=None, read=None, redirect=None,
status=None)) after connection broken by
'NewConnectionError('<urllib3.connection.HTTPConnection object at
0x7f4a32244710>: Failed to establish a
new connection: [Errno 111] Connection refused',)': /wd/hub/session
[ WARN ] Retrying (Retry(total=0, connect=None, read=None, redirect=None,
status=None)) after connection broken by
'NewConnectionError('<urllib3.connection.HTTPConnection object at
0x7f4a32235710>: Failed to establish a
new connection: [Errno 111] Connection refused',)': /wd/hub/session
| FAIL |
MaxRetryError: HTTPConnectionPool(host='localhost', port=4444): Max
retries exceeded with url: /wd/hub/session (Caused by
NewConnectionError('<urllib3.connection.HTTPConnection object at
0x7f4a32235438>: Failed to establish a new connection: [Errno 111]
Connection refused',))
Any help would be thankful
Upvotes: 3
Views: 6853
Reputation: 3543
You need to create docker-compose.yml file with all of the containers what you're going to create:
version: '3.8'
services:
chrome:
image: selenium/standalone-chrome:85.0
hostname: chrome
ports:
- "4444:4444"
e2e-tests:
build: .
depends_on:
- chrome
and use host name 'chrome' inside container what is going to use it like:
cls.driver = webdriver.Remote(command_executor='http://chrome:4444/wd/hub',desired_capabilities=DesiredCapabilities.CHROME)
Upvotes: 5
Reputation: 826
Your container is considered a different machine, network-wise. When you launch the selenium-firefox image, you probably link the port 4444 of your container with port 4444 of your host. Then, when you request localhost:4444 on your host, it links to your container.
But when you launch another container, localhost:4444 means port 4444 of this container !
What you should do is use the embed dns mechanic docker offers : when you create a container, it has a name (thar you can specify). Docker gives it an internal ip on the default docker network but does not associate the container name with that ip. To be able to use the container name as a domain name in your urls, you need to create a new network, which then will user the embed docker dns and get it's own name as an alias.
That is why Vova answer was working : docker-compose creates a network by default for your container, which means they get an alias automatically. I was so used to use network and/or compose that I overlooked the fact that alias weren't automatic on the default docker network.
You shoudl create a specific bridge network only for those containers : docker network create selenium-net --driver bridge
Then docker run -p 4444:4444 --name selenium --network selenium-net selenium/standalone-firefox:latest
When you run your other container, you should also add them in the selenium-net
network
An alternative is to connect the containers you already have to the network : let's say I have containers selenium
and testsuite
running (or existing)
I will run docker network connect selenium-net selenium
and docker network connect selenium-net testsuite
to put them in the network. When you do that, you can specify the --alias
option if you want to give them a particuliar alias/domain on the docker network.
Upvotes: 2