'拒绝连接!是否启动了selenium服务器?\ n'在运行针对Selenium Grid

时间:2018-05-03 19:53:19

标签: selenium selenium-webdriver cucumber selenium-grid nightwatch.js

我使用基于Nightwatch-Cucumber的{​​{1}}来自动化我的测试。现在我想使用Selenium Grid和Selenium hub以及几个Selenium节点来执行我的测试。

这些是我实际使用的当前依赖项:

Nightwatch.js

这是我的 "devDependencies": { "chromedriver": "2.37.0", "cucumber": "3.0.2", "geckodriver": "1.11.0", "nightwatch": "0.9.19", "nightwatch-cucumber": "9.0.0", "selenium-server-standalone-jar": "3.9.1", },

nightwatch.conf.js

所以,这些是我为实现一切而执行的步骤:

1。在localhost上启动Selenium Hub

const config = { globals_path: "globals.js", output_folder: "reports", custom_commands_path: "commands", // custom_assertions_path: 'assertions', live_output: false, page_objects_path: "pageobjects", disable_colors: false, selenium: { start_process: true, server_path: seleniumServer.path, host: "127.0.0.1", port: 4444 }, test_settings: { default: { launch_url: "http://mywebsite.com" }, firefox_grid: { selenium_host: "127.0.0.1", selenium_port: 4444, desiredCapabilities: { browserName: "firefox" } selenium: { start_process: false } } } }; module.exports = config;

2。在localhost上启动Selenium节点

java -jar selenium-server-standalone-3.9.1.jar -port 4444 -role hub

第3。启动Nightwatch测试

java -jar selenium-server-standalone-3.9.1.jar -port 5555 -role node

当前结果: 我在执行Nightwatch测试时遇到错误,我不知道为什么。它看起来像这样:

./node_modules/.bin/nightwatch --env firefox_grid --tag=myCucumberTag

对于Selenium中心的请求似乎在Nightwatch中取得了成功:

{ Error: Unhandled "error" event. ([object Object])
    at ClientManager.emit (events.js:185:19)
    at Nightwatch.<anonymous> (/Users/GRme/projects/Aservo/DP/lcm2/testautomation/end2end-web-tests/node_modules/nightwatch/lib/runner/clientmanager.js:68:10)
    at Object.onceWrapper (events.js:316:30)
    at emitOne (events.js:115:13)
    at Nightwatch.emit (events.js:210:7)
    at HttpRequest.<anonymous> (/Users/GRme/projects/Aservo/DP/lcm2/testautomation/end2end-web-tests/node_modules/nightwatch/lib/index.js:501:10)
    at emitThree (events.js:135:13)
    at HttpRequest.emit (events.js:216:7)
    at IncomingMessage.<anonymous> (/Users/GRme/projects/Aservo/DP/lcm2/testautomation/end2end-web-tests/node_modules/nightwatch/lib/http/request.js:172:16)
    at emitNone (events.js:110:20)
    at IncomingMessage.emit (events.js:207:7)
    at endReadableNT (_stream_readable.js:1057:12)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)
  context:
   { message: 'Connection refused! Is selenium server started?\n',
     data: { value: [Object], status: 33 } } }

请求也被导航到Selenium节点:

21:50:52.393 INFO - Got a request to create a new session: Capabilities {acceptSslCerts: true, browserName: chrome, javascriptEnabled: true}
21:50:52.399 INFO - Trying to create a new session on test slot {seleniumProtocol=WebDriver, se:CONFIG_UUID=037e48a7-b5bc-44f2-a25b-e85c752095a7, browserName=chrome, maxInstances=5, platformName=MAC, platform=MAC}

那么,我做错了什么,我该如何解决呢?这可能是Nightwatch.js和/或Selenium Server Standalone版本的问题吗?

1 个答案:

答案 0 :(得分:1)

此错误消息......

message: 'Connection refused!

...意味着 Selenium网格节点无法启动/生成新的 WebClient Web浏览会话。

您的主要问题是命令用于启动 / 初始化 Selenium网格节点。应使用所需的 WebDriver 变量作为参数启动 Selenium网格节点,如下所示:

  1. 启动 Selenium Grid Hub (默认端口4444):

    java -jar selenium-server-standalone-3.9.1.jar -role hub
    
  2. 启动 Selenium网格节点(默认端口5555):

    java -Dwebdriver.chrome.driver=C:/path/to/chromedriver.exe -jar selenium-server-standalone-3.9.1.jar -role node -hub http://localhost:4444/grid/register
    
  3.   

    您可以在Connection refused! Is selenium server started nightwatch on edge

    中找到类似的详细讨论