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:
Start the selenium server in the standalone mode [neither as a Hub or as a node], using the command java -jar selenium-server-standalone-3.4.0.jar (or)
Flip the flag start_process to true in your configuration file, which will cause nightwatch to start and stop the server on its own.
Related
I have started a jessie clean vps and then I installed node.js. After that I installed nightwatch and chromedriver through npm. I made 3 files, they are nightwatch.js, nightwatch.json, and js sample testing.
Here is my nightwatch.json:
{
"src_folders" : [""],
"custom_commands_path" : "",
"custom_assertions_path" : "",
"page_objects_path" : "",
"globals_path" : "",
"selenium" : {
"start_process" : true,
"server_path" : "./selenium-server-standalone-3.0.1.jar",
"log_path" : "",
"host": "127.0.0.1",
"port" : 4444,
"cli_args" : {
"webdriver.chrome.driver" :
"./node_modules/chromedriver/lib/chromedriver/chromedriver"
}
},
"test_settings" : {
"default" : {
"launch_url" : "http://localhost",
"selenium_port" : 4444,
"selenium_host" : "localhost",
"silent": true,
"screenshots" : {
"enabled" : false,
"path" : ""
},
"desiredCapabilities": {
"browserName": "chrome",
"chromeOptions" : {
"args" : ["headless", "--no-sandbox"]
}
}
}
}
}
And for sample testing, it's just a simple testing like this:
var chromedriver = require('chromedriver');
module.exports = {
before : function(done) {
chromedriver.start();
},
after : function(done) {
chromedriver.stop();
},
'Trial' : function (browser) {
browser
.url('http://www.google.com')
.waitForElementVisible('body', 1000)
.setValue('input[type=text]', 'nightwatch')
.waitForElementVisible('button[name=btnG]', 1000)
.click('button[name=btnG]')
.pause(1000)
.assert.containsText('#main', 'Night Watch')
.end();
}
};
Here is what I got:
And everytime I run the test, it seems like the headless browser doesn't work properly. Nightwatch cannot recognize every element. When I do .assert.title('Google'), it returns 'Object not found'. I have tested it on windows and it worked smoothly. Is there something that I miss? Is it necessary to use chrome binary when I run it headlessly?
I am having issues when running a simple nightwatch test file on my local Docker image. I am trying to figure out why selenium does not want to run the local tests. If anyone has figured this out, any help would be much appreciated. Thanks!
Here is my test file:
nw-example.test.js
module.exports = {
'End-to-end all browsers' : function (browser) {
browser
.init('http://localhost:3000/')
.setValue('#loginForm-username', '')
.setValue('#loginForm-password', '')
.pause(2000)
.click('#loginForm-submit')
.perform(function(done){
console.log('Done testing')
done()
})
.pause(3000)
.assert.containsText('#app','Welcome,');
}
};
Here is my nightwatch.json file:
{
"src_folders" : ["tests"],
"output_folder" : "reports",
"custom_commands_path" : "",
"custom_assertions_path" : "",
"page_objects_path" : "",
"globals_path" : "",
"selenium" : {
"start_process" : true,
"server_path" : "",
"log_path" : "",
"port" : 4444,
"cli_args" : {
"webdriver.chrome.driver" : "./usr/local/bin/chromedriver",
"webdriver.gecko.driver" : "./usr/local/bin/geckodriver",
"webdriver.edge.driver" : "",
"webdriver.safari.driver" : ""
}
},
"test_settings" : {
"default" : {
"launch_url" : "http://localhost:3000",
"selenium_port" : 4444,
"selenium_host" : "localhost",
"silent": true,
"screenshots" : {
"enabled" : false,
"path" : ""
},
"desiredCapabilities": {
"browserName" : "chrome",
"javascriptEnabled" : true,
"marionette" : true,
"acceptSslCerts" : true
}
},
"chrome" : {
"desiredCapabilities": {
"browserName": "chrome",
"chromeOptions" : {
"args" : ["headless", "--no-sandbox"]
}
}
},
"firefox" : {
"desiredCapabilities": {
"browserName": "firefox"
}
},
"edge" : {
"desiredCapabilities": {
"browserName": "MicrosoftEdge"
}
},
"safari" : {
"desiredCapabilities": {
"browserName": "safari",
"javascriptEnabled": true
}
}
}
}
And the errors I am getting:
root#2b755e5a6174:/vital-webapp/src/__tests__# nightwatch nw-example.test.js
[Nw Example Test] Test Suite
================================
Running: End-to-end all browsers
20:13:49.642 INFO - Found handler: org.openqa.selenium.remote.server.commandhandler.BeginSession#2465e6e1
20:13:49.643 INFO - /session: Executing POST on /session (handler: BeginSession)
20:13:49.646 INFO - Capabilities are: Capabilities {acceptSslCerts: true, browserName: chrome, javascriptEnabled: true, marionette: true, name: Nw Example Test}
20:13:49.646 INFO - Capabilities {acceptSslCerts: true, browserName: chrome, javascriptEnabled: true, marionette: true, name: Nw Example Test} matched class org.openqa.selenium.remote.server.ServicedSession$Factory (provider: org.openqa.selenium.chrome.ChromeDriverService)
Starting ChromeDriver 2.35.528139 (47ead77cb35ad2a9a83248b292151462a66cd881) on port 4516
Only local connections are allowed.
20:13:59.737 WARN - timeout
java.net.SocketTimeoutException: timeout
The error says it all :
20:13:49.646 INFO - Capabilities are: Capabilities {acceptSslCerts: true, browserName: chrome, javascriptEnabled: true, marionette: true, name: Nw Example Test}
20:13:49.646 INFO - Capabilities {acceptSslCerts: true, browserName: chrome, javascriptEnabled: true, marionette: true, name: Nw Example Test} matched class org.openqa.selenium.remote.server.ServicedSession$Factory (provider: org.openqa.selenium.chrome.ChromeDriverService)
Starting ChromeDriver 2.35.528139 (47ead77cb35ad2a9a83248b292151462a66cd881) on port 4516
Only local connections are allowed.
20:13:59.737 WARN - timeout
java.net.SocketTimeoutException: timeout
While you configured ChromeDriver you have suplied the following desiredCapabilities :
"desiredCapabilities": {
"browserName" : "chrome",
"javascriptEnabled" : true,
"marionette" : true,
"acceptSslCerts" : true
}
ChromeDriver have no such capability as "marionette" which is set to true.
Remove the capability "marionette" : true and execute your #Test
for some reason, I have not been able to get tests working in Microsoft Edge Windows 10.
Here's my nightwatch config
"edge": {
"use_ssl": false,
"silent": true,
"output": true,
"desiredCapabilities": {
"browserName": "MicrosoftEdge",
"platform": "Windows 10",
"version": "13.10586",
"screenResolution": "1280x1024",
"avoidProxy": true
}
}
Has anyone been able to get their tests working in Microsoft Edge?
If so, what version of selenium do you use? I use 2.52
What version of the edge driver do you use?
First of all you need Microsoft Edge Webdriver. You may download it from here: https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/
Then in nigthwatch.js config you need to specify path to you edge webdriver (webdriver.edge.driver arg). This is how my config looks like:
"selenium": {
"start_process": true,
"server_path": "./node_modules/file_dependencies/selenium-server-standalone.jar",
"log_path": "",
"host": "127.0.0.1",
"port": seleniumPort,
"cli_args": {
"webdriver.chrome.driver": "./node_modules/file_dependencies/chromedriver.exe",
"webdriver.ie.driver": "./node_modules/file_dependencies/IEDriverServer.exe",
"webdriver.edge.driver": "C:/Program Files (x86)/Microsoft Web Driver/MicrosoftWebDriver.exe",
"webdriver.gecko.driver": "./node_modules/file_dependencies/geckodriver.exe",
"webdriver.firefox.profile": ""
}
}
Rest of your config looks fine
I had issues getting edge to work using Selenium 3.9.1 where Selenium was attempting to use the geckodriver to run tests against Edge.
My configuration looked as follows (snippet to keep to the point):
"selenium" : {
"cli_args" : {
"webdriver.chrome.driver" : "bin\\chromedriver.exe",
"webdriver.edge.driver" : "bin\\MicrosoftWebDriver.exe",
"webdriver.gecko.driver" : "bin\\geckodriver.exe",
"webdriver.firefox.profile": ""
}
},
"test_settings" : {
"default" : {
"desiredCapabilities": {
"browserName": "edge",
"marionette": true
}
}
}
I was able to get around this by changing "edge" to "ie" and the browser name to "internet explorer" - see the updated configuration:
"selenium" : {
"cli_args" : {
"webdriver.chrome.driver" : "bin\\chromedriver.exe",
"webdriver.ie.driver" : "bin\\MicrosoftWebDriver.exe",
"webdriver.gecko.driver" : "bin\\geckodriver.exe",
"webdriver.firefox.profile": ""
}
},
"test_settings" : {
"default" : {
"launch_url" : "http://localhost",
"selenium_port" : 4444,
"selenium_host" : "localhost",
"silent": true,
"screenshots" : {
"enabled" : false,
"path" : ""
},
"desiredCapabilities": {
"browserName": "internet explorer",
"marionette": true
}
}
}
The auto-generated nightwatch.conf.js already includes configuration for Edge browser, so you can just run by flagging the edge environment:
nightwatch --env edge
I am using Nightwatch.js to build/run end to end tests on our web app, and as part of our build process, we want to integrate it with Jenkins. On my local machine, I am able to run my tests, on all three browsers (Firefox, Safari, Chrome) at the same time with no issue. I can also run on an individual browser with no issue. I have the correct and most recent versions of the selenium driver, and am pointing to them in my nightwatch.json file. For some reason, however, I am not able to launch Safari on the dedicated machine that is running these tests when a new Jenkins build comes in. Everything is set up the exact same way on that machine as it is on my on, but I keep getting the error
Error retrieving a new session from the selenium server
Failed to connect to SafariDriver after 10066ms
When this happens, both Chrome and Firefox are able to load with no problem, only Safari has the issue. We made sure to download the most recent version of the standalone selenium driver for Safari, and I did it again just to be sure. I've also made sure to check if there happens to be another instance of the selenium server running, but it's never the case
My nightwatch.json file looks like this....
{
"src_folders" : ["test"],
"output_folder" : "reports",
"custom_commands_path" : "node_modules/nightwatch-custom-commands- assertions/js/commands",
"custom_assertions_path" : "node_modules/nightwatch-custom-commands-assertions/js/assertions",
"page_objects_path" : "",
"globals_path" : "",
"selenium" : {
"start_process" : true,
"server_path" : "lib/selenium-server-standalone-2.53.0.jar",
"log_path" : "",
"host" : "127.0.0.1",
"port" : 4444,
"cli_args" : {
"webdriver.chrome.driver" : "lib/chromedriver",
"webdriver.safari.driver" : "lib/selenium-server-standalone-2.53.0.jar"
}
},
"test_settings" : {
"firefox" : {
"launch_url" : "http://localhost",
"selenium_port" : 4444,
"selenium_host" : "localhost",
"silent": true,
"screenshots" : {
"enabled" : false,
"path" : "./screenshots"
},
"desiredCapabilities": {
"browserName": "firefox",
"javascriptEnabled": true,
"acceptSslCerts": true
},
"end_session_on_fail": false,
"skip_testcase_on_fail": false
},
"chrome" : {
"launch_url" : "http://localhost",
"selenium_port" : 4444,
"selenium_host" : "localhost",
"silent": true,
"screenshots" : {
"enabled" : false,
"path" : "./screenshots"
},
"desiredCapabilities": {
"browserName": "chrome",
"javascriptEnabled": true,
"acceptSslCerts": true
},
"end_session_on_fail": false,
"skip_testcase_on_fail": false
},
"safari" : {
"launch_url" : "http://localhost",
"selenium_port" : 4444,
"selenium_host" : "localhost",
"silent": true,
"screenshots" : {
"enabled" : false,
"path" : "./screenshots"
},
"desiredCapabilities" : {
"browserName" : "safari",
"javascriptEnabled" : true,
"acceptSslCerts" : true
},
"end_session_on_fail": false,
"skip_testcase_on_fail": false
}
}
}
If anyone has any insight to why this might be happening I'd appreciate it. Thanks
You would have to manually install SafariDriver. SafariDriver can be found here.
To check if safariDriver is enabled or not go to Safari>Preferences>Extensions>Here enable webDriver extension. It should be enabled by default but just in case if you need to debug. Thanks
UPDATE*****
Turns out there is an extension for Safari that needs to be installed for selenium driver to work.
I'm trying to run some nightwatch.js e2e tests using Gulp.
At the moment I have to do the following:
Run the selenium server manually
Set the path of selenium-server-standalone-2.47.1.jar and phantomjs.exe
Run the web server manually
My gulp task looks as follows:
gulp.task("run-e2e-tests", function () {
return gulp.src('')
.pipe(nightwatch({
configFile: "nightwatch.json",
cliArgs: {
env: "phantomjs"
}
}));
});
My nightwatch.js configuration looks as follows:
{
"src_folders" : [
"bundle/e2e_test/"
],
"output_folder": false,
"selenium" : {
"start_process" : false,
"server_path" : "./selenium-binaries/selenium-server-standalone-2.47.1.jar"
},
"test_settings" : {
"default" : {
"silent": true,
"screenshots" : {
"enabled" : false
},
"desiredCapabilities": {
"browserName": "phantomjs",
"javascriptEnabled" : true,
"acceptSslCerts" : false
}
},
"phantomjs" : {
"desiredCapabilities": {
"browserName": "phantomjs",
"javascriptEnabled" : true,
"acceptSslCerts" : false,
"phantomjs.binary.path" : "phantomjs.exe"
}
},
"chrome" : {
"desiredCapabilities": {
"browserName": "chrome",
"javascriptEnabled": true,
"acceptSslCerts": false
}
}
}
}
If I change "start_process" to true I get the following error:
[17:10:04] Using gulpfile ~\Desktop\CPIC.UI.Web\gulpfile.js
[17:10:04] Starting 'run-e2e-tests'...
[17:10:04] log file
[17:10:04] Starting nightwatch...
[CPIC E2e Test] Test Suite
==========================
Running: CPIC integration
Error retrieving a new session from the selenium server
Error: connect ECONNREFUSED 127.0.0.1:4444
at Object.exports._errnoException (util.js:874:11)
at exports._exceptionWithHostPort (util.js:897:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1063:14)
Connection refused! Is selenium server started?
[17:10:06] 'run-e2e-tests' errored after 1.5 s
[17:10:06] Error in plugin 'gulp-nightwatch'
Message:
nightwatch exited with code 1
The e2e test run as expected but I would like to run both the web server and the selenium server from Gulp automatically as part of my CI process.
I got it to work! Basically if you install selenium and phantomjs via npm something is wrong so you have to manually download them and set the paths int the nightwatch.js configuration file:
{
"src_folders" : [
"bundle/e2e_test/"
],
"output_folder": false,
"selenium" : {
"start_process" : true,
"server_path" : "./selenium-binaries/selenium-server-standalone-2.47.1.jar"
},
"test_settings" : {
"default" : {
"silent": true,
"screenshots" : {
"enabled" : false
},
"desiredCapabilities": {
"browserName": "phantomjs",
"javascriptEnabled" : true,
"acceptSslCerts" : false
}
},
"phantomjs" : {
"desiredCapabilities": {
"browserName": "phantomjs",
"javascriptEnabled" : true,
"acceptSslCerts" : false,
"phantomjs.binary.path" : "./selenium-binaries/phantomjs.exe"
}
}
}
}
To run the web server and kill it I used 3 tasks ans run-sequence:
gulp.task("run-e2e-tests", function (cb) {
runSequence(
"run-http-server",
"run-nightwatch",
"kill-http-server",
cb);
});
gulp.task("run-nightwatch", function () {
return gulp.src('')
.pipe(nightwatch({
configFile: "nightwatch.json",
cliArgs: {
env: "phantomjs"
}
}));
});
gulp.task("run-http-server", function () {
return connect.server({
port: 8888
});
});
gulp.task("kill-http-server", function () {
return connect.serverClose();
});