- Install NodeJS
- Install all dependencies using "npm"
This tutorial is based on some examples from this project.
You may start by cloning the project's repository.
Nightwatch.js configuration is managed in a configuration file, similar to the following one.
The capabilities (devices/browsers) we want, along with the reporter/JUnit related configurations, are all defined in the previous configuraiton file.
Nightwatch.js provides a built-in JUnit reporter, which we'll use.
The tests below don't use the Page Objects pattern. However, it would be a good recommendation to do so as mentioned by Nightwatch.js.
You may find other test examples, using the Page Objects pattern, in nightwatch.js repository here.
Test 1: Verify the content of a page on GitHub
Test 2: Verify the title of some page
Test 3: upload screenshots to S3
Running tests locally
Test(s) then can be run using NPM "test" task.
After successfully running the tests, JUnit XML files will be created, under the
node_modules/nightwatch/reports/ folder (e.g. CHROME_67.0.3396.99_Mac OS X_github.xml, CHROME_67.0.3396.99_Mac OS X_guineaPig.xml).
Reports can be imported to Xray (either by the REST API or through the Import Execution Results action within the Test Execution).
Tests are mapped to Generic Tests in Jira, and the Generic Test Definition field contains the name of the file along with the title of the function implementing the automate test.
The execution screen details will provide information on the overall test run result.
Running in the cloud using SauceLabs
Before running the test(s), you need to export some environment variables with your Sauce Lab's username along with the respective access key, which you can obtain from within the User Settings section in your Sauce Lab's profile page.
Test(s) then can be run in parallel using NPM.
Multiple JUnit XML files will be created, one per capability (device+browser), under the
Since the previous command generates multiple JUnit XML files, we may need to merge them into a single XML file so it can be submitted into a Test Execution more easily. That can be achieved by using the junit-merge utility. In this case, we'll loose the visibility of results on a per Test Environment basis though.
junit-merge -o results.xml -d node_modules/nightwatch/reports/
If we want to have visibility of the results per Test Environment, then we need to separately upload them and identify the Test Environment on each REST API request.
In Sauce Labs you can see some info about it.