All Collections
Automation & API
Integrations
Integration with an external defects management tool using TestCollab API
Integration with an external defects management tool using TestCollab API

An illustration that runs you through the process of custom integration with Trello as defects manager

Vishal Vaswani avatar
Written by Vishal Vaswani
Updated over a week ago

This illustration uses Trello as defects manager to get new cards created on the basis of test cases failed in TestCollab.

Steps involved:

  • Fetching details of test cases that have failed under a test plan that are assigned to a particular tester in TestCollab

  • Posting an issue in Trello on basis of test case details fetched

  • Create a corresponding issue in TestCollab to track Trello card within TestCollab (optional)

Assumptions

  • An API token has been generated in TestCollab for the user who has rights to post new issues in the concerned project

  • API key and API token have also been acquired for Trello

  • TestCollab project has inbuilt defects management enabled (optional, only if you want to keep a linked record). In this example link for Trello cards has been opted so we used 3 custom fields for issues and named them as

    • Issue Manager,

    • Defect Id,

    • Defect URL

Here is the sample code...

const axios = require('axios');

async function reportDefect() {

let jsonString = [];
let defect = {
title: "",
desc: ""
};

let TestCollabAPIToken = "abcdef54Ijkl321";
let TestCollabProject = 1001;
let TestCollabTestPlan = 1001;
let TestCollabAssignedTo = 1001; //optional

/* Fetching details of failed test case from TestCollab begins */
await axios.get('https://api.testcollab.io/executedtestcases?token=' + TestCollabAPIToken + '&project=' + TestCollabProject + '&test_plan=' + TestCollabTestPlan + '&status=2&assigned_to=' + TestCollabAssignedTo)
.then((response) => {
jsonString = JSON.stringify(response.data);
try {
const testcases = JSON.parse(jsonString);
testcases.forEach(async testcase => {
defect.title = testcase.test_case_revision.title + " (id:" + testcase.id + ") failed";
defect.desc = "Steps: \n";
let step_cnt = 1;
testcase.step_wise_result.forEach(stepWiseResult => {
defect.desc = defect.desc + step_cnt++;
defect.desc = defect.desc + "Step: ";
defect.desc = defect.desc + stepWiseResult.step;
defect.desc = defect.desc + "Expected result: ";
defect.desc = defect.desc + stepWiseResult.expected_result;
defect.desc = defect.desc + "Status: ";
switch (stepWiseResult.status) {
case 0:
defect.desc = defect.desc + "Unexecuted";
break;
case 1:
defect.desc = defect.desc + "Passed";
break;
case 2:
defect.desc = defect.desc + "Failed";
break;
case 3:
defect.desc = defect.desc + "Skipped";
break;
case 4:
defect.desc = defect.desc + "Blocked";
break;

}
if (stepWiseResult.comment != undefined) {
defect.desc = defect.desc + "Comment: ";
defect.desc = defect.desc + stepWiseResult.comment;
}
});
if (testcase.attachments != undefined) {
defect.desc = defect.desc + "Attchment: ";
testcase.attachments.forEach(attachment => {
defect.desc = defect.desc + attachment.url;
});
}
/* Fetching of failed test case from TestCollab ends */

/* Adding card in Trello begins */
TrelloAPIToken = "ATTA987534JRNFOIU9834R534IORJNERWKJFH8934UROI34NFKSDJFN893489423R";
TrelloAPIKey = "msf8iu43r5345uokfjf943r509";
TrelloList = "52sldkifjosif93484";
//Cleaning up
defect.desc = defect.desc.replaceAll('"', '').replaceAll('"', '\"');
await axios.post("https://api.trello.com/1/cards?idList=" + TrelloList + "&key=" + TrelloAPIKey + "&token=" + TrelloAPIToken + "&name=" + defect.title + "&desc=" + defect.desc)
.then(async (postResponseTrello) => {
console.log("Process of adding a new card in Trello completed successfully");
/* Adding issue in TestCollab begins... This part is optional */
await axios.post("https://api.testcollab.io/issues?token=" + TestCollabAPIToken, {
"title": postResponseTrello.data.name,
"project": TestCollabProject,
"description": postResponseTrello.data.desc,
"attachments": [],
"custom_fields": [{
"name": "Issue Manager_text",
"id": 859,
"label": "Issue Manager",
"valueLabel": "",
"color": "",
"value": "Trello"
}, {
"name": "Defect Id_text",
"id": 860,
"label": "Defect Id",
"valueLabel": "",
"color": "",
"value": postResponseTrello.data.id
}, {
"name": "Defect URL_url",
"id": 861,
"label": "Defect URL",
"valueLabel": "",
"color": "",
"value": postResponseTrello.data.url
}]
}).then((postResponseTestCollab) => {
console.log("Process of adding issues data in TestCollab completed successfully");
}).catch((err) => {
console.log("Error while adding issues data in TestCollab " + err);
});
/* Adding issue in TestCollab ends */
})
.catch((err) => {
console.log("Error while posting defect in Trello " + err);
})
/* Adding card in Trello ends */
});
} catch (err) {
console.log('Error after processing test cases data received from TestCollab: ', err);
}
})
.catch((err) => {
console.error('Error retrieving data from TestCollab: ${err}');
});
}
reportDefect();

Note: Please replace the values according to your environment for variables having

  • API token,

  • Project,

  • Test plan,

  • Assignee in TestCollab

And

  • API key,

  • API token,

  • List that will hold the reported card in Trello.

Did this answer your question?