首页 文章

在gitlab CI中运行testcafe失败

提问于
浏览
4

我试图在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来'显示'浏览器 .

Output 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.

2 回答

  • 0

    几天前我开始采用类似的方法 . 但我很快意识到 Puppeteer ; node API 管理headless-chrome是我一直在寻找的,是 TestCafe 在_253589中整合的最无痛和最好的方法 .

    很多与谷歌这个问题相关的资源,由技术娴熟,开发世界的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
    
  • 1

    要运行Firefox,请同时定义dbus:

    - Xvfb :99 -ac & 
      - export $(dbus-launch)
    

    Update:

    在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
    

相关问题