Install the needed packages
npm i --save-dev nightwatch selenium-server chromedriver
Create a e2e-tests
dir:
mkdir e2e-tests
Create a config file nightwatch.json
:
{
"src_folders" : ["e2e-tests"],
"output_folder": "coverage",
"selenium" : {
"start_process" : true,
"server_path" : "node_modules/selenium-server/lib/runner/selenium-server-standalone-2.48.2.jar",
"host" : "127.0.0.1",
"port" : 4444,
"cli_args" : {
"webdriver.chrome.driver" : "node_modules/chromedriver/lib/chromedriver/chromedriver"
}
},
"test_settings" : {
"default" : {
"selenium_port": 4444,
"selenium_host": "localhost",
"silent": true
},
"chrome" : {
"desiredCapabilities": {
"browserName": "chrome",
"javascriptEnabled": true,
"acceptSslCerts": true
}
}
}
}
Create a sample test google.js
'use strict';
module.exports = {
'Demo test Google': function(browser) {
browser.url('http://www.google.com')
.waitForElementVisible('body', 1000)
.expect.element('input[type=text]')
.to.be.visible;
browser.setValue('input[type=text]', 'rembrandt van rijn')
.click('button[name=btnG]')
.expect.element('ol#rso a:first-child')
.to.be.visible.after(2000)
.and.text.to.contain('Rembrandt');
browser.end();
}
};
Launch nightwatch!
./node_modules/.bin/nightwatch