I'm new in using docker, so I have problems trying to run my selenium tests in it. I know that I need to run selenium server either with grid or standalone and it works fine, but how do I run my tests through docker (docker run mytest:1.0)? I'm keep getting errors such as "urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=4444): Max retries exceeded with url: /wd/hub/session", but if I run my tests on local machine - it works fine.
Dockerfile:
FROM python:3.8
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt
COPY . /tests
WORKDIR /tests
CMD [ "pytest", "-vv", "-s", "test_selenium.py" ]
Docker-compose.yaml:
version: "3"
services:
chrome:
image: selenium/node-chrome:4.0.0-rc-1-prerelease-20210823
shm_size: 2gb
depends_on:
- selenium-hub
environment:
- SE_EVENT_BUS_HOST=selenium-hub
- SE_EVENT_BUS_PUBLISH_PORT=4442
- SE_EVENT_BUS_SUBSCRIBE_PORT=4443
ports:
- "7900:7900"
selenium-hub:
image: selenium/hub:4.0.0-rc-1-prerelease-20210823
container_name: selenium-hub
ports:
- "4442:4442"
- "4443:4443"
- "4444:4444"
My driver initialization in test_file:
driver = webdriver.Remote('http://localhost:4444/wd/hub', desired_capabilities=DesiredCapabilities.CHROME)