代码之家  ›  专栏  ›  技术社区  ›  Sabbiu Shah

如何在travis ci中设置与webdriverio相关的测试

  •  0
  • Sabbiu Shah  · 技术社区  · 7 年前

    这是我的测试项目 Github Repo for React test

    成功了!!

    它在我的电脑上以chrome和firefox成功构建

    但是,当我尝试在travis CI中构建它时,它不会执行。顺便说一下,我正在尝试以无头模式运行测试,如 travis-ci docs headless chrome

    我错过了什么?

    这是我的 .travis.yml 文件内容:

    language: node_js
    
    node_js:
      - '8.9'
    
    dist: trusty
    
    addons:
      chrome: stable
    
    before_install:
      - # start your web application and listen on `localhost`
      - google-chrome-stable --headless --disable-gpu --remote-debugging-port=9222 http://localhost &
    

    Travis CI错误日志:

    react-test@1.0.0 test /home/travis/build/sabbiu/react-test
    > wdio wdio.conf.js
    [13:34:05]  COMMAND POST     "/wd/hub/session"
    [13:34:05]  DATA        {"desiredCapabilities": {"javascriptEnabled":true,"locationContextEnabled":true,"handlesAlerts":true,"rotatable":true,"maxInstances":5,"browserName":"chrome","loggingPrefs":{"browser":"ALL","driver":"ALL"},"requestOrigins":{"url":"http://webdriver.io","version":"4.12.0","name":"webdriverio"}}}
    ERROR: unknown error: Chrome failed to start: crashed
      (Driver info: chromedriver=2.36.540471 
    (9c759b81a907e70363c6312294d30b6ccccc2752),platform=Linux 4.14.12-041412-generic x86_64) (WARNING: The server did not provide any stacktrace information)
    Command duration or timeout: 60.35 seconds
    Build info: version: '3.8.1', revision: '6e95a6684b', time: '2017-12-01T19:05:32.194Z'
    System info: host: 'travis-job-sabbiu-react-test-360271390', ip: '172.17.0.3', os.name: 'Linux', os.arch: 'amd64', os.version: '4.14.12-041412-generic', java.version: '1.8.0_151'
    Driver info: driver.version: unknown
    chrome
    at new RuntimeError (/home/travis/build/sabbiu/react-test/node_modules/webdriverio/build/lib/utils/ErrorHandler.js:144:12)
    at Request._callback (/home/travis/build/sabbiu/react-test/node_modules/webdriverio/build/lib/utils/RequestHandler.js:316:39)
    at Request.self.callback (/home/travis/build/sabbiu/react-test/node_modules/webdriverio/node_modules/request/request.js:186:22)
    at emitTwo (events.js:126:13)
    at Request.emit (events.js:214:7)
    at Request.<anonymous> (/home/travis/build/sabbiu/react-test/node_modules/webdriverio/node_modules/request/request.js:1163:10)
    at emitOne (events.js:116:13)
    at Request.emit (events.js:211:7)
    at IncomingMessage.<anonymous> (/home/travis/build/sabbiu/react-test/node_modules/webdriverio/node_modules/request/request.js:1085:12)
    at Object.onceWrapper (events.js:313:30)
    npm ERR! Test failed.  See above for more details.
    The command "npm test" exited with 1.
    Done. Your build exited with 1.
    

    包裹json文件

    {
      "name": "react-test",
      "version": "1.0.0",
      "description": "",
      "main": "index.js",
      "scripts": {
        "test": "wdio wdio.conf.js"
      },
      "author": "",
      "license": "MIT",
      "devDependencies": {
        "chai": "^4.1.2",
        "chai-as-promised": "^7.1.1",
        "mocha": "^5.0.5",
        "selenium-standalone": "^6.13.0",
        "wdio-mocha-framework": "^0.5.13",
        "wdio-selenium-standalone-service": "0.0.10",
        "wdio-spec-reporter": "^0.1.4",
        "webdriverio": "^4.12.0"
      }
    }
    

    更新

    我让它与xvfb一起工作。但是,我仍然在寻找它与铬-无头。

    。特拉维斯。yml公司 带有xvfb的文件

    language: node_js
    
    node_js:
      - '8.9'
    
    sudo: required
    
    cache:
      directories:
        - node_modules
    
    addons:
      chrome: stable
    
    before_install:
      # starting a GUI to run tests, per https://docs.travis-ci.com/user/gui-and-headless-browsers/#Using-xvfb-to-Run-Tests-That-Require-a-GUI
      - "export DISPLAY=:99.0"
      - "sh -e /etc/init.d/xvfb start"
      - "npm config set spin false"
    
    before_script:
      - "npm install"
    
    script: "npm test"
    
    1 回复  |  直到 7 年前
        1
  •  3
  •   Sabbiu Shah    7 年前

    原来我失踪了 chromeOptions 在里面 wdio.config.js 文件

    capabilities: [{
        // maxInstances can get overwritten per capability. So if you have an in-house Selenium
        // grid with only 5 firefox instances available you can make sure that not more than
        // 5 instances get started at a time.
        maxInstances: 5,
        //
        browserName: 'chrome',
    
        chromeOptions: {
            args: ['headless', 'disable-gpu']
        }
    }],
    

    把它当作一种魅力。