I was trying to find a method to update my Cypress test execution into Zephyr Scale. I do not need to update the test step. I just need to update the related test cases for traceability and reporting purposes.
So this is my solution and some points before you can use it;
The code I wrote is placed in a Cypress
afterEach()
hook. By doing so, every time Cypress finish executing one of the tests, the result will get updated into Zephyr.The test name as used in Cypress MUST have the Zephyr Test Case ID else the script won't work
afterEach(function() {
console.log(this.currentTest.state)
const pattern = /PROJECTCODE-T\d+/;
const match = this.currentTest.title.match(pattern)
console.log(match[0])
const token = Cypress.env('bearerToken')
const url = Cypress.env('zephyrBaseURL') + '/testexecutions'
const testCycle = Cypress.env('testCycle')
if(this.currentTest.state === 'passed'){
cy.then(() => {
cy.request({
headers: {
Authorization: `Bearer ${token}`
},
url: `${url}`,
method: 'POST',
body: {
projectKey: "PROJECTCODE",
testCaseKey: `${match[0]}`,
testCycleKey: `${testCycle}`,
statusName: "Pass",
environmentName: "QA"
}
})
})
}else if (this.currentTest.state === 'failed')
{
cy.then(() => {
cy.request({
headers: {
Authorization: `Bearer ${token}`
},
url: `${url}`,
method: 'POST',
body: {
projectKey: "ALT",
testCaseKey: `${match[0]}`,
testCycleKey: `${testCycle}`,
statusName: "Fail",
environmentName: "QA"
}
})
})
}else if (this.currentTest.state === 'skipped')
{
cy.then(() => {
cy.request({
headers: {
Authorization: `Bearer ${token}`
},
url: `${url}`,
method: 'POST',
body: {
projectKey: "ALT",
testCaseKey: `${match[0]}`,
testCycleKey: `${testCycle}`,
statusName: "Not Executed",
environmentName: "QA"
}
})
})
}
})
Appreciate any suggestion to improve the implementation. Thanks