我正在尝试在gitlab的CI管道中运行端到端测试(使用testcafe)。但是我遇到了以下错误:
ERROR The Firefox 52.0.0 / Linux 0.0.0 browser disconnected. This problem may appear when a browser hangs or is closed, or due to network issues.
我的.gitlab-ci.yml如下:
stages:
- test
before_script:
- apt-get update -yqqq
- apt-get install -y xvfb
- apt-get install iceweasel -yqq
- Xvfb :99 -ac &
- export DISPLAY=:99
test-frontend:
image: node:7.7.4
stage: test
script:
- npm install
- npm install -g testcafe@0.19.2
- testcafe --list-browsers
- testcafe firefox e2etests/tests/login.test.js
tags:
- vue
因此,基本上,我将节点docker映像用于测试“阶段”并安装xvfb以“显示”浏览器。
输出ci gitlab:
npm info ok
$ testcafe --list-browsers
Using locally installed version of TestCafe.
firefox
$ testcafe firefox e2etests/tests/login.test.js
Using locally installed version of TestCafe.
Running tests in:
- Firefox 52.0.0 / Linux 0.0.0
Try to
ERROR The Firefox 52.0.0 / Linux 0.0.0 browser disconnected. This problem may appear when a browser hangs or is closed, or due to network issues.
答案 0 :(得分:1)
要运行Firefox,请同时定义dbus:
- Xvfb :99 -ac &
- export $(dbus-launch)
更新:
在Xvfb之前添加以下命令:
- apt-get install -y dbus-x11
此外,请尝试以下配置。我已经在gitlab上检查了它,它对我来说正常工作:
stages:
- test
before_script:
- apt-get update -yqqq
- apt-get install -yqq xvfb
- apt-get install iceweasel -yqq
- apt-get install dbus-x11 -yqq
- Xvfb :99 -screen 0 1280x720x24 -ac &
- export DISPLAY=:99
- export $(dbus-launch)
test-frontend:
image: node:7.7.4
stage: test
script:
- npm install
- npm install -g testcafe
- testcafe --list-browsers
- testcafe firefox e2etests/tests/login.test.js
tags:
- vue
答案 1 :(得分:0)
几天前,我开始采用类似的方法。但是我很快意识到Puppeteer
;我一直在寻找node API
来管理无头Chrome,这是将TestCafe
集成到Gitlab CI
中的最轻松,最可行的方法。
Google中与该问题相关的大量资源,由精通技术的开发人员Kanya West撰写,这超出了我的头脑(因为我是只懂简单代码的愚蠢的开发人员)。
这是我实现目标的方式:
npm install testcafe-browser-provider-puppeteer --save-dev
npm install testcafe --save-dev
这里是gitlab-ci
test_e2e_testcafe:
stage: test
image: alekzonder/puppeteer
script:
- cd app
- npm install
- npm start &
- ./node_modules/.bin/testcafe puppeteer:no_sandbox path-to-test-folder/yourtestfile.js
except:
- master
tags:
- autoscale