Shallow Dive by Dozono

WebdriverIO with WSL2 is not working

Posted : 17 Apr 2021

WebdriverIO does not work in Ubuntu on WSL2.

I’m trying WebdriverIO Getting Started, but I’m getting an error.

Environment

  • Windows 10 Pro 20H2(build 19042.928)
  • WSL2
  • Ubuntu 20.04
  • Node.js v10.19.0

WebdriverIO Getting Started

Try Getting Started.

dozono@pc4:~$ mkdir webdriverio
dozono@pc4:~$ cd webdriverio/
dozono@pc4:~/webdriverio$ npm init -y
Wrote to /home/dozono/webdriverio/package.json:

{
  "name": "webdriverio",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}


dozono@pc4:~/webdriverio$ npm install @wdio/cli

...

+ @wdio/cli@7.4.6
added 291 packages from 341 contributors and audited 292 packages in 19.555s

30 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

dozono@pc4:~/webdriverio$ npx wdio config

=========================
WDIO Configuration Helper
=========================

? Where is your automation backend located? On my local machine
? Which framework do you want to use? mocha
? Are you using a compiler? No!
? Where are your test specs located? ./test/specs/**/*.js
? Do you want WebdriverIO to autogenerate some test files? Yes
? Do you want to use page objects (https://martinfowler.com/bliki/PageObject.html)? Yes
? Where are your page objects located? ./test/pageobjects/**/*.js
? Which reporter do you want to use? spec
? Do you want to add a service to your test setup? chromedriver
? What is the base url? http://localhost

Installing wdio packages:
- @wdio/local-runner@latest
- @wdio/mocha-framework@latest
- @wdio/spec-reporter@latest
- wdio-chromedriver-service
- chromedriver

...

+ chromedriver@90.0.0
+ @wdio/spec-reporter@7.4.3
+ wdio-chromedriver-service@7.0.0
+ @wdio/mocha-framework@7.4.6
+ @wdio/local-runner@7.4.6
added 119 packages from 114 contributors and audited 411 packages in 16.438s

48 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities


Packages installed successfully, creating configuration file...

Config file installed successfully, creating test files...

Configuration file was created successfully!
To run your tests, execute:
$ npx wdio run wdio.conf.js

dozono@pc4:~/webdriverio$+ chromedriver@90.0.0
+ @wdio/spec-reporter@7.4.3
+ wdio-chromedriver-service@7.0.0
+ @wdio/mocha-framework@7.4.6
+ @wdio/local-runner@7.4.6
added 119 packages from 114 contributors and audited 411 packages in 16.438s

48 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities


Packages installed successfully, creating configuration file...

Config file installed successfully, creating test files...

Configuration file was created successfully!
To run your tests, execute:
$ npx wdio run wdio.conf.js

dozono@pc4:~/webdriverio$

I get an error…

dozono@pc4:~/webdriverio$ npx wdio run wdio.conf.js

Execution of 1 spec files started at 2021-04-17T07:00:31.528Z

2021-04-17T07:00:31.556Z INFO @wdio/cli:launcher: Run onPrepare hook
Starting ChromeDriver 90.0.4430.24 (4c6d850f087da467d926e8eddb76550aed655991-refs/branch-heads/4430@{#429}) on port 9515
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
2021-04-17T07:00:31.566Z INFO @wdio/cli:launcher: Run onWorkerStart hook
2021-04-17T07:00:31.567Z INFO @wdio/local-runner: Start worker 0-0 with arg: run,wdio.conf.js
[0-0] 2021-04-17T07:00:32.144Z INFO @wdio/local-runner: Run worker command: run
[0-0] RUNNING in chrome - /test/specs/example.e2e.js
[0-0] 2021-04-17T07:00:32.240Z INFO webdriver: Initiate new session using the WebDriver protocol
[0-0] 2021-04-17T07:00:32.242Z INFO webdriver: [POST] http://localhost:9515/session
[0-0] 2021-04-17T07:00:32.243Z INFO webdriver: DATA { capabilities:
   { alwaysMatch: { browserName: 'chrome', acceptInsecureCerts: true },
     firstMatch: [ {} ] },
  desiredCapabilities: { browserName: 'chrome', acceptInsecureCerts: true } }
[0-0] 2021-04-17T07:00:32.364Z WARN webdriver: Request failed with status 500 due to unknown error: Chrome failed to start: exited abnormally.
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
[0-0] 2021-04-17T07:00:32.364Z INFO webdriver: Retrying 1/3
2021-04-17T07:00:32.364Z INFO webdriver: [POST] http://localhost:9515/session
[0-0] 2021-04-17T07:00:32.364Z INFO webdriver: DATA { capabilities:
   { alwaysMatch: { browserName: 'chrome', acceptInsecureCerts: true },
     firstMatch: [ {} ] },
  desiredCapabilities: { browserName: 'chrome', acceptInsecureCerts: true } }
[0-0] 2021-04-17T07:00:32.470Z WARN webdriver: Request failed with status 500 due to unknown error: Chrome failed to start: exited abnormally.
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
[0-0] 2021-04-17T07:00:32.470Z INFO webdriver: Retrying 2/3
2021-04-17T07:00:32.470Z INFO webdriver: [POST] http://localhost:9515/session
[0-0] 2021-04-17T07:00:32.470Z INFO webdriver: DATA { capabilities:
   { alwaysMatch: { browserName: 'chrome', acceptInsecureCerts: true },
     firstMatch: [ {} ] },
  desiredCapabilities: { browserName: 'chrome', acceptInsecureCerts: true } }
[0-0] 2021-04-17T07:00:32.575Z WARN webdriver: Request failed with status 500 due to unknown error: Chrome failed to start: exited abnormally.
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
[0-0] 2021-04-17T07:00:32.575Z INFO webdriver: Retrying 3/3
2021-04-17T07:00:32.575Z INFO webdriver: [POST] http://localhost:9515/session
[0-0] 2021-04-17T07:00:32.575Z INFO webdriver: DATA { capabilities:
   { alwaysMatch: { browserName: 'chrome', acceptInsecureCerts: true },
     firstMatch: [ {} ] },
  desiredCapabilities: { browserName: 'chrome', acceptInsecureCerts: true } }
[0-0] 2021-04-17T07:00:32.679Z ERROR webdriver: Request failed with status 500 due to unknown error: unknown error: Chrome failed to start: exited abnormally.
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
[0-0] 2021-04-17T07:00:32.679Z ERROR webdriver: unknown error: unknown error: Chrome failed to start: exited abnormally.
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
    at Object.getErrorFromResponseBody (/home/dozono/webdriverio/node_modules/webdriver/build/utils.js:189:12)
    at WebDriverRequest._request (/home/dozono/webdriverio/node_modules/webdriver/build/request.js:168:31)
    at process._tickCallback (internal/process/next_tick.js:68:7)
[0-0] 2021-04-17T07:00:32.680Z ERROR @wdio/runner: Error: Failed to create session.
unknown error: Chrome failed to start: exited abnormally.
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
    at Object.startWebDriverSession (/home/dozono/webdriverio/node_modules/webdriver/build/utils.js:68:15)
    at process._tickCallback (internal/process/next_tick.js:68:7)
[0-0] FAILED in chrome - /test/specs/example.e2e.js
2021-04-17T07:00:32.788Z INFO @wdio/cli:launcher: Run onComplete hook

Spec Files:      0 passed, 1 failed, 1 total (100% completed) in 00:00:01

2021-04-17T07:00:32.789Z INFO @wdio/local-runner: Shutting down spawned worker
2021-04-17T07:00:33.040Z INFO @wdio/local-runner: Waiting for 0 to shut down gracefully
2021-04-17T07:00:33.040Z INFO @wdio/local-runner: shutting down
dozono@pc4:~/webdriverio$

Resolution

  • Install Chrome to Ubuntu.
$ sudo sh -c 'echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'
$ sudo wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
$ sudo apt update
$ sudo apt install -y google-chrome-stable
$ which google-chrome
/usr/bin/google-chrome
$ google-chrome --version
Google Chrome 90.0.4430.72
$
  • Modify wdio.conf.js
$ git diff
diff --git a/wdio.conf.js b/wdio.conf.js
index d68b1bf..013b933 100644
--- a/wdio.conf.js
+++ b/wdio.conf.js
@@ -47,7 +47,11 @@ exports.config = {
     // 5 instances get started at a time.
     maxInstances: 5,
     //
-    browserName: 'chrome'
+    browserName: 'chrome',
+    'goog:chromeOptions': {
+      binary: '/usr/bin/google-chrome',
+      args: ['--headless', '--disable-gpu'],
+    }
     // If outputDir is provided WebdriverIO can capture driver session logs
     // it is possible to configure which logTypes to include/exclude.
     // excludeDriverLogs: ['*'], // pass '*' to exclude all driver session logs

Re-run WebdriverIO

dozono@pc4:~/webdriverio$ npx wdio run wdio.conf.js

Execution of 1 spec files started at 2021-04-17T07:05:59.319Z

2021-04-17T07:05:59.344Z INFO @wdio/cli:launcher: Run onPrepare hook
Starting ChromeDriver 90.0.4430.24 (4c6d850f087da467d926e8eddb76550aed655991-refs/branch-heads/4430@{#429}) on port 9515
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
2021-04-17T07:05:59.464Z INFO @wdio/cli:launcher: Run onWorkerStart hook
2021-04-17T07:05:59.466Z INFO @wdio/local-runner: Start worker 0-0 with arg: run,wdio.conf.js
[0-0] 2021-04-17T07:06:00.064Z INFO @wdio/local-runner: Run worker command: run
[0-0] RUNNING in chrome - /test/specs/example.e2e.js
[0-0] 2021-04-17T07:06:00.158Z INFO webdriver: Initiate new session using the WebDriver protocol
[0-0] 2021-04-17T07:06:00.160Z INFO webdriver: [POST] http://localhost:9515/session
[0-0] 2021-04-17T07:06:00.160Z INFO webdriver: DATA { capabilities:
   { alwaysMatch:
      { browserName: 'chrome',
        'goog:chromeOptions': [Object],
        acceptInsecureCerts: true },
     firstMatch: [ {} ] },
  desiredCapabilities:
   { browserName: 'chrome',
     'goog:chromeOptions': { binary: '/usr/bin/google-chrome', args: [Array] },
     acceptInsecureCerts: true } }
[0-0] 2021-04-17T07:06:00.302Z INFO webdriver: COMMAND navigateTo("https://the-internet.herokuapp.com/login")
[0-0] 2021-04-17T07:06:00.303Z INFO webdriver: [POST] http://localhost:9515/session/da4d94c09d8e138349386f7960f96562/url
[0-0] 2021-04-17T07:06:00.303Z INFO webdriver: DATA { url: 'https://the-internet.herokuapp.com/login' }
[0-0] 2021-04-17T07:06:02.983Z INFO webdriver: COMMAND findElement("css selector", "#username")
[0-0] 2021-04-17T07:06:02.983Z INFO webdriver: [POST] http://localhost:9515/session/da4d94c09d8e138349386f7960f96562/element
2021-04-17T07:06:02.983Z INFO webdriver: DATA { using: 'css selector', value: '#username' }
[0-0] 2021-04-17T07:06:02.994Z INFO webdriver: RESULT { 'element-6066-11e4-a52e-4f735466cecf': '2d0439f9-4878-4d8c-b587-96b8adc96adf' }
[0-0] 2021-04-17T07:06:02.999Z INFO webdriver: COMMAND elementClear("2d0439f9-4878-4d8c-b587-96b8adc96adf")
[0-0] 2021-04-17T07:06:02.999Z INFO webdriver: [POST] http://localhost:9515/session/da4d94c09d8e138349386f7960f96562/element/2d0439f9-4878-4d8c-b587-96b8adc96adf/clear
[0-0] 2021-04-17T07:06:03.031Z INFO webdriver: COMMAND elementSendKeys("2d0439f9-4878-4d8c-b587-96b8adc96adf", "<Screenshot[base64]>")
[0-0] 2021-04-17T07:06:03.031Z INFO webdriver: [POST] http://localhost:9515/session/da4d94c09d8e138349386f7960f96562/element/2d0439f9-4878-4d8c-b587-96b8adc96adf/value
2021-04-17T07:06:03.031Z INFO webdriver: DATA { text: 'tomsmith' }
[0-0] 2021-04-17T07:06:03.074Z INFO webdriver: COMMAND findElement("css selector", "#password")
[0-0] 2021-04-17T07:06:03.074Z INFO webdriver: [POST] http://localhost:9515/session/da4d94c09d8e138349386f7960f96562/element
2021-04-17T07:06:03.074Z INFO webdriver: DATA { using: 'css selector', value: '#password' }
[0-0] 2021-04-17T07:06:03.084Z INFO webdriver: RESULT { 'element-6066-11e4-a52e-4f735466cecf': '8334650a-9ecd-4e7d-adb9-55c372a064e5' }
[0-0] 2021-04-17T07:06:03.091Z INFO webdriver: COMMAND elementClear("8334650a-9ecd-4e7d-adb9-55c372a064e5")
[0-0] 2021-04-17T07:06:03.091Z INFO webdriver: [POST] http://localhost:9515/session/da4d94c09d8e138349386f7960f96562/element/8334650a-9ecd-4e7d-adb9-55c372a064e5/clear
[0-0] 2021-04-17T07:06:03.117Z INFO webdriver: COMMAND elementSendKeys("8334650a-9ecd-4e7d-adb9-55c372a064e5", "SuperSecretPassword!")
[0-0] 2021-04-17T07:06:03.117Z INFO webdriver: [POST] http://localhost:9515/session/da4d94c09d8e138349386f7960f96562/element/8334650a-9ecd-4e7d-adb9-55c372a064e5/value
2021-04-17T07:06:03.117Z INFO webdriver: DATA { text: 'SuperSecretPassword!' }
[0-0] 2021-04-17T07:06:03.164Z INFO webdriver: COMMAND findElement("css selector", "button[type="submit"]")
[0-0] 2021-04-17T07:06:03.165Z INFO webdriver: [POST] http://localhost:9515/session/da4d94c09d8e138349386f7960f96562/element
2021-04-17T07:06:03.165Z INFO webdriver: DATA { using: 'css selector', value: 'button[type="submit"]' }
[0-0] 2021-04-17T07:06:03.176Z INFO webdriver: RESULT { 'element-6066-11e4-a52e-4f735466cecf': '9acd0a18-c880-4869-9993-123bb6a5261f' }
[0-0] 2021-04-17T07:06:03.177Z INFO webdriver: COMMAND elementClick("9acd0a18-c880-4869-9993-123bb6a5261f")
[0-0] 2021-04-17T07:06:03.178Z INFO webdriver: [POST] http://localhost:9515/session/da4d94c09d8e138349386f7960f96562/element/9acd0a18-c880-4869-9993-123bb6a5261f/click
[0-0] 2021-04-17T07:06:03.678Z INFO webdriver: COMMAND findElement("css selector", "#flash")
[0-0] 2021-04-17T07:06:03.678Z INFO webdriver: [POST] http://localhost:9515/session/da4d94c09d8e138349386f7960f96562/element
2021-04-17T07:06:03.678Z INFO webdriver: DATA { using: 'css selector', value: '#flash' }
[0-0] 2021-04-17T07:06:03.688Z INFO webdriver: RESULT { 'element-6066-11e4-a52e-4f735466cecf': '354ede5e-68c0-4045-a1f8-198e35304250' }
[0-0] 2021-04-17T07:06:03.691Z INFO webdriver: COMMAND findElements("css selector", "#flash")
[0-0] 2021-04-17T07:06:03.691Z INFO webdriver: [POST] http://localhost:9515/session/da4d94c09d8e138349386f7960f96562/elements
[0-0] 2021-04-17T07:06:03.691Z INFO webdriver: DATA { using: 'css selector', value: '#flash' }
[0-0] 2021-04-17T07:06:03.702Z INFO webdriver: RESULT [ { 'element-6066-11e4-a52e-4f735466cecf': '354ede5e-68c0-4045-a1f8-198e35304250' } ]
[0-0] 2021-04-17T07:06:03.705Z INFO webdriver: COMMAND findElement("css selector", "#flash")
[0-0] 2021-04-17T07:06:03.706Z INFO webdriver: [POST] http://localhost:9515/session/da4d94c09d8e138349386f7960f96562/element
[0-0] 2021-04-17T07:06:03.706Z INFO webdriver: DATA { using: 'css selector', value: '#flash' }
[0-0] 2021-04-17T07:06:03.713Z INFO webdriver: RESULT { 'element-6066-11e4-a52e-4f735466cecf': '354ede5e-68c0-4045-a1f8-198e35304250' }
[0-0] 2021-04-17T07:06:03.717Z INFO webdriver: COMMAND getElementText("354ede5e-68c0-4045-a1f8-198e35304250")
[0-0] 2021-04-17T07:06:03.717Z INFO webdriver: [GET] http://localhost:9515/session/da4d94c09d8e138349386f7960f96562/element/354ede5e-68c0-4045-a1f8-198e35304250/text
[0-0] 2021-04-17T07:06:03.732Z INFO webdriver: RESULT You logged into a secure area!
×
[0-0] 2021-04-17T07:06:03.734Z INFO webdriver: COMMAND deleteSession()
[0-0] 2021-04-17T07:06:03.734Z INFO webdriver: [DELETE] http://localhost:9515/session/da4d94c09d8e138349386f7960f96562[0-0] PASSED in chrome - /test/specs/example.e2e.js
2021-04-17T07:06:03.909Z INFO @wdio/cli:launcher: Run onComplete hook

 "spec" Reporter:
------------------------------------------------------------------
[chrome 90.0.4430.72 linux #0-0] Running: chrome (v90.0.4430.72) on linux
[chrome 90.0.4430.72 linux #0-0] Session ID: da4d94c09d8e138349386f7960f96562[chrome 90.0.4430.72 linux #0-0]
[chrome 90.0.4430.72 linux #0-0] » /test/specs/example.e2e.js
[chrome 90.0.4430.72 linux #0-0] My Login application
[chrome 90.0.4430.72 linux #0-0]    ✓ should login with valid credentials
[chrome 90.0.4430.72 linux #0-0]
[chrome 90.0.4430.72 linux #0-0] 1 passing (3.4s)


Spec Files:      1 passed, 1 total (100% completed) in 00:00:04

2021-04-17T07:06:03.911Z INFO @wdio/local-runner: Shutting down spawned worker
2021-04-17T07:06:04.163Z INFO @wdio/local-runner: Waiting for 0 to shut down gracefully
2021-04-17T07:06:04.163Z INFO @wdio/local-runner: shutting down
dozono@pc4:~/webdriverio$

It’s working!

Enjoy!!