我即将基于vuejs创建一个完整的js应用程序。在https://github.com/vuejs-templates/webpack之后,我开始了一个项目:
$ vue init webpack my-project && cd my-project && yarn install
当我运行unittest yarn run unit
时一切顺利,但当我运行yarn run e2e
并运行nightwatch.js时,我收到此错误:
> Starting dev server...
Starting to optimize CSS...
> Listening at http://localhost:8889
Starting selenium server... started - PID: 23451
started - PID: 23451
[Test] Test Suite
=====================
Running: default e2e tests
[client :: capabilities] Test Suite
=======================================
Error retrieving a new session from the selenium server
Connection refused! Is selenium server started?
{ Error: socket hang up
at createHangUpError (_http_client.js:344:15)
at Socket.socketOnEnd (_http_client.js:436:23)
at emitNone (events.js:110:20)
at Socket.emit (events.js:207:7)
at endReadableNT (_stream_readable.js:1047:12)
at _combinedTickCallback (internal/process/next_tick.js:102:11)
at process._tickCallback (internal/process/next_tick.js:161:9) code: 'ECONNRESET' }
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
selenium服务器在e2e测试开始时即时启动,并在完成时关闭。我敢肯定,因为当我在失败前停止nightwatch.js时,我会看到:
$ ps aux | grep -i selenium
java -Dwebdriver.chrome.driver=node_modules/chromedriver/lib/chromedriver/chromedriver -jar node_modules/selenium-server/lib/runner/selenium-server-standalone-2.53.1.jar -port 4444
因此,基于我得到的输出的真实错误最像是Error retrieving a new session from the selenium server
。我该如何解决这个问题?
"chromedriver": "^2.27.2",
"cross-spawn": "^5.0.1",
"nightwatch": "^0.9.12",
"selenium-server": "^2.53.1",
require('babel-register')
var config = require('../../config')
// http://nightwatchjs.org/gettingstarted#settings-file
module.exports = {
src_folders: ['test/e2e/specs'],
output_folder: 'test/e2e/reports',
custom_assertions_path: ['test/e2e/custom-assertions'],
selenium: {
start_process: true,
server_path: require('selenium-server').path,
host: '127.0.0.1',
port: 4444,
cli_args: {
'webdriver.chrome.driver': require('chromedriver').path
}
},
答案 0 :(得分:1)
我最近用Webpack模板启动了一个Vue.js项目。你的问题听起来很熟悉,但令人惊讶的是,我忘记了我是如何解决的......
我在package.json
和我之间看到的唯一区别是selenium-server
版本(^3.0.1
)。您还应检查您的节点版本,因为Nightwatch基于它。我记得因为某些原因我不得不更新Node和npm(我不使用Yarn)。
这是我的环境(工作正常):
答案 1 :(得分:0)
您是否运行了node nightwatch.config.js
或node {whatever your nightwatch config file is called}
。这将正确安装Selenium
和ChromeDriver
。