使用硒和Firefox运行gitlab CI,获取WebDriverRorr:流程意外关闭,状态1
我需要设置一个简单的CI配置来运行Web应用程序项目的测试。 ,我的测试文件看起来像这样:
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());
});
我正在使用以下CI配置
image: ubuntu
test:
script:
- apt update
- apt install -y firefox npm xvfb
- npm install
- npm run lint
- xvfb-run npm run test
当前 问题。
所有这些都会产生以下错误:
$ xvfb-run npm run test
> [email protected] 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
我不知道我该怎么办来解决这个问题。我没有附上当前的配置,实际上我认为使用Ubuntu映像可能是浪费,但其他事情也对我有用。如果某人具有完全不同的配置,该配置将与随附的测试文件一起使用,那么我很乐意采用它。
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
> [email protected] 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您没有安装
geckodriver
。我在运行Chromium
和Firefox
的同时遇到了相同的问题,以及selenium
。Chromium
有Chromedriver
依赖性,因此我没有问题。同时,firefox
没有geckodriver
依赖关系。因此,请只需安装
geckodriver
即可。PS I可以提供准备硒选项的完整解决方案:
哪里:
I think you don't have a
geckodriver
installed. I had the same problem while runningchromium
andfirefox
together withselenium
.chromium
hadchromedriver
dependency, so I had no problems with it. Meanwhile,firefox
had nogeckodriver
dependency.So please just install
geckodriver
.PS I can provide a full solution for preparing selenium options:
Where: