Nightwatch

AIO Tests supports importing Nightwatch test results through its support for JUnit reports/Cucumber reports or via the AIO Tests REST APIs, which can be invoked from the hooks available in Nightwatch.

Nightwatch.js is an integrated framework for performing automated end-to-end testing on web applications and websites, across all major browsers. It is written in Node.js and uses the WebDriver API to interact with various browsers.

This document provides an overview on:

  • Generating Cucumber reports with Nightwatch + Cucumber and uploading it in AIO Tests.

  • Using AIO Tests REST APIs to report results and much more, using the Nightwatch framework hooks.

In this documentation, you’ll understand:

Nightwatch + Cucumber Setup

  1. npm init nightwatch

  2. npm i @cucumber/cucumber --save-dev

  3. In order to use CucumberJS in Nightwatch you need to set the test_runner config property and set the type to cucumber. You will also need to set the path to where the feature files are located. Additionally, you can configure where the report files would be generated.

    { test_runner: { // set cucumber as the runner type: 'cucumber', options: { feature_path: 'test/features', format: 'json:report/cucumber_report.json', auto_start_session: true, parallel: 2 } }, src_folders: ['examples/cucumber-js/features/step_definitions'] }

Mapping and Running Your Tests

In AIO Tests, a unique key PROJKEY-TC-12 exists for each case. The unique key can be added to the scenario tags to report results against it in AIO Tests.

The below example maps a scenario to an AIO Case:

//test/features/nightwatch.feature Feature: Google Search Background: Background name Given I open the Rijksmuseum page And I dismiss the cookie dialog Then the title is "Rijksmuseum Amsterdam, home of the Dutch masters" @PROJKEY-TC-12 @Sanity Scenario: Searching the Rijksmuseum with operation Given I search "night watch" Then Body contains "Operation Night Watch" @PROJKEY-TC-13 @P0 Scenario: Searching the Rijksmuseum with night watch Given I search "night watch" Then Body contains "The Night Watch, Rembrandt van Rijn, 1642sakljdfl"

To trigger the Nightwatch cucumber tests:

npx nightwatch test/features/nightwatch

Reporting Results via Cucumber.json

Nightwatch-Cucumber generates a cucumber.json report which can be directly imported to AIO Tests. All scenarios that are not tagged with any case keys, will be created as new cases, along with the steps from the JSON report.

Nightwatch will forward --format and --format-options CLI arguments, if present, to Cucumber. Based on the configuration in nightwatch.conf.js, the cucumber.json report would be created at the path specified in the format field. In the configuration above, the path was:

format: 'json:report/cucumber_report.json',

AIO Tests provides a rich set of APIs for Execution Management, using which users can not only report execution status, but also add effort, actual results, comments, defects and attachments to runs as well as steps.

The basic sample below will show how Cucumber Hooks can leverage the AIO Tests REST APIs to report results. We would be using the AfterAll hook of cucumber to achieve this.

To trigger the Nightwatch tests with the above file, the reporting file needs to be provided to cucumber-js, using the following command:

npx nightwatch test/features/nightwatch --require aio_reporting.js

Reporting Results for Each Scenario Individually

Reporting scenario-wise results can come in handy in a couple of scenarios:

  1. No mapping is done using the key and there is some other way to identify tests either via automation key or some custom fields.

  2. One-to-many mapping i.e. one automated test covers multiple manual cases.

  3. There are long-running suites and there is a need to see runtime results.

  4. BDD Cases map to classic cases in AIO Tests and step-wise results are not required.

For any of the above requirements, users can use the Mark TC Result API to report individual results.

The below sample demonstrates, where a scenario tag maps to one of the fields in AIO Tests, (automation key in sample). We would be using the After hook of cucumber to achieve this. The steps would be to:

  1. Find AIO cases based on search criteria.

  2. Report results against each case using bulk update requests.

To trigger the Nightwatch tests with the above file, the reporting file needs to be provided to cucumber-js, using the following command:

npx nightwatch test/features/nightwatch --require aio_reporting.js

 

For further queries and suggestions, feel free to reach out to our customer support via help@aiotests.com.