A First Look At Nightwatch Version 3.0

A First Look At Nightwatch Version 3.0

Hello, In my previous two articles, I introduced you to Nightwatch.js, an open-source automated testing framework powered by Node.js. The latest version released by Nightwatch has some interesting features. In today's article, I'm going to share with you an overview of the latest Nightwatch release, Nightwatch Version 3.0. Nightwatch started as a Selenium-based automated testing solution using JavaScript to write end-to-end browser-based tests quickly. It is an integrated framework for running automated tests on web applications and websites on all major browsers. Earlier, it supported the JSON wire protocol, but now it supports the W3C WebDriver API (formerly Selenium WebDriver) to interact with various browsers. It is an open-source tool that can be used for both individual and organizational purposes. The best thing about Nightwatch is that the installation package has all necessary features packaged, and a user can install the tool, set the configuration, and start testing as fast as 60 seconds.

The new version claims to add a lot more functionality to the existing framework of tests. It's an effort to re-imagine automated testing for the future and is based on three pillars:

1. Developer experience

2. Mobile first

3. One automated test framework

Let's see in detail some of the major features included in Nightwatch version 3.0:

1. One framework for all platforms—web, native, and mobile applications.

  • ? Mobile web: Test your web apps on real mobile devices and scale easily by connecting to cloud grids.
  • Native Mobile: Test your native iOS and Android apps with Nightwatch.
  • ? Real desktop browsers: Test on real browsers that accurately reflect your users’ environment.

Nightwatch - one framework for all platforms.

The Nightwatch framework can now automate tests for both web-based and mobile-based applications. Earlier, the tests were mostly limited to desktop-based browsers. The new change enables users to compile tests that run on both desktop and mobile browsers using Nightwatch. This includes browser-based tests on both Android and iOS devices. Since websites are increasingly run on mobile devices rather than desktops or laptops, for any automated tests on non-mobile platforms, Nightwatch was not a potential framework. This is going to change with the Nightwatch 3.0 release. Installation and set-up of Nightwatch for mobile browser-based tests are as easy and straightforward as the web counterpart. There is also a more intuitive installation tool that asks a series of questions while you install and makes the setup customized as per the user's requirements. In addition to these, users don't even have to worry about running the tests on physical devices if they are not confident enough to try them out or don't have a test device. Nightwatch supports both emulators and physical devices to run automated tests. Users can configure this in the Nightwatch test run configuration; they can also create separate test run configurations for real devices and emulators.

I would be disappointed if the new version automated just the mobile browser tests and skipped native mobile applications. But Nightwatch won't fail you there as well. Nightwatch 3.0 can now automate native iOS and Android application-based tests. This will allow users to test web or native iOS and Android mobile applications on simulators, real mobile devices, or in a cloud-based grid environment like BrowserStack. A user can download the apk file for any Android application that they want to automate and set up the path and port to the local file for running Appium on the Nightwatch configuration file. Once this is done, you are all set to start writing your first test on Nightwatch. The Nightwatch mobile automation uses Appium, an open-source mobile application testing framework. Appium allows native, hybrid, and browser-based tests on mobile devices. The best part is that all the necessary software is installed when the Nightwatch package is installed. The installation is intuitive, and there are examples for new users to get themselves familiar with the mobile browser-based tests.

2. New Nightwatch inspector tool to help testers easily find the locator for an element.

Identifying web elements is a crucial part of creating automated tests. Unable to locate elements is one of the most common reasons for the failure of automated tests. Any person who wants to develop software test automation skills should be able to write efficient locators. This can't be mastered overnight, and like any other skill, learning takes time. This has been a hurdle for manual testers who want to start writing automated tests. There are some third-party tools that act as browser plugins, like the xPath selector, xPath Finder, etc., to help with finding locators for beginners. After trying some of the locator identifiers available, I wasn't satisfied, to be honest. In my opinion, none of them were effective at writing a good locator like the one a good automation tester creates using the browser developer tools. Also, none are packaged or supported with any of the common automated frameworks available on the market. This is where the Nightwatch Inspector tool has an advantage over other frameworks.

Nightwatch inspector tool

Nightwatch 3.0 introduces a point and click tool that can help to find selectors easily. This will help both new and experienced automation testers. It will enable manual testers to start writing automated test cases swiftly. In the same way it will aid experienced automation testers to identify locators for complex web elements without scourging through the Html of the web page. It will improve the productivity by enabling more test coverage & assist testers to find durable selectors for lower long term maintenance. The benefits of the Nightwatch inspector tool can be summarized as following:

  • Save time identifying selectors.
  • Build more robust tests.
  • Reduced back and forth between test file & browser as you can test commands in the browser itself.? Replicate: Pause and debug your tests by trying out commands in a REPL(Read–eval–print loop) interface.

The Nightwatch inspector tool comes as a tab in the chrome developer tools and gets automatically installed with Nightwatch. It is a point and click tool, means the tool automatically identifies the most efficient locator path using the cursor location and displays it on the selector section. The Inspector tool provides two options for the user, a highlight button to focus on the element displayed in selector box. This will ensure the user has selected the right element on the page. Also, a copy button to copy the selector and to use it in the test. In order to navigate through the page without interference, Nightwatch has limited the point and click tool action to a specific case called Explore mode. This mode can be enabled and disabled by selecting or deselecting a checkbox. Once the locator to an element is identified the next task is usually to verify whether the locator works with a Nightwatch command. There is a field in the Inspector tool to test the Nightwatch commands with the identified locator to make certain that the identified selector is in fact the correct one. The result of the command run is displayed in the results field as Boolean values, i. True or ii. False. The successful Nightwatch commands are automatically saved in the command history section for future reference. In Summary, this tool can test any Nightwatch commands that could be run on the page and it will avoid wasting time debugging the reason for a test failure. This tool is not limited to Nightwatch.js and can be used in any project that needs CSS selectors by importing Nightwatch inspector.

3. Searching bugs got easy - powerful built in command line debugging tool.

Nightwatch debug mode

In the new Nightwatch version there is a debug mode where a user can search for automation test issues while running the tests. It's a command line tool and can be used to debug the reason for test failures while running automated test. The best thing about it is that a user can try Nightwatch commands directly on the page where tests are being run during the test. This will make debugging of test fails faster and easier. It works similar to the pause command where execution is stopped until the user presses another key. But the key difference is that any Nightwatch commands can be ran on the browser on which actual test runs using the command line. Sometimes, Nightwatch commands which are successful while writing test scripts fail during actual run. In such situations also debug mode helps to identify issues quicker. In order to enter debug mode, add browser.debug() in the test at the line where you want to start the Nightwatch Inspector. The test will execute normally until that line and will automatically enters debug mode and pauses test execution. A user can then start running Nightwatch commands on the command line on the opened browser window. The results of the Nightwatch commands ran will be immediately displayed on the command line (eg: terminal) itself. If the command run is successful: "TRUE" is returned, else an error is thrown. In order to exit this mode user can either type use the command ".exit". One the exited the test continues as normal and resumes execution. The tool has following limitations, the tool only supports serial mode and does not support parallelism. And, including this tool in other non Nightwatch projects does not allow you to test commands directly from the browser. In summary, the new Nightwatch version empowers testers to efficiently write, run and debug tests across web and native mobile applications. I welcome you all to explore this new automation tool. Adding the link to the home page of Nightwatch here: https://nightwatchjs.org/. I will come back with another topic next time, until then happy testing.
















Conclusion

Meghna Arora

Quality Assurance Project Manager at IBM

1 年

Are you prepared to pass your ISTQB Certification with flying colors? www.processexam.com/istqb is your key to success! ???? #CertificationSuccessWithFlyingColors #CertificationSuccessAwaitsYou

回复

要查看或添加评论,请登录

Jobin P.Sunny的更多文章

社区洞察

其他会员也浏览了