I am trying to setup the latest nightwatch.js for the first time. This is my nightwatch.json:
{
"src_folders" : ["tests"],
"output_folder" : "reports",
"custom_commands_path" : "",
"custom_assertions_path" : "",
"page_objects_path" : "",
"globals_path" : "",
"selenium" : {
"start_process" : true,
"server_path" : "selenium-server-standalone-3.8.1.jar",
"log_path" : "",
"port" : 4444,
"cli_args" : {
"webdriver.chrome.driver" : "",
"webdriver.gecko.driver" : "",
"webdriver.edge.driver" : ""
}
},
"test_settings" : {
"default" : {
"launch_url" : "http://localhost",
"selenium_port" : 4444,
"selenium_host" : "localhost",
"silent": true,
"screenshots" : {
"enabled" : false,
"path" : ""
},
"desiredCapabilities": {
"browserName": "firefox",
"marionette": true
}
},
"chrome" : {
"desiredCapabilities": {
"browserName": "chrome"
}
},
"edge" : {
"desiredCapabilities": {
"browserName": "MicrosoftEdge"
}
}
}
}
When I run nightwatch I get this error:
Starting selenium server... started - PID: 3176
[Go] Test Suite
===================
Running: Demo test
Error retrieving a new session from the selenium server
Connection refused! Is selenium server started?
{ value:
{ message: 'Unable to create new service: GeckoDriverService\nBuild info: ve
sion: \'3.8.1\', revision: \'6e95a6684b\', time: \'2017-12-01T19:05:32.194Z\'\n
ystem info: host: \'S0026COW1983\', ip: \'10.39.13.81\', os.name: \'Windows Ser
er 2008 R2\', os.arch: \'x86\', os.version: \'6.1\', java.version: \'1.8.0_131\
\nDriver info: driver.version: unknown',
error: 'session not created' },
How can I resolve this?
I will assume that you are launching the default test settings which will try to access geckoDriver.
Looks like you haven't specified the paths for your drivers, "webdriver.chrome.driver" : "", "webdriver.gecko.driver" : "", "webdriver.edge.driver" : ""
You need to point those to your driver executables, e.g. from my project:
'webdriver.gecko.driver':'/.selenium/geckodriver/0.19.0-x64-geckodriver'
Related
I have configured several test settings and I want to run parallel chrome and ie.
When I run
./node_modules/.bin/nightwatch --env chrome
test for chrome runs
./node_modules/.bin/nightwatch --env ie
test for ie runs
./node_modules/.bin/nightwatch --env ie,chrome
test for firefox runs (as I guess this run only default ones and nothing more)
Nightwatch 1.0.18
{
"src_folders": [
"test"
],
"output_folder": "reports",
"live_output" : true,
"custom_commands_path": "config/commands",
"test_runner": {
"type" : "mocha",
"options" : {
"grep": "#acc"
}
},
"test_settings": {
"default": {
"selenium_host": "hub-cloud.browserstack.com",
"selenium_port": 80,
"launch_url": "localhost",
"browserstack.key": "KEY",
"browserstack.user": "USER",
"browserstack.local": "true"
},
"chrome-local": {
"default_path_prefix": "",
"launch_url": "localhost",
"screenshots": {
"enabled": true,
"on_failure": true,
"on_success": true,
"on_error": true,
"path": "./screenshots"
},
"desiredCapabilities": {
"browserName": "chrome",
"javascriptEnabled": true,
"chromeOptions": {
"args": [
"--no-sandbox",
"headless",
"window-size=1920,1200"
]
},
"acceptSslCerts": true,
"acceptInsecureCerts": true,
"elementScrollBehavior": 1
}
},
"chrome": {
"desiredCapabilities": {
"browser": "chrome"
}
},
"ie": {
"desiredCapabilities": {
"browserName": "ie",
}
}
}
}
for running parallel tests using Nightwatch refer - https://github.com/browserstack/nightwatch-browserstack
As you need to run parallel tests on Chrome and IE browsers you need to make changes to the line https://github.com/browserstack/nightwatch-browserstack/blob/master/package.json#L10 as follows-
"parallel": "./node_modules/.bin/nightwatch -c conf/parallel.conf.js
-e ie,chrome"
I have the following error on Windows 7 but not a a mac. It is started by nightwatch. Any ideas?
Starting selenium server... started - PID: 17228
[Test] Test Suite
=============================
Running: TestWithSettingSearchValue
Error retrieving a new session from the selenium server
Connection refused! Is selenium server started?
{ value:
{ stacktrace: 'org.openqa.selenium.WebDriverException: Timed out waiting for driver server to start.\nBuild info: version: \'3.7.1\', revision: \'8a0099a\', time: \'2017-11-06T21:07:36.161Z\'\nSystem info: host: \'W7D0596\', ip: \'172.21.1.54\', os.name: \'Windows 7\', os.arch: \'amd64\', os.version: \'6.1\', java.version: \'1.8.0_91\'\nDriver info: driver.version: unknown\r\n\tat org.openqa.selenium.remote.service.DriverService.waitUntilAvailable(DriverService.java:192)\r\n\tat org.openqa.selenium.remote.service.DriverService.start(DriverService.java:178)\r\n\tat org.openqa.selenium.remote.server.ServicedSession$Factory.apply(ServicedSession.java:207)\r\n\tat org.openqa.selenium.remote.server.ActiveSessionFactory.lambda$apply$11(ActiveSessionFactory.java:167)\r\n\tat
Our package.json
{
"name": "nightwatch",
"version": "1.0.0",
"description": "",
"main": "index.js",
"directories": {
"test": "tests"
},
"scripts": {
"test": "nightwatch"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"chromedriver": "^2.33.2",
"nightwatch": "^0.9.16",
"selenium-server-standalone-jar": "^3.7.1"
}
}
nightwatch:
{
"src_folders" : ["tests"],
"output_folder" : "reports",
"custom_commands_path" : "",
"custom_assertions_path" : "",
"page_objects_path" : "",
"globals_path" : "",
"selenium" : {
"start_process" : true,
"server_path" : "./node_modules/selenium-server-standalone-jar/jar/selenium-server-standalone-3.7.1.jar",
"log_path" : "",
"host" : "127.0.0.1",
"port" : 4444,
"cli_args" : {
"webdriver.chrome.driver" : "./node_modules/chromedriver/bin/chromedriver",
"webdriver.ie.driver" : ""
}
},
"test_settings" : {
"default" : {
"launch_url" : "http://127.0.0.1:3000/",
"selenium_port" : 4444,
"selenium_host" : "localhost",
"silent": true,
"screenshots" : {
"enabled" : false,
"path" : ""
},
"desiredCapabilities": {
"browserName": "chrome",
"javascriptEnabled": true,
"acceptSslCerts": true
}
}
}
}
You have to use the file extension for it to work on windows. Update your config and add .exe to the chromedriver path and it should start working.
"cli_args" : {
"webdriver.chrome.driver" : "./node_modules/chromedriver/lib/chromedriver/chromedriver.exe"
}
I have the following configuration in my nightwatch.json file
"saucelabsChrome": {
"selenium_host": "ondemand.saucelabs.com",
"selenium_port": 80,
"username": "example",
"access_key": "--REDACTED---",
"desiredCapabilities": {
"acceptsSslCerts": true,
"name": "chrome",
"browserName": "chrome",
"platform": "OS X 10.11",
"version": "45.0"
}
},
However, when I run nightwatch with sauce labs
node nightwatch ---args '{"beta": "true", "env": "stage"}' --test tests/example.js -e saucelabsChrome
I get an error
Couldn't find element signUpAdobe
Two questions
Where can I see the nightwatch command running on Saucelabs?
What is the best way to integrate saucelabs with nightwatch?
Here is an example of my nightwatch.json file configured to run parallel tests on Sauce Labs.
{
"src_folders" : ["tests"],
"output_folder" : "reports",
"custom_commands_path" : "custom_commands",
"custom_assertions_path" : "",
"page_objects_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_workers" : {"enabled" : true, "workers" : "auto"},
"test_settings" : {
"default" : {
"launch_url" : "http://localhost",
"selenium_port" : 80,
"selenium_host" : "ondemand.saucelabs.com",
"silent": true,
"screenshots" : {
"enabled" : false,
"path" : ""
},
"username" : "${SAUCE_USERNAME}",
"access_key" : "${SAUCE_ACCESS_KEY}",
"desiredCapabilities": {
"javascriptEnabled": true,
"acceptSslCerts": true
}
},
"chrome": {
"desiredCapabilities": {
"platform": "XP",
"browserName": "chrome",
"version": "41"
}
},
"firefox" : {
"desiredCapabilities": {
"platform": "XP",
"browserName": "firefox",
"version": "33"
}
},
"internet_explorer_10" : {
"desiredCapabilities": {
"platform": "Windows 7",
"browserName": "internet explorer",
"version": "10"
}
}
}
}
Here is a link to the entire project if you would like to take a look:
https://github.com/saucelabs-sample-test-frameworks/JS-Nightwatch.js
As to your second question. You can see the tests running in the Sauce Labs dashboard. Login at www.saucelabs.com and click on the tests tab in the top left corner.
I realize it's been a few years, but when I was searching I came across this post and found a newer guide for how to use SauceLabs with Nightwatch
Hopefully this helps anyone ending up here like I did :D
I have a simple smoketest set up using Nightwatch.js. They pass locally, but they're failing on CircleCI.
Source Code:
const WAIT = 1000;
const NODE_PORT = process.env.NODE_PORT || 3000;
module.exports = {
'Smoketest' (browser) {
browser
.url(`http://localhost:${NODE_PORT}/`)
.waitForElementVisible('body', WAIT)
.pause(300)
.assert.containsText('body', 'Client render')
.end();
}
};
Local output:
> cross-env NODE_PORT=3000 NODE_PATH=source babel-node source/test/e2e.js
Running with config:
{ logDir: '/Users/eric/Dropbox/dev/react-easy-universal/reports',
reportDir: '/Users/eric/Dropbox/dev/react-easy-universal/reports/test-e2e',
nightwatchConfig: '/Users/eric/Dropbox/dev/react-easy-universal/nightwatch.json',
webpackConfig: '/Users/eric/Dropbox/dev/react-easy-universal/webpack.config.js',
port: '3000',
server: [Object] }
[Smoketest] Test Suite
======================
Running: Smoketest
✔ Element <body> was visible after 58 milliseconds.
✔ Testing if element <body> contains text: "Client render".
OK. 2 assertions passed. (2.831s)
Failing CircleCI output:
REPORT_DIR=${CIRCLE_TEST_REPORTS} LOG_DIR=${CIRCLE_ARTIFACTS} npm run test:e2e -s
Running with config:
{ logDir: '/tmp/circle-artifacts.ddv7oJ3',
reportDir: '/tmp/circle-junit.hhJgS6N',
nightwatchConfig: '/home/ubuntu/react-easy-universal/nightwatch.json',
webpackConfig: '/home/ubuntu/react-easy-universal/webpack.config.js',
port: '3000',
server: [Object] }
[Smoketest] Test Suite
======================
Running: Smoketest
✔ Element <body> was visible after 85 milliseconds.
✖ Testing if element <body> contains text: "Client render". - expected "Client render" but got: Untitled
at Object.Smoketest (smoketest.js:10:15)
at Module.call (/home/ubuntu/react-easy-universal/node_modules/nightwatch/lib/runner/module.js:63:34)
at /home/ubuntu/react-easy-universal/node_modules/nightwatch/lib/runner/testcase.js:97:29
at _fulfilled (/home/ubuntu/react-easy-universal/node_modules/q/q.js:834:54)
at self.promiseDispatch.done (/home/ubuntu/react-easy-universal/node_modules/q/q.js:863:30)
at Promise.promise.promiseDispatch (/home/ubuntu/react-easy-universal/node_modules/q/q.js:796:13)
at /home/ubuntu/react-easy-universal/node_modules/q/q.js:556:49
at runSingle (/home/ubuntu/react-easy-universal/node_modules/q/q.js:137:13)
at flush (/home/ubuntu/react-easy-universal/node_modules/q/q.js:125:13)
at nextTickCallbackWith0Args (node.js:452:9)
FAILED: 1 assertions failed and 1 passed (3.242s)
----------------------------------------------------
TEST FAILURE: 1 assertions failed, 1 passed (3.543s)
✖ smoketest
- Smoketest
Testing if element <body> contains text: "Client render". - Expected "Client render" but got: "Untitled" REPORT_DIR=${CIRCLE_TEST_REPORTS} LOG_DIR=${CIRCLE_ARTIFACTS} npm run test:e2e -s returned exit code 1
Initially, the browser starts with some rendered output from the server. The title from the server render is set to "Untitled". Then some JavaScript loads and runs in the client, and the client render happens, changing the text to "Client render". This test is intended to ensure that the client render is working as expected.
Here's the nightwatch.json:
{
"src_folders" : ["source/test/functional/browser"],
"output_folder" : "./reports/test-e2e",
"custom_commands_path" : "",
"custom_assertions_path" : "",
"page_objects_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
}
}
}
}
I've suspected it could be a race condition, thinking that the assertion runs before CircleCI has a chance to load and process the JavaScript, so I've tried inserting a pause before the assertion.
Any ideas would be appreciated.
I have also this issue and it looks like (still need to recheck) I found a solution.
Make sure you you have as last code in each of your test this at the end.
browser.end();
I have marathon/mesos successfully deploying app, but if I add a port mapping, it doesn't work anymore.
My slave container is runned as :
docker run --privileged -v /data/docker/notebook:/notebook:rw -v /etc/localtime:/etc/localtime:ro --net=host -e NFS_PATH=$NFS_PATH -e IP=$IP -e RESOURCES=$RESOURCES -e ATTRIBUTES=$ATTRIBUTES -e HOSTNAME=$HOSTNAME -e MASTER=$MASTER -e SLAVE_PORT=$SLAVE_PORT -d -p 5151:5151 --name $CONTAINER_NAME $IMAGE_NAME
Then in the slave container I have to start by hand the daemon because of a strange [time="2015-10-17T12:27:40.963674511Z" level=fatal msg="Error starting daemon: error initializing graphdriver: operation not permitted"] error, so I do :
docker -d -D --insecure-registry=localhost:5000 -g /var/test
Then I see my slave on Mesos as a working ressource, and I can post some app to marathon :
{
"id": "rstudiorocker2",
"container": {
"type" : "DOCKER",
"volumes" : [],
"docker" : {
"image" : "localhost:5000/rocker/rstudio",
"privileged" : true,
"parameters" : [],
"forcePullImage" : true
}
}
}
Here the app is instantaenously deployed on the slave. The issue is that rocker is listening on port 8787, and I want to access on it on another port, so I try to make a port mapping :
{
"id": "rstudiorocker",
"container": {
"type" : "DOCKER",
"volumes" : [],
"docker" : {
"image" : "192.168.0.38:5000/rocker/rstudio",
"privileged" : true,
"parameters" : [],
"forcePullImage" : true,
"network":"BRIDGE",
"portMappings": [
{ "containerPort": 8787,
"hostPort": 2036,
"protocol": "tcp" }
, { "containerPort": 8787,
"hostPort": 2036,
"protocol": "udp" }
]}
}
}
and here the problem appear : the app stay on "stagging" stage, without never being deployed (even if I delete all other app first) :(
What could go wrong ?
You've tried to map the same container port twice, which is not allowed by Marathon:
"portMappings": [
{ "containerPort": 8787,
"hostPort": 2036,
"protocol": "tcp" },
{ "containerPort": 8787,
"hostPort": 2036,
"protocol": "udp" }
]}
Marathon will reject this configuration with a message like
{"message":"Bean is not valid","errors":[{"attribute":"ports","error":"Elements must be unique"}]}
Try changing one of the containerPort values, eg:
"portMappings": [
{ "containerPort": 8787,
"hostPort": 0,
"protocol": "tcp" },
{ "containerPort": 8789,
"hostPort": 0,
"protocol": "udp" }
]}