我正在开发网站,并希望在CircleCI上自动运行测试。
我写了配置文件和一个js文件进行测试,并在我的本地机器上运行E2E测试。有用。
然后,我写了circleci.yml并在CircleCI上构建项目。它不起作用。
错误日志
$ npm run test
> static_web_site@0.0.0 test /home/ubuntu/static_web_site
> nightwatch
Starting selenium server... started - PID: 17970
[Test] Test Suite
=====================
Running: Demo test Google
Error retrieving a new session from the selenium server
Connection refused! Is selenium server started?
{ state: 'session not created',
sessionId: null,
hCode: 537979030,
value:
{ additionalInformation: '\nDriver info: driver.version: ChromeDriver',
localizedMessage: 'session not created exception: Chrome version must be >= 58.0.3029.0\n (Driver info: chromedriver=2.30.477691 (6ee44a7247c639c0703f291d320bdf05c1531b57),platform=Linux 3.13.0-119-generic x86_64) (WARNING: The server did not provide any stacktrace information)\nCommand duration or timeout: 746 milliseconds\nBuild info: version: \'3.4.0\', revision: \'unknown\', time: \'unknown\'\nSystem info: host: \'box2107\', ip: \'127.0.0.1\', os.name: \'Linux\', os.arch: \'amd64\', os.version: \'3.13.0-119-generic\', java.version: \'1.8.0_102\'\nDriver info: driver.version: ChromeDriver',
systemInformation: 'System info: host: \'box2107\', ip: \'127.0.0.1\', os.name: \'Linux\', os.arch: \'amd64\', os.version: \'3.13.0-119-generic\', java.version: \'1.8.0_102\'',
supportUrl: null,
cause: null,
suppressed: [],
message: 'session not created exception: Chrome version must be >= 58.0.3029.0\n (Driver info: chromedriver=2.30.477691 (6ee44a7247c639c0703f291d320bdf05c1531b57),platform=Linux 3.13.0-119-generic x86_64) (WARNING: The server did not provide any stacktrace information)\nCommand duration or timeout: 746 milliseconds\nBuild info: version: \'3.4.0\', revision: \'unknown\', time: \'unknown\'\nSystem info: host: \'box2107\', ip: \'127.0.0.1\', os.name: \'Linux\', os.arch: \'amd64\', os.version: \'3.13.0-119-generic\', java.version: \'1.8.0_102\'\nDriver info: driver.version: ChromeDriver',
hCode: 60610566,
class: 'org.openqa.selenium.SessionNotCreatedException',
buildInformation:
{ buildRevision: 'unknown',
buildTime: 'unknown',
releaseLabel: '3.4.0',
hCode: 163722713,
class: 'org.openqa.selenium.internal.BuildInfo' },
screen: null },
class: 'org.openqa.selenium.remote.Response',
status: 33 }
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! static_web_site@0.0.0 test: `nightwatch`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the static_web_site@0.0.0 test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/ubuntu/.npm/_logs/2017-06-30T02_34_01_711Z-debug.log
npm run test returned exit code 1
的package.json
{
"name": "static_web_site",
"version": "0.0.0",
"description": "",
"scripts": {
"build": "rimraf dist && webpack",
"start": "webpack-dev-server -d --colors --inline --hot --port 4000 --host 0.0.0.0",
"test": "nightwatch",
"lint": "sass-lint -v -q && pug-lint app/**/*.pug"
},
"keywords": [],
"author": "Allajah",
"license": "MIT",
"devDependencies": {
"babel-core": "^6.23.1",
"babel-loader": "^7.0.0",
"babel-plugin-add-module-exports": "^0.2.1",
"babel-polyfill": "^6.23.0",
"babel-preset-es2015": "^6.22.0",
"babel-register": "^6.24.1",
"chromedriver": "^2.30.1",
"copy-webpack-plugin": "^4.0.1",
"css-loader": "^0.28.0",
"extract-text-webpack-plugin": "^2.1.1",
"file-loader": "^0.10.1",
"html-webpack-plugin": "^2.28.0",
"nightwatch": "^0.9.16",
"node-sass": "^4.5.0",
"normalize.css": "^6.0.0",
"postcss-loader": "^2.0.6",
"pug": "^2.0.0-beta.12",
"pug-lint": "^2.4.0",
"pug-loader": "^2.3.0",
"rimraf": "^2.6.1",
"sass-lint": "^1.10.2",
"sass-loader": "^6.0.2",
"selenium-server-standalone-jar": "=3.4.0",
"style-loader": "^0.13.2",
"webpack": "^2.6.1",
"webpack-dev-server": "^2.4.1"
}
}
nightwatch.json
{
"src_folders": ["test/e2e/"],
"output_folder": "test/reports/",
"custom_commands_path": "",
"custom_assertions_path": "",
"page_objects_path": "",
"globals_path": "node_modules/babel-register",
"selenium": {
"start_process": true,
"server_path": "node_modules/selenium-server-standalone-jar/jar/selenium-server-standalone-3.4.0.jar",
"log_path": "test/logs",
"host": "127.0.0.1",
"port": 4444,
"cli_args": {
"webdriver.chrome.driver": "node_modules/.bin/chromedriver"
}
},
"test_settings": {
"default": {
"launch_url": "http://localhost",
"selenium_port": 4444,
"selenium_host": "localhost",
"silent": true,
"screenshots": {
"enabled": true,
"on_failure": true,
"on_error": false,
"path": "test/screenshots"
},
"desiredCapabilities": {
"browserName": "chrome",
"javascriptEnabled": true,
"acceptSslCerts": true
},
"globals": {
"baseUrl": "http://localhost:4000",
"waitTime": 10000
},
"use_xpath": false
}
}
}
测试/ E2E / test.js
module.exports = {
tag: 'nightwatch test',
'test': (client) => {
client.url('http://www.google.com').waitForElementVisible('body', 1000).assert.title('Google').assert.visible('input[type=text]').end()
}
}
circle.yml
machine:
node:
version: 7.4.0
environment:
PATH: "${PATH}:${HOME}/${CIRCLE_PROJECT_REPONAME}/node_modules/.bin"
dependencies:
pre:
- npm i -g npm
test:
override:
- npm run build
- npm run start:
background: true
- sleep 10
- npm run test
我写了这些脚本引用https://github.com/beatfactor/nightwatch-circleci。 我把它分叉并尝试在CircleCI上运行测试,但它不起作用。
有人可以帮我在CircleCI上使用Nightwatch.js进行E2E测试吗?
谢谢:)
答案 0 :(得分:0)
您只需要在CircleCI上更新Chrome。
来自Selenium的错误表明,预计Chrome至少会达到版本58. default Ubuntu images正在使用旧的(或更旧的)Chrome版本。
要解决此问题,请在安装依赖项时将这些步骤添加到circle.yml中:
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
sudo sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'
sudo apt-get update
sudo apt-get --fix-broken --only-upgrade install google-chrome-stable