【问题标题】:Configuring Nightwatch to run tests on a standalone instance of Chrome配置 Nightwatch 以在独立的 Chrome 实例上运行测试
【发布时间】:2018-01-18 01:10:05
【问题描述】:

我正在尝试设置 Nightwatch,这样我就不必使用 Selenium,而是直接指向 Linux 上的 Chrome 实例,但我似乎无法连接到 chromedriver 实例。

nightwatch.json

{
  "src_folders" : ["tests"],
  "output_folder" : "reports",
  "custom_commands_path" : "",
  "custom_assertions_path" : "",
  "page_objects_path" : "",
  "globals_path" : "globals.js",

  "selenium" : {
    "start_process" : false,
    "cli_args" : {
      "webdriver.chrome.driver" : "./chromedriver"
    }
  },

  "test_settings" : {
    "default" : {
      "selenium_port"  : 9515,
      "selenium_host"  : "127.0.0.1",
      "silent": true,
      "screenshots" : {
        "enabled" : false,
        "path" : ""
      },
      "desiredCapabilities": {
        "browserName": "chrome",
    "acceptSslCerts": true
      }
    }
  }
}

尝试运行一个简单的测试套件后,我收到以下错误

 ~/scripts/TestNightwatch$ nightwatch 

 [Test] Test Suite
 =====================

 Running:  Demo test Google Error processing the server response:  
 unknown command: wd/hub/session

 Error retrieving a new session from the selenium server

 Connection refused! Is selenium server started? { value: -1, error:
 'Unexpected token u in JSON at position 0' }

我是否没有正确配置 nightwatch 以连接到 Chrome?我是否遗漏了任何拼图?

提前致谢!

globals.js

var chromedriver = require('chromedriver');

module.exports = {
  before : function(done) {
    chromedriver.start();

    done();
  },

  after : function(done) {
    chromedriver.stop();

    done();
  }
}

【问题讨论】:

  • @user8185655 提供的答案似乎解决了我的问题。

标签: selenium-chromedriver nightwatch.js


【解决方案1】:

问题可能是 Chromedriver 期望在 / 而不是 /wd/hub 的命令。要修复,请使用 --url-base=/wd/hub 启动 Chromedriver

来源:Selenium WebDriverJS, cannot build webdriver for Chromehttps://github.com/webdriverio/webdriverio/issues/113

【讨论】:

  • 是的,我执行 ./chromedriver 并且实例在端口 9515 可用。Starting ChromeDriver 2.35.528139 (47ead77cb35ad2a9a83248b292151462a66cd881) on port 9515 Only local connections are allowed.
  • @pclaunch1 也许问题是 Chromedriver 没有在正确的位置处理命令。我已经更新了我的答案。
  • 好的,我将命令更改为 ./chromedriver --url-base=/wd/hub 以启动 chromedriver,我的测试现在正在运行。谢谢@user8185655
【解决方案2】:

您需要在外部全局文件中启动 chromedriver。看起来你的配置是正确的。只需在外部全局模块中设置 beforeafter 函数即可启动 chromedriver。

before : function(done) {
  chromedriver.start();

  done();
},

after : function(done) {
  chromedriver.stop();

  done();
}

查看Getting Started 指南了解更多详情。

【讨论】:

  • 好的,我已经配置了一个 globals.js 文件,我在 nightwatch.js 文件中指向它,但我仍然遇到同样的错误。我在上面的编辑中包含了我的全局变量。在使用外部全局模块时,我是否缺少步骤?
猜你喜欢
  • 2018-03-30
  • 1970-01-01
  • 1970-01-01
  • 2018-05-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-01-31
  • 1970-01-01
相关资源
最近更新 更多