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.
When I try and run the end-to-end test using grunt. I get:
$ 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.jar in grunt-nightwatch. So I take the PID is the selenium server starting. If I start the jar first(outside of grunt) I get
$ 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
{
"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
"webdriver.chrome.driver" : "",
You need to specify your chrome driver location within this line of the nightwatch.json file
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
So when you start selenium server, it should look like terminal 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.
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.
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 issue In 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):
{
"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)...
Conclusion chromedriver version 2.33 needs chrome version >= 60. Updating chrome resolved my issue.
Kind regards, Aril
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.
Thanks so much for including the nightwatch.json file.
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.
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
.
Regardless of whether this solves your immediate problem, it will probably save you time in the future by not having to start the server then run the tests.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With