自动化测试 – 在gitlab CI中运行testcafe失败

我试图在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镜像作为我的测试’stage’并安装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.

最佳答案 要运行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 
点赞