0

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
k_rollo
  • 5,304
  • 16
  • 63
  • 95
  • Where is your GitLab running? – Alexey R. Feb 09 '23 at 12:42
  • If they are running within the same virtua; network you should use `selenium-hub` as the host name to your grid. – Alexey R. Feb 09 '23 at 12:51
  • @AlexeyR. I am using whatever the default runner is for pipelines (new to GitLab, didn't alter anything in the project settings apart from env vars). Unfortunately, using `http://selenium-hub:4444` also threw the `UnknownHostException`. Any ideas? – k_rollo Feb 09 '23 at 13:03
  • I mean if it runs on host machine where docker is running or it runs also within a container or it runs on different physical machine – Alexey R. Feb 09 '23 at 14:02
  • gitlab is just a service. It has to be hosted somewhere. Alright. let me focus my question. Do you know where your tests run. On which machine. So we do understand where we would like to connect. It is your selenium hub container. But now we should also understand **where we are connecting from**. – Alexey R. Feb 09 '23 at 14:50
  • I'm using this "shared runner" that is provided by default in the GitLab pipelines. I did not config any machine (physical or virtual), just these 2 YAML files. The shared runner runs the tests on some default agent I don't know. – k_rollo Feb 09 '23 at 14:57
  • Where do you deploy your selenium container? Also sometwhere in the cloud or on your local machine? – Alexey R. Feb 09 '23 at 15:53
  • All in the cloud. Everything via the shared runner provided in GitLab pipelines by default. – k_rollo Feb 09 '23 at 20:32
  • @k_rollo I am facing the same issue. Were you able to resolve this? – shank087 Aug 16 '23 at 10:50

0 Answers0