NightWatchjs Part 2 (Getting Started)

NightWatchjs?

The makers of NightWatch say:

“Nightwatch.js is an automated testing framework for web applications and websites, written in Node.js and using the Selenium WebDriver API.”

They also emphasize it being an E2E (end-to-end) solution. Their interpretation of E2E is “browser automation” and is sometimes interchangeably with System Testing among some teams, but that is not exactly correct. System Testing tends to test the functionality, while E2E tests more realistic end user scenario and the real flow through.

But before we get too deep on what NightWatch sells itself as and the vernacular for testers; you can test all variations, even Unit Testing with added plugins. So after you get started, it is on your team to make the best use of this powerful and yet simple tool.

NightWatch IS a Selenium software

NightWatch is an API into the Selenium WebDriver, so you need to understand Selenium and it’s limitations before you can really understand how to use NightWatch fully.

Also something worth noting, NightWatch is not using direct bindings to the WebDriver, they use a Selenium Standalone Server, so a .jar file that you will need (along with Java) before your testing can start. A lot of this happens behind the scenes so for most it is not noticed, but if running into issues sometimes this is the culprit.

With the Selenium Server acting as a middle-man to all your processes, you need to write tests in a two part process, your selectors to verify something exists, then your step or assertion in the test. How this is done depends on your design pattern, but due to this unique requirement, patterns are already popular in the “Selenium” community, so you can hide away the selectors to not obfuscate your logic in the tests.

Environment requirements & Installation

Nodejs and NPM

With the explosion of nodejs applications, multiple versions and different OS you will install on, it is best you visit nodejs.org if you are new to nodejs. For installation, I recommend the latest LTS version. Myself I use n while others use nvm to manage your nodejs versions. For testers this comes in handy when you have multiple apps that are tested on various version of nodejs.

JDK

You will need the Java Development Kit installed to deploy your Selenium Server I mentioned earlier. Like I said, it is mostly behind the scenes as a Java servlet, but keeping this update and/or proper version can be the difference between NightWatch failing or working properly.

Selenium

From the download page you can download the Selenium Standalone Server. This will be placed in your root of the NightWatch tests or a bin folder.

The Nightwatch Test Runner will automatically detect this .jar file once you set path and start it before tests begin with the WebDriver.

Install NightWatchjs

If you want to install on just the app you intend to test:

$ npm install nightwatch

But I prefer to install globally:

$ npm install -g nightwatch

What’s Next?

Now that everything is installed you are ready to get started on configuration and building tests for a specific app. We will be using the NightWatch Test Runner (a CLI for NightWatch) in NightWatch Part 3 (Configuration & Testing your first App), that will be testing ShaneOfAllTrades. Since this is a short blog, I will try to complete Part 3 in the next week to keep you from waiting! While you wait, I suggest checking out the docs for NightWatch, Selenium and nodejs if just learning any of them. See you soon!

UPDATE

I have been super busy with a new job working on Protractor tests, so my apologies for not getting the next blog out. To keep anyone from waiting I created a GitHub repository with a very simply Nightwatch plug-n-play @ Nightwatch-bones

Please check it out, clone it and run per the directions. Should work on any OS.

Share