Selenium Grid 4 uses http://localhost:4444
instead of http://localhost:4444/wd/hub
which is Selenium Grid 3. Following this thread, I used http://docker:4444
as below.
.gitlab-ci.yml:
variables:
MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository"
# Other vars
SELENIUM_GRID_URL: "http://docker:4444"
cache:
paths:
- .m2/repository/
- target/
stages:
- build
- test
compile:
stage: build
image: maven:3.8.7-eclipse-temurin-17
script: mvn compile
docker-selenium:
stage: test
image: docker:23.0.0
services:
- docker:23.0.0-dind
script:
- docker compose up -d
junit:
stage: test
needs: ["docker-selenium"]
image: maven:3.8.7-eclipse-temurin-17
script: mvn test -Dparallel-enabled=true -Dthread-count=7
docker-compose.yml:
version: "3.8"
services:
chrome:
image: selenium/node-chrome:latest
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
- SE_NODE_MAX_SESSIONS=8
- SE_NODE_OVERRIDE_MAX_SESSIONS=true
- SE_VNC_NO_PASSWORD=1
- SE_VNC_VIEW_ONLY=1
firefox:
image: selenium/node-firefox:latest
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
- SE_NODE_MAX_SESSIONS=8
- SE_NODE_OVERRIDE_MAX_SESSIONS=true
- SE_VNC_NO_PASSWORD=1
- SE_VNC_VIEW_ONLY=1
selenium-hub:
image: selenium/hub:latest
container_name: selenium-hub
ports:
- "4444:4444"
The RemoteWebDriver
is instantiated like this:
WebDriver driver = new RemoteWebDriver(gridUrl, options)
Exception when I use docker
as hostname:
Caused by: java.net.UnknownHostException: docker
Exception when I use localhost
as hostname:
Caused by: java.net.ConnectException: Connection refused: localhost/[0:0:0:0:0:0:0:1]:4444