Javascript 连接被拒绝!selenium服务器启动了吗
我继承了一个工作中没有文档的项目。这是一个sails.js应用程序。 有一小部分单元测试和端到端测试 当我尝试使用grunt运行端到端测试时。我得到:Javascript 连接被拒绝!selenium服务器启动了吗,javascript,node.js,testing,selenium,sails.js,Javascript,Node.js,Testing,Selenium,Sails.js,我继承了一个工作中没有文档的项目。这是一个sails.js应用程序。 有一小部分单元测试和端到端测试 当我尝试使用grunt运行端到端测试时。我得到: $ grunt e2e Running "nightwatch" task started - PID: 5440 >> Executing "default" tests (standalone) [Index] Test Suite ================== Running: Should clean the
$ 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服务器的启动。如果我先启动罐子(在grunt之外),我会得到
$ 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
}
}
}
}
非常感谢您的帮助
p、 windows 7设备上的s.Am
"webdriver.chrome.driver" : "",
您需要在nightwatch.json文件的这一行中指定您的chrome驱动程序位置
例如,我使用:
"webdriver.chrome.driver" : "~/bin/chromedriver",
您也开始使用chrome驱动程序了吗?如果启动selenium时没有,请附加:
-Dwebdriver.chrome.driver=/Users/[username]/bin/chromedriver
因此,当您启动selenium服务器时,它应该看起来像终端cmd:
java-jar[SeleniumServerName]-Dwebdriver.chrome.driver=/Users/[username]/bin/chromedriver
请记住先将CD刻录到seleniumserver文件夹中,然后根据Windows更改文件/文件夹路径结构。非常感谢您包含nightwatch.json文件 我认为乔丹指出了问题的一部分。开箱即用,我还没能让夜表在Chrome上运行。我的.json文件到处都有Firefox,你的Chrome说。我不得不下载Firefox,但它没有设置Jordan提到的驱动程序 我的下一个问题是服务器 我将selenium对象
start\u进程
设置为true;当您使用grunt运行测试时,nightwatch将自动启动服务器。您还需要将server\u路径设置为some/directory/selenium-server-standalone-2.40.0.jar
不管这是否解决了您当前的问题,它可能会在将来为您节省时间,因为您不必启动服务器然后运行测试。以防其他人也遇到同样的问题
过去几天我遇到了这个问题。问题是在我的情况下,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 } } }
结论
chromedriver版本2.33需要chrome版本>=60。
更新chrome解决了我的问题
亲切问候,,
Aril我的问题是因为在我的/etc/hosts文件中,我的127.0.0.1没有指向localhost。我解决了这个问题。我在第一次运行selenium服务器时遇到了同样的问题
如果selenium控制台也没有启动会话,则很可能webdriver未放置或不在路径中。
如果您使用的是chrome浏览器,请尝试从下载chromedriver或运行npm安装chromedriver
如果您单独下载了驱动程序可执行文件,请不要忘记将其添加到PATH中。是否启动了Selenium?你的地址是什么?请在您的问题中解释更多细节。您好@Antônio Carlos我已经更新了问题,但不确定要添加哪些其他信息。请注意“Selenium已经在4444端口上运行”。然后,将测试配置为在中运行。你用Jasmine吗?我在nightwatch.json中看到chrome。。但是我不知道这意味着什么。你能提供更多关于nightwatch.json和测试套件的详细信息吗?我也将此设置为true,但我得到相同的错误。尝试重新启动你的计算机。您可能已经有另一个selenium任务在某处运行,占用端口4444。
{
"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)...