SeleniumHQ / docker-selenium

Provides a simple way to run Selenium Grid with Chrome, Firefox, and Edge using Docker, making it easier to perform browser automation
http://www.selenium.dev/docker-selenium/
Other
7.96k stars 2.51k forks source link

[🐛 Bug]: Selenium Grid 4 does not work in a Gitlab CI/CD pipeline #1600

Closed merrillh closed 2 years ago

merrillh commented 2 years ago

What happened?

My gitlab.ci.yml config fails for my deployment pipleline but my docker-compose.yml works locally. The service running a Selenium Chrome node node doesn't register with the Selenium hub service, resulting in a hub not ready error. The default port 5555 used to connect to the hub on the Selenium Chrome node isn't open, even if I make a custom docker image to open the port using EXPOSE 5555.

Command used to start Selenium Grid with Docker

#this works locally
chrome-webdriver:
    image: selenium/node-chrome:4.1.4-20220427
    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

selenium-hub:
    image: selenium/hub:4.1.4-20220427
    container_name: selenium-hub
    ports:
        - "4442:4442"
        - "4443:4443"
        - "4444:4444"

dotnet-test-end-to-end:
    image: mcr.microsoft.com/dotnet/sdk:5.0
    working_dir: /var/www/html
    volumes:
        - ./tests_end_to_end:/test/.
    command: tail -F anything
    environment:
        - SELENIUM_HUB=http://selenium-hub:4444

docker compose up

```yaml gitlab-ci.yml
#this doesn't work

test-frontend:
    stage: test-end-to-end
    variables:
        FF_NETWORK_PER_BUILD: 1
    services:
      - name: selenium/hub:4.1.4-20220427
        alias: selenium-hub
      - name: selenium/node-chrome:4.1.4-20220427
        alias: chrome-webdriver
        variables:
            SE_EVENT_BUS_HOST: selenium-hub
            SE_EVENT_BUS_PUBLISH_PORT: 4442
            SE_EVENT_BUS_SUBSCRIBE_PORT: 4443

    image: $TEST_FROTEND_IMAGE:$IMAGE_TAG
    variables:
      SELENIUM_HUB: http://selenium-hub:4444
    script:
      - curl -X GET http://selenium-hub:4444/status
      - curl -X GET http://chrome-webdriver:5555/status
      - dotnet test web-html/tests_end_to_end/csharp_test

### Relevant log output

```shell
Running with gitlab-runner 13.8.0
  on gitlab executor 
Preparing the "docker" executor
Using Docker executor with image [MASKED]/app/end-to-end-test ...
Starting service selenium/hub:4.1.4-20220427 ...
Pulling docker image selenium/hub:4.1.4-20220427 ...
Using docker image sha256:68a462272959ba572057bf5822f70fec521cd458e6eacfa56682a797e4797d6f for selenium/hub:4.1.4-20220427 with digest selenium/hub@sha256:f48603db8b9795dd851d79477da8e7e205193d7e7553bf78d045b0fd328f9b41 ...
WARNING: Service selenium/hub:4.1.4-20220427 is already created. Ignoring.
Starting service selenium/node-chrome:4.1.4-20220427 ...
Pulling docker image selenium/node-chrome:4.1.4-20220427 ...
Using docker image sha256:c901064778ac7be4dd8b4cf6d6f189fe822a8dcf9469a7326790ba4823578793 for selenium/node-chrome:4.1.4-20220427 with digest selenium/node-chrome@sha256:7b22b191df3d9a7182b5a68ed12d151a046e3baf989471e53d777971f77c91c2 ...
Waiting for services to be up and running...
Pulling docker image [MASKED]/app/end-to-end-test
Using docker image sha256:2c9e28c02512ef4ac04a65d727240359246f9a967b186f512926f2d2438cff08 for [MASKED]/app/-frontend-test
Preparing environment
00:01
Running on runner via ais-gitlab-runner...
Getting source from Git repository
00:02

Executing "step_script" stage of the job script
00:01
$ curl selenium-hub:4444 --max-time 1; echo $?
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
0
$ curl -X GET http://selenium-hub:4444/status
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   104  100   104    0     0   {
  "value": {
    "ready": false,
    "message": "Selenium Grid not ready.",
    "nodes": [
    ]
  }
}1283      0 --:--:-- --:--:-- --:--:--  1283
$ curl -X GET http://chrome-webdriver:5555/status
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  curl: (7) Failed to connect to chrome-webdriver port 5555: Connection refused

Operating System

macos & linux based gitlab runner

Docker Selenium version (tag)

selenium/hub:4.1.4-20220427 and Selenium/node-chrome:4.1.4-20220427

diemol commented 2 years ago

Not sure how we can help here, as I am not an expert in GitLab. Maybe check the GitLab docs and see how can services talk to each other.

diemol commented 2 years ago

Closing this as there is not much we can do about this.

shameekagarwal commented 2 years ago

maybe my answer can help someone get started

kathyrollo commented 1 year ago

@diemol I must say, getting GitLab CI/CD and selenium/hub + selenium/node-<browser> (Docker in Docker) to work together is notoriously difficult. YAML templates for commonly used pipelines in the readme can be an increasingly important resource as this will be common occurrence to fully utilise Docker Selenium.

Sadly, I haven't figured it out yet.

github-actions[bot] commented 10 months ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.