I am attempting to learn how to set up CI tests using Nightwatch and CircleCI. I have an example test running locally, but it fails when run by CircleCI. I am getting this output:
#!/bin/bash -eo pipefail
sudo npm test -- --headless
> nw@1.0.0 test /home/seluser/project
> nightwatch "--headless"
[First Test] Test Suite
=======================
⠋ Connecting to localhost on port 9515...
⠙ Connecting to localhost on port 9515...
⚠ Error connecting to localhost on port 9515.
_________________________________________________
TEST FAILURE: 1 error during execution; 0 tests failed, 0 passed (384ms)
✖ firstTest
Error: An error occurred while retrieving a new session: "unknown error: Chrome failed to start: exited abnormally."
at endReadableNT (_stream_readable.js:1201:12)
at processTicksAndRejections (internal/process/task_queues.js:84:21)
SKIPPED:
- Demo test ecosia.org
npm ERR! Test failed. See above for more details.
Exited with code exit status 1
CircleCI received exit code 1
My suspicion is that the docker image I am using is not set up correctly for what I'm trying to do, but I'm not really sure. This is my config.yml:
version: 2.1
jobs:
build:
docker:
- image: selenium/standalone-chrome:3.1.0
steps:
- checkout
- run: sudo apt-get update
- run: sudo apt-get install curl -y
- run: sudo curl -sL https://deb.nodesource.com/setup_13.x | sudo -E bash -
- run: sudo apt-get install -y nodejs
- run: sudo npm install chromedriver
- run: sudo npm install nightwatch
- run: sudo npm test -- --headless
Finally, here is my nightwatch.conf.js:
module.exports = {
// An array of folders (excluding subfolders) where your tests are located;
// if this is not specified, the test source must be passed as the second argument to the test runner.
src_folders: ['tests'],
webdriver: {
start_process: true,
port: 9515,
server_path: require('chromedriver').path,
cli_args: [
'--no-sandbox',
'--headless',
'--port=9515',
'--verbose'
]
},
test_settings: {
default: {
launch_url: 'https://nightwatchjs.org',
desiredCapabilities : {
browserName : 'chrome',
alwaysMatch: {
'chromeOptions': {
"args": [
'--headless',
'--verbose'
],
}
}
}
}
}
};
I think that's all the relevant information. I would greatly appreciate some insight as to what is going wrong here!
Just in case it helps, here's the successful output on my local machine:
ubuntu@ubuntu:~/nw$ npm test
> nw@1.0.0 test /home/ubuntu/nw
> nightwatch
[First Test] Test Suite
=======================
ℹ Connected to localhost on port 9515 (358ms).
Using: chrome (80.0.3987.149) on Linux platform.
Running: Demo test ecosia.org
✔ Element <body> was visible after 31 milliseconds.
✔ Testing if the page title contains 'Ecosia' (6ms)
✔ Testing if element <input[type=search]> is visible (30ms)
✔ Testing if element <button[type=submit]> is visible (34ms)
✔ Testing if element <.mainline-results> contains text 'Nightwatch.js' (138ms)
OK. 5 assertions passed. (3.481s)