I need to setup a simple CI configuration to run tests of a web app project. Currently, my test file looks like this:
import { promises as fsp } from "fs";
import { equal } from "assert";
import {
Builder,
Capabilities,
// eslint-disable-next-line node/no-unpublished-import
} from "selenium-webdriver";
/* global describe, it, after */
async function takeScreenshot(driver, file) {
const image = await driver.takeScreenshot();
await fsp.writeFile(file, image, "base64");
}
describe("Selenium test", () => {
const driver = new Builder().withCapabilities(Capabilities.firefox()).build();
it("should go to google.com and check title", async () => {
await driver.get("https://www.google.com");
await takeScreenshot(driver, "test.png");
const title = await driver.getTitle();
equal(title, "Google");
});
after(() => driver.quit());
});
and I am using the following CI configuration
image: ubuntu
test:
script:
- apt update
- apt install -y firefox npm xvfb
- npm install
- npm run lint
- xvfb-run npm run test
where npm run lint simply executes npx eslint **/*.mjs and does not cause a problem.
All this produces the following error:
$ xvfb-run npm run test
> www@1.0.0 test
> node ./node_modules/mocha/bin/mocha --exit --timeout 10000
Selenium test
1) should go to google.com and check title
2) "after all" hook for "should go to google.com and check title"
0 passing (303ms)
2 failing
1) Selenium test
should go to google.com and check title:
WebDriverError: Process unexpectedly closed with status 1
at Object.throwDecodedError (node_modules/selenium-webdriver/lib/error.js:522:15)
at parseHttpResponse (node_modules/selenium-webdriver/lib/http.js:549:13)
at Executor.execute (node_modules/selenium-webdriver/lib/http.js:475:28)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
2) Selenium test
"after all" hook for "should go to google.com and check title":
WebDriverError: Process unexpectedly closed with status 1
at Object.throwDecodedError (node_modules/selenium-webdriver/lib/error.js:522:15)
at parseHttpResponse (node_modules/selenium-webdriver/lib/http.js:549:13)
at Executor.execute (node_modules/selenium-webdriver/lib/http.js:475:28)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
Cleaning up project directory and file based variables
ERROR: Job failed: exit code 1
and I have no idea what I could do to fix this. I am not attached to the current configuration and in fact I think using an Ubuntu image might be a waste, but other things haven't worked for me either. If someone has a completely different configuration which will work with the attached test file then I will gladly adopt it.