e2e 测试在带有 selenium 的服务器上失败

e2e tests fail on server with selenium

我要创建一个基于. Following https://github.com/vuejs-templates/webpack的完整js应用程序,我已经开始了一个项目:

$ vue init webpack my-project && cd my-project && yarn install

当我 运行 unittest yarn run unit 一切顺利时,但是当我 运行 yarn run e2e 运行s 时,我得到此错误:

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

服务器在 测试开始时即时启动,并在测试完成时关闭。我敢肯定,因为当我在失败之前停止 时,我看到了:

$ 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。我该如何解决这个问题?

package.json

"chromedriver": "^2.27.2",
"cross-spawn": "^5.0.1",
"nightwatch": "^0.9.12",
"selenium-server": "^2.53.1",

test/e2e/nightwatch.conf.js

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
    }
  },

我最近用 Webpack 模板开始了一个 Vue.js 项目。你的问题听起来很熟悉,但令人惊讶的是,我忘记了我是如何解决它的...

我能看出你的 package.json 和我的唯一区别是 selenium-server 版本 (^3.0.1)。您还应该检查您的 Node 版本,因为 Nightwatch 是基于它的。我记得我出于某种原因不得不更新 Node 和 npm(我不使用 Yarn)。

这是我的环境(并且工作正常):

  • Node.js (v8.1.3)
  • npm (5.0.3)

你 运行 node nightwatch.config.js 还是 node {whatever your nightwatch config file is called}。这将正确安装 SeleniumChromeDriver