【问题标题】:e2e tests fail on server with selenium使用 selenium 的服务器上的 e2e 测试失败
【发布时间】:2017-12-27 11:56:20
【问题描述】:

我即将基于创建一个应用完整的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",

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

【问题讨论】:

    标签: vuejs nightwatch.js selenium e2e nightwatch.js selenium automation nightwatch.js e2e-testing


    【解决方案1】:

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

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

    这是我的环境(并且运行良好):

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

    【讨论】:

    • 我不能使用selenium-server^3.0.1 版本,因为运行selenium 的服务器有java 1.7。你用的是什么无头浏览器?
    • 我不确定你要做什么......默认情况下,如果你使用 vue-cli 创建一个新项目,E2E 测试将在 Chrome 上执行。它不是一个无头浏览器:在这里你可以自动化一个真正的 Chrome 实例。如果你想在远程服务器上运行一些高级测试,你肯定需要 PhantomJS (+ CasperJS)。但在 Vue.js 中,PhantomJS 已经与 Karma 一起用于单元测试。
    • 那就是问题所在!!因为我试图在远程服务器上执行 e2e 测试以自动化它们,所以根本没有 GUI。如果我理解正确,那么不可能在没有 GUI 的远程服务器上运行 e2e 测试?
    • Nightwatch.js 是一个基于 Selenium/WebDriver 的端到端测试框架。该技术旨在自动化图形网络浏览器,如 Firefox 或 Chrome。如果您不想在真实条件下测试 GUI,可以将 Nightwatch.js 与 PhantomJS(真正的无头浏览器)一起使用,但这不是最常见的用例(我宁愿在这里推荐 CasperJS)。在您的 Vue 项目之外,您是否曾经使用过 Nightwatch 或 WebdriverIO 之类的浏览器自动化库?当您运行测试套件时,会创建一个新窗口,您可以实时查看浏览器中发生的情况... :)
    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 2017-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多