Skip to content

Instantly share code, notes, and snippets.

@primaryobjects
Last active August 18, 2022 13:56
Show Gist options
  • Save primaryobjects/cf09545253d21111078424be436e089b to your computer and use it in GitHub Desktop.
Save primaryobjects/cf09545253d21111078424be436e089b to your computer and use it in GitHub Desktop.
Running Nightwatch automated testing with Selenium on Windows. Quick-start setup.
  1. Install the chromedriver package via:
npm install chromedriver --save

or install with a local binary via:

npm install chromedriver --chromedriver_filepath=C:\\YOUR_PROJECT_PATH\\chromedriver.zip
  1. Install packages.
npm install
  1. Create a folder "tests" and place test.js inside it.
  2. Run the tests by using the command nightwatch
  3. Run individual tests with the command nightwatch --test tests\\test.js --testcase demoTestGoogle
require('nightwatch/bin/runner.js');
var chromedriver = require('chromedriver');
module.exports = {
before : function(done) {
chromedriver.start();
},
after : function(done) {
chromedriver.stop();
done();
}
};
{
"src_folders" : ["tests"],
"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" : "./nightwatch.js",
"selenium" : {
"start_process" : false,
"log_path" : "reports"
},
"live_output": true,
"test_settings" : {
"default" : {
"selenium_port" : 9515,
"selenium_host" : "localhost",
"default_path_prefix" : "",
"screenshots" : {
"enabled" : true,
"path" : "reports/error-screenshots"
},
"desiredCapabilities": {
"browserName": "chrome",
"chromeOptions" : {
"args" : ["--no-sandbox --disable-web-security --user-data-dir"]
},
"javascriptEnabled" : true,
"acceptSslCerts": true
}
}
}
}
{
"name": "nightwatch-test",
"version": "0.0.1",
"description": "Quick start with Nightwatch and Selenium.",
"dependencies": {
"chromedriver": "^2.31.0",
"nightwatch": "*",
"nightwatch-custom-commands-assertions": "^1.1.0",
"selenium-webdriver": "^3.5.0"
}
}
module.exports = {
'demoTestGoogle' : 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();
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment