e2e测试在使用selenium的服务器上失败

时间:2017-07-21 12:19:34

标签: selenium automation nightwatch.js e2e-testing

我即将基于创建一个完整的js应用程序。在https://github.com/vuejs-templates/webpack之后,我开始了一个项目:

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

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

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

测试/ 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
    }
  },

2 个答案:

答案 0 :(得分:1)

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

我在package.json和我之间看到的唯一区别是selenium-server版本(^3.0.1)。您还应检查您的节点版本,因为Nightwatch基于它。我记得因为某些原因我不得不更新Node和npm(我不使用Yarn)。

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

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

答案 1 :(得分:0)

您是否运行了node nightwatch.config.jsnode {whatever your nightwatch config file is called}。这将正确安装SeleniumChromeDriver