Nightwatch and automation testing

Anton Lytvynov
3 min readOct 1, 2018

5 minutes guide to run Nightwatch tests

Nightwatch.js is an automated testing framework for web applications and websites, written in Node.js and using the W3C WebDriver API (formerly Selenium WebDriver).

Install Nightwatch

All the installation process described here very clear. But I had some additional steps.

  1. Install Nightwatch globally
npm install -g nightwatch

2. Install at least Java Development Kit 7

Check if JDK was installed earlier

java -version

3. Download Selenium

Selenium is a portable software testing framework for web applications: Releases.

4. Running Selenium Manually

java -jar selenium-server-standalone-{VERSION}.jar
java -jar selenium-server-standalone-{VERSION}.jar -help

If everything is ok you should see http://127.0.0.1:4444/

Selenium on 127.0.0.1:4444

5. Download Chrome Drive to run tests with Chrome

And follow this documentation

Install chromedriver globally

sudo npm install -g chromedriver

6. Install ImageMagick for reports

brew install imagemagick --build-from-source

Run your first autotest

The initial folder structure

Initial folder structure

Here you can find Configuration part.

You can copy-paste initial configurations for your nightwatch.json file.

nightwatch.json

If you prefer to use package.json you can take this one as an example

{
"name": "nightwatch-test",
"version": "0.0.1",
"description": "Quick start with Nightwatch and Selenium.",
"dependencies": {
"chromedriver": "^2.42.0",
"nightwatch": "*",
"nightwatch-custom-commands-assertions": "^1.1.0",
"selenium-webdriver": "^3.5.0"
}
}

My nightwatch.js

require('nightwatch/bin/runner.js');

var chromedriver = require('chromedriver');

module.exports = {
before : function(done) {
chromedriver.start();
},

after : function(done) {
chromedriver.stop();
done();
}
};

And the first test: tests/google.js

module.exports = {
'demoTestGoogle': function (browser) {
browser
.url('http://www.google.com')
.waitForElementVisible('body', 1000)
.setValue('input[type=text]', 'nightwatch')
.waitForElementVisible('input[name=btnK]', 10000)
.waitForElementVisible('button[name=btnG]', 10000)
.click('button[name=btnG]')
.pause(5000)
.assert.containsText('#main', 'Night Watch')
.end();
}
};

You are ready to run the first autotest

nightwatch tests/google.js -e chrome

You should see a new chrome page

Can be also interesting for you

This article Php & Selenium can also be interesting for you.

Soon I’ll add other posts one by one on the same topics. Feel free to follow me or subscribe here.

Thank you for your attention

Thank you for your attention. If you have any question or advice please feel free to contact me. I‘ll be glad to help you.

Need professional help in web or mobile development?
Recommendation for planning or estimation of your project?
Feel free to contact me here.

P.S. I really appreciate your like or share 🙏.

--

--

Anton Lytvynov
Anton Lytvynov

Written by Anton Lytvynov

CEO & Founder of Lytvynov Production, Senior web developer, architect, cryptocurrencies trader, https://lytvynov-production.com

No responses yet