Search code examples
dockerselenium-webdriverwebdriverchromiumarm64

Webdriver (selenium-standalone) tests with chromium - not starting ECONNREFUSED (on Apple M1)


our end to end tests run in a docker container and use Webdriver.io - with selenium-standalone.

Since updating to an M1/arm64 Mac I've been trying to update the tests to run.

Our unit tests (jest) were fixed easily by changing from using the ./google-chrome-stable_current_amd64.deb to using chromium.

Test container dockerfile:

FROM node:14-bullseye
ENV CHROME_BIN=/usr/bin/chromium

RUN apt-get update \
    && apt-get install -y chromium \
    openjdk-11-jre \
    xvfb \
    x11vnc \
    php \
    && mkdir ~/.vnc \
    && x11vnc -storepasswd "fakepwd" ~/.vnc/passwd \
    && rm -rf /var/lib/apt/lists/*

COPY ./entrypoint.sh /usr/local/bin/

ENTRYPOINT ["entrypoint.sh"]

I hoped it would be as simple for webdriver tests but no luck so far.

I've upgraded @wdio packages as below:

    "@wdio/allure-reporter": "^7.10.1",
    "@wdio/cli": "^7.19.3",
    "@wdio/devtools-service": "^7.19.3",
    "@wdio/junit-reporter": "^7.19.1",
    "@wdio/local-runner": "^7.19.3",
    "@wdio/mocha-framework": "^7.19.3",
    "@wdio/selenium-standalone-service": "^7.19.1",
    "@wdio/sync": "^7.19.3",

In the lock file I've confirmed the selenium-standalone version is 7.1. (As above we use 7.19.1 of @wdio's service - this uses ^7.0 but only 7.1 works for M1's: https://github.com/webdriverio/selenium-standalone/commit/10e31d0e20444b0f6eb2d897cb3b471782dd243d)

I've confirmed that the correct chromedriver binary is used too (under ./node_modules/selenium-standalone/.selenium/chromedriver is 99.0.4844.51-arm64)

From wdio.conf.js:

    services:[['selenium-standalone',{
        installArgs: {
            drivers: {
                chrome: {
                    binary: '/usr/bin/chromium',
                    version: chromeDriverVersion,
                    arch : process.arch,
                    baseURL : 'https://chromedriver.storage.googleapis.com'
                }
            }
        },
        args: {
            drivers: {
                chrome: {
                    binary: '/usr/bin/chromium',
                    version: chromeDriverVersion,
                    arch : process.arch
                }
            }
        }
    }]]; 
    capabilities: [{
        browserName: process.env._BROWSER,
        acceptInsecureCerts: true,
        maxInstances: 4,
        'goog:browserOptions': {
            binary: '/usr/bin/chromium', // may not be needed, tried anyway
            args: process.env._ENABLE_UI === 'false' ?
                ['--disable-dev-shm-usage','--no-sandbox','--headless','--disable-infobars','--deterministic-fetch', `--window-size=${default_viewport_width},${default_viewport_height}`] :
                ['--disable-dev-shm-usage','--no-sandbox','--disable-infobars', `--window-size=${default_viewport_width},${default_viewport_height}`]
        }
    }],

Watching wdio log outputs:

2022-04-01T08:09:37.336Z WARN @wdio/utils:shim: You are running tests with @wdio/sync which will be discontinued starting Node.js v16.Read more on https://github.com/webdriverio/webdriverio/discussions/6702
2022-04-01T08:09:40.101Z INFO @wdio/local-runner: Run worker command: run
2022-04-01T08:09:40.124Z DEBUG @wdio/config:ConfigParser: No compiler found, continue without compiling files
2022-04-01T08:09:42.042Z DEBUG @wdio/local-runner:utils: init remote session
2022-04-01T08:09:42.048Z DEBUG @wdio/utils:initialiseServices: initialise service "selenium-standalone" as NPM package
2022-04-01T08:09:42.648Z DEBUG @wdio/sync: Finished to run "beforeSession" hook in 0ms
2022-04-01T08:09:44.535Z DEBUG @wdio/local-runner:utils: init remote session
2022-04-01T08:09:44.536Z INFO webdriver: Initiate new session using the WebDriver protocol
2022-04-01T08:09:44.585Z INFO webdriver: [POST] http://127.0.0.1:4433/wd/hub/session
2022-04-01T08:09:44.586Z INFO webdriver: DATA {
  capabilities: {
    alwaysMatch: {
      browserName: 'chromium',
      acceptInsecureCerts: true,
      'goog:browserOptions': [Object]
    },
    firstMatch: [ {} ]
  },
  desiredCapabilities: {
    browserName: 'chromium',
    acceptInsecureCerts: true,
    'goog:browserOptions': { binary: '/usr/bin/chromium', args: [Array] }
  }
}
2022-04-01T08:09:44.600Z ERROR webdriver: RequestError: connect ECONNREFUSED 127.0.0.1:4433
    at ClientRequest.<anonymous> (/srv/api/author/node_modules/got/dist/source/core/index.js:956:111)
    at Object.onceWrapper (events.js:520:26)
    at ClientRequest.emit (events.js:412:35)
    at ClientRequest.emit (domain.js:475:12)
    at ClientRequest.origin.emit (/srv/api/author/node_modules/@szmarczak/http-timer/dist/source/index.js:43:20)
    at Socket.socketErrorListener (_http_client.js:475:9)
    at Socket.emit (events.js:400:28)
    at Socket.emit (domain.js:475:12)
    at emitErrorNT (internal/streams/destroy.js:106:8)
    at emitErrorCloseNT (internal/streams/destroy.js:74:3)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1159:16)
2022-04-01T08:09:44.601Z ERROR @wdio/runner: Error: Failed to create session.
Unable to connect to "http://127.0.0.1:4433/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 (/srv/api/author/node_modules/webdriver/build/utils.js:72:15)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async Function.newSession (/srv/api/author/node_modules/webdriver/build/index.js:46:45)
    at async remote (/srv/api/author/node_modules/@wdio/runner/node_modules/webdriverio/build/index.js:77:22)
    at async Runner._startSession (/srv/api/author/node_modules/@wdio/runner/build/index.js:223:56)
    at async Runner._initSession (/srv/api/author/node_modules/@wdio/runner/build/index.js:176:25)
    at async Runner.run (/srv/api/author/node_modules/@wdio/runner/build/index.js:88:19)
2022-04-01T08:09:44.601Z DEBUG @wdio/sync: Finished to run "after" hook in 0ms

I presume it's chromium having an issue starting - but I can't find any relevant logs.

I've tried to start it inside the container manually, but I have no idea if there's anything useful here:

root@15adddf1e180:/srv/mydir# export DISPLAY=:99
root@15adddf1e180:/srv/mydir# /usr/bin/Xvfb :99 -ac -screen 0 1920x1080x24 > /dev/null 2>&1 &
[1] 9
root@15adddf1e180:/srv/mydir# x11vnc -listen 0.0.0.0 -display :99.0 -usepw -forever -nevershared > /dev/null 2>&1 &
[2] 24
root@15adddf1e180:/srv/mydir# /usr/bin/chromium --no-sandbox
[25:67:0401/081257.532385:ERROR:bus.cc(397)] Failed to connect to the bus: Failed to connect to socket /run/dbus/system_bus_socket: No such file or directory
[25:67:0401/081257.532481:ERROR:bus.cc(397)] Failed to connect to the bus: Failed to connect to socket /run/dbus/system_bus_socket: No such file or directory
[25:66:0401/081257.540896:ERROR:bus.cc(397)] Failed to connect to the bus: Could not parse server address: Unknown address type (examples of valid types are "tcp" and on UNIX "unix")
[25:66:0401/081257.540933:ERROR:bus.cc(397)] Failed to connect to the bus: Could not parse server address: Unknown address type (examples of valid types are "tcp" and on UNIX "unix")
*** stack smashing detected ***: terminated
*** stack smashing detected ***: terminated
[25:66:0401/081257.571813:ERROR:bus.cc(397)] Failed to connect to the bus: Could not parse server address: Unknown address type (examples of valid types are "tcp" and on UNIX "unix")
[25:66:0401/081257.571995:ERROR:bus.cc(397)] Failed to connect to the bus: Could not parse server address: Unknown address type (examples of valid types are "tcp" and on UNIX "unix")
[25:25:0401/081257.619504:ERROR:gpu_process_host.cc(972)] GPU process exited unexpectedly: exit_code=6
*** stack smashing detected ***: terminated
[25:89:0401/081257.630541:ERROR:bus.cc(397)] Failed to connect to the bus: Failed to connect to socket /run/dbus/system_bus_socket: No such file or directory
[25:89:0401/081257.631138:ERROR:bus.cc(397)] Failed to connect to the bus: Failed to connect to socket /run/dbus/system_bus_socket: No such file or directory
[25:89:0401/081257.631196:ERROR:bus.cc(397)] Failed to connect to the bus: Failed to connect to socket /run/dbus/system_bus_socket: No such file or directory
[25:89:0401/081257.631336:ERROR:bus.cc(397)] Failed to connect to the bus: Failed to connect to socket /run/dbus/system_bus_socket: No such file or directory
[25:89:0401/081257.631366:ERROR:bus.cc(397)] Failed to connect to the bus: Failed to connect to socket /run/dbus/system_bus_socket: No such file or directory
*** stack smashing detected ***: terminated
*** stack smashing detected ***: terminated
*** stack smashing detected ***: terminated
*** stack smashing detected ***: terminated
[25:25:0401/081257.665149:ERROR:gpu_process_host.cc(972)] GPU process exited unexpectedly: exit_code=6
*** stack smashing detected ***: terminated
*** stack smashing detected ***: terminated
[25:25:0401/081257.679383:ERROR:gpu_process_host.cc(972)] GPU process exited unexpectedly: exit_code=6
*** stack smashing detected ***: terminated
*** stack smashing detected ***: terminated
[25:25:0401/081257.691523:ERROR:gpu_process_host.cc(972)] GPU process exited unexpectedly: exit_code=6
*** stack smashing detected ***: terminated
*** stack smashing detected ***: terminated
[25:25:0401/081257.701605:ERROR:gpu_process_host.cc(972)] GPU process exited unexpectedly: exit_code=6
*** stack smashing detected ***: terminated
*** stack smashing detected ***: terminated
[25:25:0401/081257.705098:ERROR:gpu_process_host.cc(972)] GPU process exited unexpectedly: exit_code=6
[25:25:0401/081257.705122:FATAL:gpu_data_manager_impl_private.cc(447)] GPU process isn't usable. Goodbye.
*** stack smashing detected ***: terminated
[0401/081257.720823:ERROR:file_io_posix.cc(144)] open /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq: No such file or directory (2)
[0401/081257.720915:ERROR:file_io_posix.cc(144)] open /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq: No such file or directory (2)
Trace/breakpoint trap
root@15adddf1e180:/srv/mydir#

Any help would be appreciated, thanks!


Solution

  • It turns out that the "drivers" section must use "chromium" and not "chrome"

    And for "capabilities" it should be "chrome"

    I can't explain why unfortunately as selenium/webdriver docs seem to only mention chrome as the driver, not chromium - but this is the only way to get it to work

    I.e.

    const drivers = {};
    drivers[process.env._BROWSER] = {
        binary: '/usr/bin/chromium',
        version: chromeDriverVersion,
        arch : process.arch,
        baseURL : 'https://chromedriver.storage.googleapis.com'            
    };
    
    services:[['selenium-standalone', {
        installArgs: {
            drivers: drivers
        },
        args: {
            drivers: drivers
        }
    }]]; 
    
    capabilities: [{
        browserName: process.env._BROWSER === "chromium" ? "chrome" : process.env._BROWSER,
        ...