Skip to main content
Image
blog%20banner%20nightwatchjs.jpg

Leveraging NightwatchJS in Drupal

article publisher

Shankar

Drupal

The night watchman can get a new image as an alert guard if he senses correctly that something does not look right. Imagine a man dressed like a stockbroker and carrying a soft leather briefcase and a valise. His walking style is sort of tentative and squirrelish which is not the way a stockbroker walks. On being asked for an ID by the watchman, he scurries off towards the entry gate of a building and drops his valise on to the floor before being finally captured by the watchman who later finds out that he was trying to rob someone from the building.

A security guard posing for the camera in a broad daylight


Much like the night watchman and his brilliance in judgement that makes sure that the building is kept safe from any such robbers, there is another solution in the digital landscape that helps in writing browser tests easily and safely. NightwatchJS is an exceptional option to run browser tests and its inclusion in the Drupal core has only made things easier for the Drupalists.

Understanding NightwatchJS

Logo of nightwatchjs with an icon representing an owl


NightwatchJS is an automated testing framework for web applications and websites. It is written on NodeJS and uses the W3C WebDriverAPI (formerly known as Selenium WebDriver) for performing commands and assertions on DOM elements.

Nightwatch.js is an integrated, easy to use End-to-End testing solution for browser-based apps and websites, written on Node.js. - Nightwatchjs.org

As a complete browser (end-to-end) testing solution, NightwatchJS has the objective of streamlining the process of setting up continuous integration and writing automated tests. It can also be utilised for writing NodeJS unit tests. It has a clean syntax that helps in writing testing rapidly with the help of NodeJS and CSS or Xpath selectors. Its out-of-the-box command line test runner propels sequential or parallel test runs simultaneously by group, tags or single. It, also, has the support for Mocha runner out-of-the-box.

NightwatchJS has its own cloud testing platform called NightCloud.io in addition to the support for other cloud testing providers like SauceLabs and BrowserStack. It governs Selenium and WebDriver services automatically in a different child process and has great support for working with Page Object Model. Moreover, with its out-of-the-box JUnit XML reporting, it is possible to incorporate your tests in the build process with systems like Jenkins. 

NightwatchJS in Drupal

JavaScript Modernisation Initiative paved the way for the addition of NightwatchJS to the Drupal core (in version 8.6) as the new standard framework for unit and functional testing of JavaScript. It makes sure that alterations made to the system do not break expected functionality in addition to the provision for writing tests for your contributed modules and themes. It can be included in the build process for ensuring that regressions hardly creep into production.

You can try NightwatchJS in Drupal 8.6 by adhering to the instructions given on GitHub. It exhibits how to test core functionality. It also instructs on how to use it for testing your existing sites, modules, and themes by giving your own custom commands, assertions and tests. It is worth considering to check out Nightwatch API documentation and the developer guide of NightwatchJS for creating custom commands and assertions.

NightwatchJS tests will be run by Drupal CI and are viewable in test log for core developers and module authors. And for your own projects, tests can be run easily in, for instance, CircleCI, that can provide you access to artefacts like screenshots and console logs.

Conclusion

While Drupal 8 has extensive back-end test coverage, NightwatchJS offers a more modern platform that will make Drupal more familiar to PHP and JavaScript developers. 

Offering amazing digital experience has been our biggest objective and we have been doing that with a suite of services.

Contact us at [email protected] and let us know how can we help you achieve your digital transformation dreams.

Subscribe

Ready to start your digital transformation journey with us?

Related Blogs

DrupalCon Singapore: It’s A Wind Up For 2024

DrupalCon Singapore Wind Up DrupalCon Singapore OpenSense Labs

OpenSense Labs team attended the DrupalCon Singapore 2024 and it was a wonderful and valuable experience, especially since it…

Drupal SDC: Advantages of Single Directory Components 

Advantages of Drupal SDC OpenSense Labs

What if one solution could organize website UI components, make them easy to reuse in different projects, ensure consistency…

Drupal 11 Upgrade: Checklist For Drupal 7 to 11 Migration 

Drupal 11 Upgrade Checklist OpenSense Labs

Drupal 10 was released in December 2022, and Drupal 11 upgrade arrived in just a year and a half. Drupal 11 came out early,…