In this tutorial, we will create some tests in TestNG in order to validate a simple browser interaction using Sauce Labs for cloud testing.
Within this tutorial, only one Test Execution will be used; it will contain one Test Run with all the results for the different used browsers. Thus, the overall test run status will be affected by the results made for all the browsers.
Instead of this approach, a different one could be creating a Test Execution per each browser; this would require some adaptions in order to produce a XML report per each used browser. This approach would give the ability to take advantage of Test Environments (more info in Working with Test Environments).
- Install Java
- Install all dependencies using "mvn"
This tutorial is based on Sauce Labs's own tutorial for TestNG.
You may start by cloning the repository https://github.com/saucelabs-sample-test-frameworks/Java-TestNG-Selenium.
There are two tests, which extend a TestBase helper class where the target browsers/capabilities are enumerated along with the logic for obtaining the Sauce Labs credentials.
The tests use the Page Objects pattern, implemented by the following class.
Test 1: Verify the link works on the "GuineaPigPage"
Test 2: Verify comments can be added on the "GuineaPigPage"
If you wish to map the test method to an existing Test issue, or to create links to requirements whenever importing the results, please have a look at the tutorial Testing using TestNG in Java which provides the necessary instructions in order to setup TestNG for this purpose.
Before running the tests themselves, 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 Maven's "test" task.
After successfully running the tests and generating the TestNG XML report (e.g. testng-results.xml), it can be imported to Xray (either by the REST API or through the Import Execution Results action within the Test Execution).
TestNG's tests are mapped to Generic Tests in Jira, and the Generic Test Definition field contains the namespace, the name of the class, and the method name that implements the Test case.
The execution screen details will not only provide information on the overall test run result, but also on a "browser" basis.
For each browser, a different "context" will appear along with the respective result.
In Sauce Labs you can see some info about it.