Versions Compared

Key

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

...

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

Table of Contents
minLevel1
maxLevel7

Nightwatch + Cucumber Setup

...

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.

...

Code Block
breakoutModewide
languagejs
//aio-reporting.js
const {AfterAll} = require('@cucumber/cucumber');
const fs = require("fs");
const FormData = require('form-data');
const axios = require('axios');

const AIO_API_BASEURL = "https://tcms.aioreportsaiojiraapps.com/aio-tcms/api/v1/project"
const JIRA_PROJ = "NVTES"
const AIO_API_KEY = "yourapikey"

AfterAll(  function() {
    console.log("Reporting results to AIO Tests")
    //timeout is important - since the report gets generated in some time
    setTimeout(() => {
        let promises = [];
        fs.readdirSync("./report/").forEach(file => {
            console.log("Uploading file to AIO" + file)
            var bodyFormData = new FormData();
            bodyFormData.append('file', fs.createReadStream("./report/" + file));
            bodyFormData.append('createCase', 'true');
            bodyFormData.append('bddForceUpdateCase','true');
            promises.push(axios.post(`${AIO_API_BASEURL}/${JIRA_PROJ}/testcycle/NVTES-CY-666/import/results?type=Cucumber`,
                bodyFormData, {
                    headers: {
                        'Authorization': `AioAuth ${AIO_API_KEY}`,
                        'Content-Type': 'multipart/form-data'
                    }
                }).then(function (response) {
                console.log(response.data)
            }).catch((e) => console.log(e.response.data)))
        });
        return Promise.all(promises);
    }, 2000);
});

...

Code Block
breakoutModewide
languagejs
//aio-reporting.js
const {After} = require('@cucumber/cucumber');
const axios = require('axios');

const AIO_API_BASEURL = "https://tcms.aioreportsaiojiraapps.com/aio-tcms/api/v1/project"
const JIRA_PROJ = "NVTES"
const AIO_API_KEY = "your key"

After(async function (scenario) {

    const aioCaseKeys = [];
    await fetchAIOCases(scenario.pickle.tags, aioCaseKeys)

    if (aioCaseKeys.length) {
        await markCaseResult(scenario, aioCaseKeys)
    }
    return;
})

async function fetchAIOCases(scenarioTags, aioCaseKeys) {
    for (const t of scenarioTags) {
        if (t.name.startsWith("@MGM-")) {
            let searchQuery = {
                "automationKey": {
                    "comparisonType": "EXACT_MATCH",
                    "value": t.name.substring(1)
                }
            };
            const caseSearchResponse = await axios({
                method: 'post',
                url: `${AIO_API_BASEURL}/${JIRA_PROJ}/testcase/search`,
                headers: {'Authorization': `AioAuth ${AIO_API_KEY}`},
                data: searchQuery
            })
            if (caseSearchResponse.data.items?.length) {
                caseSearchResponse.data.items.forEach(i => aioCaseKeys.push(i.key));
            }
        }
    }
}

async function markCaseResult(scenario, aioCaseKeys) {
    let bulkUpdateRequest = {"testRuns": []};
    for (const aioCaseKey of aioCaseKeys) {
        let caseStatus = {
            "testCaseKey": aioCaseKey,
            //Can be enhanced based on statuses
            "testRunStatus": scenario.result.status === 'PASSED' ? "Passed" : scenario.result.status === "FAILED" ? "Failed": "Not Run",
            //comments can be added
            "effort": scenario.result.duration.seconds
        }
        bulkUpdateRequest.testRuns.push(caseStatus);
    }
    try {
        const response = await axios({
            method: 'post',
            url: `${AIO_API_BASEURL}/${JIRA_PROJ}/testcycle/NVTES-CY-437/bulk/testrun/update`,
            headers: {'Authorization': `AioAuth ${AIO_API_KEY}`},
            data: bulkUpdateRequest
        })
    } catch (e) {
        console.log(e.response.data)
    }
}

...