'拒绝连接!selenium 服务器是否已启动? ' 同时针对 Selenium Grid 运行 Nightwatch.js 测试 [英] 'Connection refused! Is selenium server started? ' while running Nightwatch.js tests against Selenium Grid

查看:19
本文介绍了'拒绝连接!selenium 服务器是否已启动? ' 同时针对 Selenium Grid 运行 Nightwatch.js 测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用基于 Nightwatch.jsNightwatch-Cucumber 来自动化我的测试.现在我想使用 Selenium Grid 和一个 Selenium 集线器和几个 Selenium 节点来执行我的测试.

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

 "devDependencies": {chromedriver":2.37.0",黄瓜":3.0.2","geckodriver": "1.11.0",守夜人":0.9.19",守夜黄瓜":9.0.0",硒服务器独立罐":3.9.1",},

这是我的 nightwatch.conf.js:

const config = {globals_path: "globals.js",输出文件夹:报告",custom_commands_path: "命令",//custom_assertions_path: '断言',直播输出:假,page_objects_path: "页面对象",disable_colors:假,硒:{start_process:真,server_path: seleniumServer.path,主机:127.0.0.1",端口:4444},测试设置:{默认: {启动网址:http://mywebsite.com"},firefox_grid:{selenium_host: "127.0.0.1",硒端口:4444,期望能力:{浏览器名称:火狐"}硒:{开始进程:假}}}};module.exports = 配置;

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

1.在 localhost 上启动 Selenium Hub

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

<强>2.在 localhost 上启动 Selenium 节点

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

3.开始 Nightwatch 测试

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

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

{ 错误:未处理的错误"事件.([对象对象])在 ClientManager.emit (events.js:185:19)在守夜人.<匿名>(/Users/GRme/projects/Aservo/DP/lcm2/testautomation/end2end-web-tests/node_modules/nightwatch/lib/runner/clientmanager.js:68:10)在 Object.onceWrapper (events.js:316:30)在 emitOne (events.js:115:13)在 Nightwatch.emit (events.js:210:7)在 HttpRequest.<匿名>(/Users/GRme/projects/Aservo/DP/lcm2/testautomation/end2end-web-tests/node_modules/nightwatch/lib/index.js:501:10)在 emitThree (events.js:135:13)在 HttpRequest.emit (events.js:216:7)在 IncomingMessage.<匿名>(/Users/GRme/projects/Aservo/DP/lcm2/testautomation/end2end-web-tests/node_modules/nightwatch/lib/http/request.js:172:16)在 emitNone (events.js:110:20)在 IncomingMessage.emit (events.js:207:7)在 endReadableNT (_stream_readable.js:1057:12)在 _combinedTickCallback (内部/进程/next_tick.js:138:11)在 process._tickCallback (internal/process/next_tick.js:180:9)语境:{消息:'连接被拒绝!selenium 服务器是否已启动?
',数据:{值:[对象],状态:33}}}

Nightwatch 对 Selenium hub 的请求似乎是成功的:

21:50:52.393 INFO - 收到创建新会话的请求:Capabilities {acceptSslCerts: true, browserName: chrome, javascriptEnabled: true}21:50:52.399 信息 - 尝试在测试槽 {seleniumProtocol=WebDriver, se:CONFIG_UUID=037e48a7-b5bc-44f2-a25b-e85c752095a7, browserName=chrome, maxInstances=5, platformName=MAC, platform=MAC 上创建新会话}

请求也被导航到 Selenium 节点:

2018-05-03 21:50:52.418:INFO:osjshC.ROOT:qtp1300393335-22:org.openqa.selenium.remote.server.WebDriverServlet-49d904ec:初始化 WebDriverServlet21:50:52.450 信息 - 找到处理程序:org.openqa.selenium.remote.server.commandhandler.BeginSession@31a65f9521:50:52.454 INFO -/session:在/session 上执行 POST(处理程序:BeginSession)21:50:52.546 信息 - 功能是:功能 {acceptSslCerts: true, browserName: chrome, javascriptEnabled: true}21:50:52.548 INFO - Capabilities {acceptSslCerts: true, browserName: chrome, javascriptEnabled: true} 匹配类 org.openqa.selenium.remote.server.ServicedSession$Factory(提供者:org.openqa.selenium.chrome.ChromeDriverService)

那么,我做错了什么,我该如何解决?Nightwatch.js 和/或 Selenium Server 独立版本是否存在问题?

解决方案

这个错误信息...

消息:'连接被拒绝!

...暗示 Selenium Grid Node 无法启动/产生新的 WebClientWeb Browsing 会话.

您的主要问题在于用于启动/初始化 Selenium Grid Node命令.Selenium Grid Node 应该以所需的 WebDriver 变体作为参数启动,如下所示:

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

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

  2. 启动 Selenium Grid 节点(默认在端口 5555):

    java -Dwebdriver.chrome.driver=C:/path/to/chromedriver.exe -jar selenium-server-standalone-3.9.1.jar -role node -hub http://localhost:4444/网格/寄存器

<块引用>

您可以在 连接被拒绝!selenium 服务器是否在边缘启动了 nightwatch

I use Nightwatch-Cucumber based on Nightwatch.js to automate my tests. And now I want to use Selenium Grid with a Selenium hub and several Selenium nodes to execute my tests.

These are my current dependencies I actually use:

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

And this is my nightwatch.conf.js:

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;

So, and these are the steps I executed to realize everything:

1. Start the Selenium Hub on localhost

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

2. Start the Selenium Node on localhost

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

3. Start the Nightwatch tests

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

Current result: I get an error while executing the Nightwatch tests and I don't know why. It looks like this:

{ 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?
',
     data: { value: [Object], status: 33 } } }

The request to the Selenium hub seems to be successful from Nightwatch:

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}

And the request also was navigated to the Selenium node:

2018-05-03 21:50:52.418:INFO:osjshC.ROOT:qtp1300393335-22: org.openqa.selenium.remote.server.WebDriverServlet-49d904ec: Initialising WebDriverServlet
21:50:52.450 INFO - Found handler: org.openqa.selenium.remote.server.commandhandler.BeginSession@31a65f95
21:50:52.454 INFO - /session: Executing POST on /session (handler: BeginSession)
21:50:52.546 INFO - Capabilities are: Capabilities {acceptSslCerts: true, browserName: chrome, javascriptEnabled: true}
21:50:52.548 INFO - Capabilities {acceptSslCerts: true, browserName: chrome, javascriptEnabled: true} matched class org.openqa.selenium.remote.server.ServicedSession$Factory (provider: org.openqa.selenium.chrome.ChromeDriverService)

So, what I'm doing wrong and how can I fix it? Is it maybe a problem with the Nightwatch.js and/or Selenium Server Standalone Version?

解决方案

This error message...

message: 'Connection refused!

...implies that the Selenium Grid Node was unable to initiate/spawn a new WebClient i.e. Web Browsing session.

Your main issue is in the command being used to start / initialize Selenium Grid Node. The Selenium Grid Node should be started with the desired WebDriver variant as an argument as follows :

  1. Start the Selenium Grid Hub (default on port 4444):

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

  2. Start the Selenium Grid Node (default on port 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
    

You can find a similar detailed discussion in Connection refused! Is selenium server started nightwatch on edge

这篇关于'拒绝连接!selenium 服务器是否已启动? ' 同时针对 Selenium Grid 运行 Nightwatch.js 测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆