【问题标题】:Connection refused! Is selenium server started拒绝连接!硒服务器是否已启动
【发布时间】:2015-01-29 06:21:50
【问题描述】:

我继承了一个没有文档的工作项目。这是一个sails.js 应用程序。 有一小部分单元测试和一个端到端测试。

当我尝试使用 grunt 运行端到端测试时。我明白了:

$ grunt e2e
Running "nightwatch" task
started - PID:  5440
>> Executing "default" tests (standalone)

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

Running:  Should clean the collection

removing 0 places
>> Connection refused! Is selenium server started?

我不知道我会错过什么。这让我卡了一个多星期。

该项目在 grunt-nightwatch 中有一个 selenium-server-standalone-2.40.0.jar。所以我取的PID是selenium server启动的。如果我先启动罐子(在咕噜声之外),我会得到

$ grunt e2e
org.openqa.grid.selenium.GridLauncher main
INFO: Launching a standalone server
18:38:46.189 WARN - Failed to start: SocketListener0@0.0.0.0:4444
Exception in thread "main" java.net.BindException: Selenium is already running on port 4444. Or     some other service is.
    at org.openqa.selenium.server.SeleniumServer.start(SeleniumServer.java:491)
    at org.openqa.selenium.server.SeleniumServer.boot(SeleniumServer.java:300)
    at org.openqa.selenium.server.SeleniumServer.main(SeleniumServer.java:245)
    at org.openqa.grid.selenium.GridLauncher.main(GridLauncher.java:95)
>> Could not start Selenium.

这是 nightwatch.json

{
  "src_folders" : ["tests/e2e"],
  "custom_commands_path" : "",
  "custom_assertions_path" : "",
  "globals_path" : "",

  "selenium" : {
    "start_process" : false,
    "server_path" : "",
    "log_path" : "",
    "host" : "127.0.0.1",
    "port" : 4444,
    "cli_args" : {
      "webdriver.chrome.driver" : "",
      "webdriver.ie.driver" : ""
    }  
  },

  "test_settings" : {
    "default" : {
      "launch_url" : "http://localhost",
      "selenium_port"  : 4444,
      "selenium_host"  : "localhost",
      "silent": true,
      "screenshots" : {
        "enabled" : false,
        "path" : ""
      },
      "desiredCapabilities": {
        "browserName": "chrome",
        "javascriptEnabled": true,
        "acceptSslCerts": true
      }
    },

    "chrome" : {
      "desiredCapabilities": {
        "browserName": "chrome",
        "javascriptEnabled": true,
        "acceptSslCerts": true
      }
    }
  }
}

非常感谢您的帮助!

附言我在 Windows 7 盒子上

【问题讨论】:

  • 您是否启动了 Selenium?你的 Selenium 运行什么地址?请在您的问题中解释更多细节。
  • 嗨@AntônioCarlos 我已经更新了问题,但不确定要添加哪些其他信息。
  • 看看“Selenium 已经在端口 4444 上运行”。然后,将您的测试配置为在localhost:4444 中运行。你用茉莉花吗?
  • 我在 nightwatch.json 中看到了 chrome.. 但我不知道这是什么意思
  • 您能否提供更多有关您的 nightwatch.json 和测试套件的详细信息?

标签: javascript node.js testing selenium sails.js


【解决方案1】:
 "webdriver.chrome.driver" : "",

您需要在 nightwatch.json 文件的这一行中指定您的 chrome 驱动程序位置

例如,我使用:

"webdriver.chrome.driver" : "~/bin/chromedriver",

您是否也开始使用 selenium 以使用 chrome 驱动程序?如果在您启动 selenium 时没有,请附加: -Dwebdriver.chrome.driver=/Users/[用户名]/bin/chromedriver

所以当你启动 selenium 服务器时,它应该看起来像终端 cmd: java -jar [SeleniumServerName] -Dwebdriver.chrome.driver=/Users/[用户名]/bin/chromedriver

记得先将光盘放入 seleniumserver 文件夹,然后根据 Windows 更改文件/文件夹路径结构。

【讨论】:

    【解决方案2】:

    非常感谢您提供 nightwatch.json 文件。

    我认为乔丹指出了问题的一部分。开箱即用,我无法让 Nightwatch 在 Chrome 上运行。我的 .json 文件在你说 Chrome 的任何地方都有 Firefox。我必须下载 Firefox,它没有实际设置 Jordan 提到的驱动程序。

    我的下一个问题是服务器。

    我将selenium对象start_process设置为true;当您使用 grunt 运行测试时,nightwatch 将自动启动服务器。您还需要将server_path 设置为some/directory/selenium-server-standalone-2.40.0.jar

    无论这是否能解决您当前的问题,它可能会在将来节省您的时间,因为不必启动服务器然后运行测试。

    【讨论】:

    • 我也将此设置为 true,但我得到了同样的错误。
    • 尝试重新启动您的计算机。你可能已经有另一个 selenium 任务在某个地方运行,占用了 4444 端口。
    【解决方案3】:

    以防万一其他人也同样挣扎。

    最近几天我遇到了这个问题。问题是在我的情况下,chromedriver 版本与 chrome 版本不兼容。我无法从 nightwatch 输出中分辨出来,但添加了一个告诉我的日志输出。

    我最初看到的

    Starting selenium server... started - PID:  12835
    ...
    { Error: Unhandled "error" event. ([object Object])
        at ClientManager.emit (events.js:185:19)
        at Nightwatch.<anonymous> (/home/n23430/dev/Ps.Web/WebTest/ps-web-test/node_modules/nightwatch/lib/runner/clientmanager.js:67:10)
        at Object.onceWrapper (events.js:316:30)
        at emitOne (events.js:115:13)
        at Nightwatch.emit (events.js:210:7)
        at HttpRequest.<anonymous> (/home/n23430/dev/Ps.Web/WebTest/ps-web-test/node_modules/nightwatch/lib/index.js:501:10)
        at emitThree (events.js:135:13)
        at HttpRequest.emit (events.js:216:7)
        at IncomingMessage.<anonymous> (/home/n23430/dev/Ps.Web/WebTest/ps-web-test/node_modules/nightwatch/lib/http/request.js:168:16)
        at emitNone (events.js:110:20)
        at IncomingMessage.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)
      context: 
       { message: 'Connection refused! Is selenium server started?\n',
         data: { value: [Object], status: 33 } } }
    

    我是如何发现问题的 在上面的回溯中,在 /node_modules/nightwatch/lib/index.js 中有对第 501 行的引用。我在那里添加了一个 console.log 语句,从这里打印出“数据”,它读到这个(从头开始):

    {
      "value": {
        "stacktrace": "org.openqa.selenium.SessionNotCreatedException: session not created exception: Chrome version must be >= 60.0.3112.0\n  (Driver info: chromedriver=2.33.506092 (733a02544d189eeb751fe0d7ddca79a0ee28cce4),platform=Linux 4.4.0-79-generic x86_64) (WARNING: The server did not provide any stacktrace information)...
    

    结论 chromedriver 2.33 版需要 chrome 版本 >= 60。 更新 chrome 解决了我的问题。

    亲切的问候, 假种皮

    【讨论】:

      【解决方案4】:

      我的问题出现了,因为在我的 /etc/hosts 文件中,我的 127.0.0.1 没有指向 localhost。我解决了这个问题,它解决了问题。

      【讨论】:

        【解决方案5】:

        我第一次运行 selenium 服务器时遇到了同样的问题。

        如果 selenium 控制台 http://localhost:4444/wd/hub/ 也没有启动会话,则可能是 webdriver 未放置或不在 PATH 中。 如果您使用的是 chrome 浏览器,请尝试从 https://chromedriver.storage.googleapis.com/ 下载 chromedriver 或运行 npm install chromedriver

        如果您已经单独下载了驱动程序可执行文件,请不要忘记将其添加到 PATH 中。

        【讨论】:

          猜你喜欢
          • 2018-04-15
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-10-14
          • 2016-06-21
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多