Automation Testing with Nightwatch JS and Cucumber: Everything You Need to Know

What is Nightwatch JS?

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). It is a complete End-to-End testing solution which aims to simplify writing automated tests and setting up Continuous Integration. Nightwatch works by communicating over a restful HTTP API with a WebDriver server (such as ChromeDriver or Selenium Server). The protocol is defined by the W3C WebDriver spec, which is derived from JSON Wire protocol. The latest version available in market is 1.0.

Why Use Nightwatch JS Over Any Other Automation Tool?

Selenium is demanded for developing automation framework since it supports various programming languages, provides cross-browser testing and also used in both web application and mobile application testing.

  • Robust configuration
  • Integrates with cloud servers like SauceLabs and Browserstack for web and mobile testing with JavaScript, Appium
  • Allows configuration with Cucumber to build a strong BDD (Behaviour Driven Development) setup
  • High performance of the automation execution
  • Improves test structuring
  • Minimum usage and less Maintenance of code

Installation and Configuration of Nightwatch Framework

For configuring Nightwatch framework, all needed are the following in your system -

  • Install npm

Using Nightwatch — Writing and Running Tests

We create a JavaScript file named demo.js for running a test through nightwatch with the command

Nightwatch and Cucumber JS

Cucumber is a tool that supports Behavior Driven Development (BDD) and allows to write tests in simple english language in Given, When, Then format.

  • Cucumber Testing focuses on end-user experience
  • Style of writing tests allow for easier reuse of code in the tests
  • Quick and easy set up and execution
  • An efficient tool for testing

Executing Individual Feature Files or Scenarios

  • Single feature file

Feature and Scenario Tags

Cucumber allows to add tags to features or scenarios and we can selectively run a scenario using those tags. The tags can be used with conditional operators also, depending on the requirement.

Custom Reporters in Nightwatch and Cucumber Framework

Reporting is again an advantage provided by Cucumber which generates a report of test results at the end of the execution and it provides an immediate visual clue of a possible problem and will simplify the debugging process. HTML reports are best suited and easy to understand due to its format. To generate the same, we will add cucumber-html-reporter as a dependency in our nightwatch.conf.js file.

Conclusion

Nightwatch-Cucumber is a great module for linking the accessibility of Cucumber.js with the robust testing framework of Nightwatch.js. Together they can not only provide easily readable documentation of test suite, but also highly configurable automated user tests, all while keeping everything in JavaScript.

Velotio Perspectives

Thoughts and ideas on startups, enterprise software &…

Velotio Technologies

Written by

Velotio Technologies is an outsourced software and product development partner for technology startups & enterprises. #Cloud #DevOps #ML #UI #DataEngineering

Velotio Perspectives

Thoughts and ideas on startups, enterprise software & technology by the Velotio team. Learn more at www.velotio.com.

Velotio Technologies

Written by

Velotio Technologies is an outsourced software and product development partner for technology startups & enterprises. #Cloud #DevOps #ML #UI #DataEngineering

Velotio Perspectives

Thoughts and ideas on startups, enterprise software & technology by the Velotio team. Learn more at www.velotio.com.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store