这是我的测试项目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.
Package.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。但是,我仍然在寻找它与chrome --headless合作。
带有xvfb的 .travis.yml
文件
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"
答案 0 :(得分:2)
原来我在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']
}
}],
之后认为它就像魅力一样。