I have to add the URL of failed test case in Mochawesome Report so we could get the draft URL.
Below is my spec file where I’m adding URL through addContext() statement on end of every test if test is failing. and it’s working fine.
it("Create Register User Order", () => {
orderRegions = 'Rest of World'
createOrder.clickCreateOrderButton()
createOrder.getUrl().then(result => {
draftURL = result
})
Cypress.on('test:after:run', (test) => {
if(test.state==='failed'){
addContext({ test }, {
title: 'here is the link to access DraftOrder:', value: `${draftURL}`
})
})
})
})
But instead of pasting at the end of everyTest I’m trying to put it inside e2e.js
file
Cypress.on('test:after:run', (test) => {
if(test.state==='failed'){
addContext({ test }, {
title: 'here is the link to access DraftOrder:', value: `${test.draftURL}`
})
})
})
But it’s not working and displaying undefined on place of draftLink.
How we can pass the variable value from spec file test to e2e.js file, or how we can fetch the URL of browser when test was failed?