javascript 拒绝连接!硒服务器是否启动
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27225118/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Connection refused! Is selenium server started
提问by codemeasandwich
I have inherited a project in work with no documentation. It is a sails.js application. There is a small set of unit tests and an end-to-end test.
我继承了一个没有文档的项目。这是一个sails.js 应用程序。有一小组单元测试和端到端测试。
When I try and run the end-to-end test using grunt. I get:
当我尝试使用 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?
I don't know what I could be missing. This has me stuck for over a week.
我不知道我会错过什么。这让我坚持了一个多星期。
The project has a selenium-server-standalone-2.40.0.jarin grunt-nightwatch. So I take the PID is the selenium server starting. If I start the jar first(outside of grunt) I get
该项目在 grunt- nightwatch中有一个selenium-server-standalone-2.40.0.jar。所以我取的PID是selenium服务器启动的。如果我先启动罐子(在咕噜声之外)我得到
$ grunt e2e
org.openqa.grid.selenium.GridLauncher main
INFO: Launching a standalone server
18:38:46.189 WARN - Failed to start: [email protected]: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.
Here is the nightwatch.json
这是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
}
}
}
}
Huge thanks for any help!
非常感谢您的帮助!
p.s. Am on a windows 7 box
ps 在 Windows 7 盒子上
回答by Jordan
"webdriver.chrome.driver" : "",
You need to specify your chrome driver location within this line of the nightwatch.json file
您需要在 nightwatch.json 文件的这一行中指定您的 chrome 驱动程序位置
For example, i use:
例如,我使用:
"webdriver.chrome.driver" : "~/bin/chromedriver",
Also are you starting selenium to use the chrome driver? If not when you boot selenium, append: -Dwebdriver.chrome.driver=/Users/[username]/bin/chromedriver
您是否也在启动 selenium 以使用 chrome 驱动程序?如果在启动 selenium 时没有,请附加:-Dwebdriver.chrome.driver=/Users/[username]/bin/chromedriver
So when you start selenium server, it should look like terminal cmd: java -jar [SeleniumServerName] -Dwebdriver.chrome.driver=/Users/[username]/bin/chromedriver
所以当你启动 selenium 服务器时,它应该看起来像终端 cmd:java -jar [SeleniumServerName] -Dwebdriver.chrome.driver=/Users/[username]/bin/chromedriver
Remember to CD into the seleniumserver folder first and to change around file/folder path structure based on Windows.
记得先CD进入seleniumserver文件夹,并根据Windows更改文件/文件夹路径结构。
回答by Adam
Thanks so much for including the nightwatch.json file.
非常感谢您包含 nightwatch.json 文件。
I think Jordan is pointing at part of the problem. Out-of-the-box, I haven't been able to get Nightwatch to run on Chrome. My .json file had Firefox everywhere yours says Chrome. I had to download Firefox and it worked without actually setting the drivers Jordan mentioned.
我认为乔丹指出了问题的一部分。开箱即用,我无法让 Nightwatch 在 Chrome 上运行。我的 .json 文件在你的 Chrome 中随处可见 Firefox。我不得不下载 Firefox,它在没有实际设置 Jordan 提到的驱动程序的情况下工作。
My next problem was the server.
我的下一个问题是服务器。
I set the selenium object start_process
is set to true; nightwatch will then automatically start the server when you run the tests with grunt. You'll also need to set the server_path
to some/directory/selenium-server-standalone-2.40.0.jar
.
我将selenium对象start_process
设置为true;当您使用 grunt 运行测试时,nightwatch 将自动启动服务器。您还需要将 设置server_path
为some/directory/selenium-server-standalone-2.40.0.jar
。
Regardless of whether this solves your immediate problem, it will probably save you time in the future by not having to start the server thenrun the tests.
不管这是否能解决您当前的问题,它可能会节省您将来的时间,因为不必启动服务器然后运行测试。
回答by Aril Spetalen
just in case anyone else struggles likewise.
以防万一其他人也有同样的挣扎。
I had this issue the last couple of days. The problem was in my case, the chromedriver version was incompatible with the chrome version. I could not tell from the nightwatch output, but added a log output which told me.
最近几天我遇到了这个问题。问题是在我的情况下,chromedriver 版本与 chrome 版本不兼容。我无法从 nightwatch 输出中分辨出来,但添加了一个告诉我的日志输出。
What I saw initially
我最初看到的
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 } } }
How I spotted the issueIn the traceback above, there's a reference to line 501 in /node_modules/nightwatch/lib/index.js. I added a console.log statement there, printing out the 'data' from here, which read this (from start):
我是如何发现问题的在上面的回溯中,/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)...
Conclusionchromedriver version 2.33 needs chrome version >= 60. Updating chrome resolved my issue.
结论chromedriver 版本 2.33 需要 chrome 版本 >= 60。更新 chrome 解决了我的问题。
Kind regards, Aril
亲切的问候,阿里尔
回答by Joel M.
My issue came because in my /etc/hosts file I had 127.0.0.1 not pointed to localhost. I fixed that and it solved the problem.
我的问题是因为在我的 /etc/hosts 文件中我有 127.0.0.1 没有指向 localhost。我解决了这个问题,它解决了问题。
回答by AnkitK
I had the same problem while running the selenium server for the first time.
我第一次运行 selenium 服务器时遇到了同样的问题。
If the selenium console http://localhost:4444/wd/hub/is also not starting the session, it is likely that the webdriver is not placed or not in PATH.
If you are using chrome browser, try downloading the chromedriver from https://chromedriver.storage.googleapis.com/or run npm install chromedriver
.
如果 selenium 控制台http://localhost:4444/wd/hub/也没有启动会话,则可能是 webdriver 未放置或不在 PATH 中。如果您使用的是 chrome 浏览器,请尝试从https://chromedriver.storage.googleapis.com/下载 chromedriver或运行npm install chromedriver
。
If you have downloaded the driver executable separately, don't forget to add it in PATH.
如果您单独下载了驱动程序可执行文件,请不要忘记将其添加到 PATH 中。