aerokube / selenoid

Selenium Hub successor running browsers within containers. Scalable, immutable, self hosted Selenium-Grid on any platform with single binary.
https://aerokube.com/selenoid/latest/
Apache License 2.0
2.6k stars 324 forks source link

Docker + Selenoid + ggr - ERROR webdriver: RequestError: connect ECONNREFUSED 127.0.0.1:4445 #1265

Closed HarryFree closed 2 years ago

HarryFree commented 2 years ago

Hi, I build docker image and run the test on selenoid container, but test is failing on refuse connection

docker file

FROM alpine:latest

RUN apk --no-cache add \
    build-base\
    python3\
    nodejs \
    npm \
    ffmpeg \
    libjpeg \
    cairo-dev \
    imagemagick \
    icu-dev \
    jpeg-dev \
    libpng-dev \
    pango-dev \
    giflib-dev \
    gd-dev \
    && npm install -g \
    npm@latest \
    android-tools \
    && rm -rf \
    /tmp/* \
    /root/.npm

WORKDIR /usr/lib/wdio

COPY package.json /usr/lib/wdio
COPY package-lock.json /usr/lib/wdio

RUN npm install \
    && rm -rf \
    /tmp/* \
    /root/.npm

COPY . /usr/lib/wdio

ENTRYPOINT [ "npm", "run" ]

CMD [ "web-test" ]

Docker compose file

version: '3.4'

services:
  selenoid:
    container_name: selenoid
    image: aerokube/selenoid:latest
    network_mode: bridge
    restart: unless-stopped
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock"
      - "/etc/selenoid/video/:/opt/selenoid/video/"
      - "/etc/selenoid/logs/:/opt/selenoid/logs/"
      - "/etc/selenoid/config/:/opt/selenoid/config/"
      - "./core/browser-config/:/etc/selenoid"
      - "./resources/videos/:/etc/selenoid/videos"
    environment:
      #- OVERRIDE_VIDEO_OUTPUT_DIR=$PWD
      - TZ=Asia/Singapore
    command:
      [
        "-conf",
        "/etc/selenoid/browsers.json",
        "-limit",
        "15",
        "-timeout",
        "20m",
        "-video-output-dir",
        "/etc/selenoid/video",
        "-log-output-dir",
        "/etc/selenoid/logs",
        "-save-all-logs"
      ]
    ports:
      - "4445:4444"

  selenoid-ui:
    container_name: selenoid-ui
    image: aerokube/selenoid-ui
    network_mode: bridge
    restart: unless-stopped
    links:
      - selenoid
    ports:
      - 8080:8080
    command: [ "--selenoid-uri", "http://selenoid:4444" ]

  ggr:
    container_name: ggr
    image: aerokube/ggr
    network_mode: bridge
    restart: unless-stopped
    volumes:
      - "/etc/grid-router/:/etc/grid-router/:ro"
    depends_on:
      - selenoid
    links:
      - selenoid
    ports:
      - "4444:4444"

  ggr-ui:
    container_name: ggr-ui
    image: aerokube/ggr-ui
    network_mode: bridge
    restart: unless-stopped
    volumes:
      - "/etc/grid-router/:/etc/grid-router/:ro"
    depends_on:
      - selenoid
      - ggr
    links:
      - selenoid
    ports:
      - "8888:8888"

  chrome:
    container_name: chrome
    image: sskorol/selenoid_chromium_vnc:100.0
    network_mode: bridge
    depends_on:
      - selenoid
    links:
      - selenoid
    ports:
      - "4447:4444"

  e2e:
    image: qa-test
    network_mode: bridge
    build: .
    depends_on:
      - selenoid
    links:
      - selenoid
    volumes:
      - "./reports/allure-results:/usr/lib/wdio/allure-results"

docker compose test

version: '3.4'

services:
  e2e:
    container_name: web-login
    image: qa-test
    network_mode: bridge
    depends_on:
      - selenoid
      - selenoid-ui
      - chrome
    links:
      - selenoid
      - selenoid-ui
      - chrome

wdio config

export const config: Options.Testrunner = merge(webRunnerConfig, {

    specs: ['tests/features/web/**/*.feature'],
    exclude: [  ],

    maxInstances: 15,
    capabilities: browserCaps(), // getting from config files

    specFileRetries: 0,
    specFileRetriesDelay: 5,
    baseUrl: getEnvUrl(),
    runner: 'local',
    protocol: 'http',
    hostname: 'localhost',
    path: '/wd/hub',
    port: 4445,
    user: 'test',
    key: 'Password18',
    services: isLocalOrDocker(),
    cucumberOpts: cucumberOptions(stepFiles, process.env.Tags),

})

compose build and up

docker-compose -f docker-compose.yml -f docker-compose.test.yml build
docker-compose -f docker-compose.yml -f docker-compose.test.yml up

Error

RUNNING in chrome - /tests/features/web/login/smoke/Login.feature
 2022-09-16T06:33:10.134Z ERROR webdriver: RequestError: connect ECONNREFUSED 127.0.0.1:4445
     at ClientRequest.<anonymous> (/usr/lib/wdio/node_modules/got/dist/source/core/index.js:970:111)
     at Object.onceWrapper (node:events:642:26)
     at ClientRequest.emit (node:events:539:35)
     at ClientRequest.emit (node:domain:475:12)
     at ClientRequest.origin.emit (/usr/lib/wdio/node_modules/@szmarczak/http-timer/dist/source/index.js:43:20)
     at Socket.socketErrorListener (node:_http_client:454:9)
     at Socket.emit (node:events:527:28)
     at Socket.emit (node:domain:475:12)
     at emitErrorNT (node:internal/streams/destroy:157:8)
     at emitErrorCloseNT (node:internal/streams/destroy:122:3)
     at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1187:16)
 2022-09-16T06:33:10.150Z ERROR @wdio/runner: Error: Failed to create session.
 Unable to connect to "http://localhost:4445/wd/hub", make sure browser driver is running on that address.
 If you use services like chromedriver see initialiseServices logs above or in wdio.log file as the service might had problems to start the driver.
     at startWebDriverSession (/usr/lib/wdio/node_modules/webdriver/build/utils.js:73:15)
     at processTicksAndRejections (node:internal/process/task_queues:96:5)
     at async Function.newSession (/usr/lib/wdio/node_modules/webdriver/build/index.js:46:45)
     at async remote (/usr/lib/wdio/node_modules/webdriverio/build/index.js:77:22)
     at async Runner._startSession (/usr/lib/wdio/node_modules/@wdio/runner/build/index.js:223:56)
     at async Runner._initSession (/usr/lib/wdio/node_modules/@wdio/runner/build/index.js:176:25)
     at async Runner.run (/usr/lib/wdio/node_modules/@wdio/runner/build/index.js:88:19)
 FAILED in chrome - /tests/features/web/login/smoke/Login.feature

Logs

Selenoid

2022/09/16 13:32:51 [-] [INIT] [Loading configuration files...]
2022/09/16 13:32:51 [-] [INIT] [Loaded configuration from /etc/selenoid/browsers.json]
2022/09/16 13:32:51 [-] [INIT] [Video Dir: /etc/selenoid/video]
2022/09/16 13:32:51 [-] [INIT] [Logs Dir: /etc/selenoid/logs]
2022/09/16 13:32:51 [-] [INIT] [Saving all logs]
2022/09/16 13:32:51 [-] [INIT] [Your Docker API version is 1.41]
2022/09/16 13:32:51 [-] [INIT] [Timezone: Asia/Singapore]
2022/09/16 13:32:51 [-] [INIT] [Listening on :4444]

ggr

2022/09/16 06:32:52 [-] [-] [INIT] [-] [-] [-] [-] [-] [-] [Users file is "/etc/grid-router/users.htpasswd"]
2022/09/16 06:32:52 [-] [-] [INIT] [-] [-] [-] [-] [-] [-] [Loading configuration files from "/etc/grid-router/quota"]
2022/09/16 06:36:50 [-] [5m0s] [SHUTTING_DOWN] [-] [-] [-] [-] [-] [-] [-]

could someone please help on this?

vania-pooh commented 2 years ago

@HarryFree Should be selenoid:4444 instead of 127.0.0.1:4445. This is because containers are living in the same Docker network and you can refer by container name. Take a look at Docker networking documentation.

HarryFree commented 2 years ago

Thank you. changed as suggested and works fine.