...
Generating the Junit report from WebdriverIO tests and uploading it to AIO Tests.
Using AIO Tests REST APIs to report results and much more, using the WDIO framework hooks.
...
Table of Contents |
---|
Required WDIO Setup
npm init wdio ./path/to/new/project
. On prompt to select framework, select Mocha.For reporting results
For JUnit report :
npm install @wdio/junit-reporter --save-dev
For reporting results via AIO Tests API :
npm install axios
(This can be replaced with any library to make API calls)
Running your tests
The sample test generated by Webdriver IO is as follows. One more test has been added to demo an error case.
...
Post execution of a suite, the TEST-<xxx>.xml file can be uploaded either via
AIO Tests REST API call using multipart form-data to upload file
...
Uploading the above file for the first time will
create new cases in the system. The new case is created with
- title as thename
value from <testcase> tag of the JUnit report
- automation key asclassname.name
from the JUnit report.
- status as Published
- automation status as Automated
- automation owner as user uploading the resultsAdd the newly created case to the cycle being uploaded to
Mark the details of the run
Execution mode is set to Automated
Duration of run is set to Actual Effort
Status of run is set based on status mapping table below
Failures and errors are reported as Run Level comments
If the same file is uploaded again, the cases will be identified using the automation key (
classname.name )
and would be updated, instead of creating new cases.
...
Status Mapping JUnit → AIO Tests
JUnit XML | Description | AIO Tests Mapping |
---|---|---|
No tag inside <testcase> means Passed | Passed case | Passed |
</skipped> | Skipped case either by @Ignore or others | Not Run |
</failure> |
| Failed |
</error> |
| Failed |
Reporting results via WebdriverIO Mocha Hooks and AIO Tests REST APIs
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.
AIO Tests also provides APIs to create cycles and to add cases to cycles for execution planning.
The basic sample below will show how Mocha Hooks in WebdriverIO can leverage the AIO Tests REST APIs to report results. In the wdio.conf.js, the afterTest
method can be used to make AIO API call.
...
For the purpose of the example, we have established a convention to map cases - the AIO Tests case key is the prefix to the case title ege.g. it('NVPROJ-TC-11: should login with valid credentials'
contains NVPROJ-TC-11, which is the AIO Tests Case key.
...
In the example below, the postResults
method uses Axios to make an HTTP call.
It uses the test title to identify the case key [ based on the convention we established]
Create a POST request
URL : For cloud the
...
URL host would be
https://tcms.
...
aiojiraapps.com/aio-tcms/api/v1
. For Jira server, it would be the native Jira server hostname.Authorization : Please refer to Rest API Authentication to understand how to authorize users. The authentication information goes in the
headers: {'Authorization': '<Auth based on Jira Cloud/Jira Server>'},
POST Body : The body consists of data from the test object provided by Webdriver IO. If the case has failed, the error is posted as comments.
If required, the basic example can be extended to upload attachments against the case using the upload attachment API.
Code Block | ||
---|---|---|
| ||
const axios = require('axios'); const chalk = require('chalk'); exports.config = { // // ==================== // Runner Configuration // ==================== // afterTest: function(test, context, { error, result, duration, passed, retries }) { return this.postResults(test, {error, duration, passed}); }, postResults(test, { error, duration, passed }) { if(test.title.startsWith("NVPROJ-TC-")) { let tc = test.title.split(":")[0] console.log(chalk.hex('#0094a6').underline.bold("Reporting results ..." + tc)) let resultData = {"testRunStatus": passed? "Passed":"Failed", "effort": duration/1000}; if(!passed) { resultData["comments"] = [error.matcherResult.message] } return axios({ method: 'post', url: `https://tcms.aioreportsaiojiraapps.com/aio-tcms/api/v1/project/NVPROJ/testcycle/NVPROJ-CY-48/testcase/${tc}/testrun`, headers: {'Authorization': '<Auth based on Jira Cloud/Jira Server>'}, data :resultData }) .then(function (response) { console.log(response.data) }).catch((e) => console.log(e)); } } |
Running the above in the afterTest method, will result in 2 cases being added to cycle NVPROJ-CY-48
.
NVPROJ-TC-11: should login with valid credentials
- NVPROJ-TC-11 will be added to cycle with status as passed and duration.NVPROJ-TC-12: should login with invalid credentials
- NVPROJ-TC-12 will be added to cycle with status as Failed and comments would hold the error messages.
Info |
---|
The above is a basic example of what can be done with the hooks and AIO Tests APIs. It is recommended to add appropriate error handling and enhance it based on your automation requirements. |
...