I have a simple test to open the launch_url in chrome. But I am getting error as cannot retrieve any new session.
Also I would like to know how can I use nightwatch without running in grid. Just a standalone instance.
Below is the configuration I have used.
{
"src_folders" : ["tests"],
"output_folder" : "reports",
"custom_commands_path" : "",
"custom_assertions_path" : "",
"page_objects_path" : "",
"globals_path" : "",
"selenium" : {
"start_process" : false,
"server_path" : "./bin/selenium-server-standalone-3.4.0.jar",
"log_path" : "",
"port" : 4444,
"cli_args" : {
"webdriver.chrome.driver" : "./bin/chromedriver.exe",
"webdriver.gecko.driver" : "",
"webdriver.edge.driver" : ""
}
},
"test_settings" : {
"default" : {
"launch_url" : "http://127.0.0.1",
"selenium_port" : 4444,
"selenium_host" : "127.0.0.1",
"silent": true,
"screenshots" : {
"enabled" : false,
"path" : ""
},
"desiredCapabilities": {
"browserName": "firefox",
"marionette": true
}
},
"chrome" : {
"desiredCapabilities": {
"browserName": "chrome",
"javascriptEnabled": true,
"acceptSslCerts": true
}
},
"edge" : {
"desiredCapabilities": {
"browserName": "MicrosoftEdge"
}
}
}
}
When I run nightwatch using the command nightwatch --env chrome or simply nightwatch, it gives me the below error
[Test1] Test Suite
======================
Running: Demo test
http://127.0.0.1
Error retrieving a new session from the selenium server
Connection refused! Is selenium server started?
{ status: 13,
value:
{ message: 'Error forwarding the new session Empty pool of VM for setup Capabilities [{acceptSslCerts=true, marionette=true, name=Test1, browserName=chrome, javascriptEnabled=true, platform=ANY}]',
class: 'org.openqa.grid.common.exception.GridException' } }
My Test looks something like
module.exports = {
'Demo test' : function (browser) {
console.log(browser.launchUrl);
browser
.url(browser.launchUrl)
.end();
}
};
I can see that the launch url is been logged into the console, but the browser is not starting. I am using the latest jar file and the chromedriver binary.
I just now gave this a try and here's what I have figured out
In your selenium
configuration section I am seeing that you have set start_process
as false
.
"selenium" : {
"start_process" : false,
"server_path" : "./bin/selenium-server-standalone-3.4.0.jar",
"log_path" : "",
"port" : 4444,
"cli_args" : {
"webdriver.chrome.driver" : "./bin/chromedriver.exe",
"webdriver.gecko.driver" : "",
"webdriver.edge.driver" : ""
}
},
When you have the value as false
, you can essentially get rid of this section itself (because its not going to be used at all per your configuration)
You are essentially telling nightwatch that it shouldn't try and start a selenium-server by itself but it should just connect to the selenium server running on port 4444
(These values are obtained from default
section of your test_settings
section
"default" : {
"launch_url" : "http://www.google.com",
"selenium_port" : 4444,
"selenium_host" : "127.0.0.1",
"silent": false,
"screenshots" : {
"enabled" : false,
"path" : ""
},
"desiredCapabilities": {
"browserName": "firefox",
"marionette": true
}
},
So far we are good. So before you ran nightwatch
command am guessing you started the selenium server but in the incorrect mode.
I think you started the server using the below command
java -jar selenium-server-standalone-3.4.0.jar -role hub
This causes a Hub
to be started. A Hub is like a manager
. It cannot do the work (of launching browsers, opening urls, typing texts, clicking links etc) on its own. It needs a node
to be available so that it can route all of its work to the node.
The error Error forwarding the new session Empty pool of VM for setup Capabilities [{acceptSslCerts=true, marionette=true, name=Nightwatchtest, browserName=firefox, javascriptEnabled=true, platform=ANY}]'
is essentially the Selenium Grid's way of telling you, that you haven't wired in any nodes for it to route the traffic to.
So in order to fix your issue, you can do one of the following:
java -jar selenium-server-standalone-3.4.0.jar
(or)start_process
to true
in your configuration file, which will cause nightwatch to start and stop the server on its own.