Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • 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

  1. npm init wdio ./path/to/new/project. On prompt to select framework, select Mocha.

  2. For reporting results

    1. For JUnit report : npm install @wdio/junit-reporter --save-dev

    2. 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

...

Uploading the above file for the first time will

  1. create new cases in the system. The new case is created with
    - title as the name value from <testcase> tag of the JUnit report
    - automation key as classname.name from the JUnit report.
    - status as Published
    - automation status as Automated
    - automation owner as user uploading the results

  2. Add the newly created case to the cycle being uploaded to

  3. Mark the details of the run

    1. Execution mode is set to Automated

    2. Duration of run is set to Actual Effort

    3. Status of run is set based on status mapping table below

    4. 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>

Indicates that the test failed. A failure is a test which the code has explicitly failed by using the mechanisms for that purpose. e.g., via an assertEquals.

Failed

</error>

Indicates that the test errored. An errored test is one that had an unanticipated problem. e.g., an unchecked throwable;

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.

  1. It uses the test title to identify the case key [ based on the convention we established]

  2. Create a POST request

    1. URL : For cloud the

...

    1. URL host would be https://tcms.

...

    1. aiojiraapps.com/aio-tcms/api/v1. For Jira server, it would be the native Jira server hostname.

    2. 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>'},

    3. 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.

    4. If required, the basic example can be extended to upload attachments against the case using the upload attachment API.

Code Block
breakoutModewide
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.

  1. NVPROJ-TC-11: should login with valid credentials - NVPROJ-TC-11 will be added to cycle with status as passed and duration.

  2. 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.

...