How to capture Screen automatically on failure for Typescript Cypress?
Hi Toby,
Please add the below code snippet into your cypress/support/index.js to automatically capture the screen for TypeScript Cypress:
import addContext from "mochawesome/addContext";
Cypress.on("test:after:run", (test, runnable) => {
if (test.state === "failed") {
let item = runnable;
const nameParts = [runnable.title];
// Iterate through all parents and grab the titles
while (item.parent) {
nameParts.unshift(item.parent.title);
item = item.parent;
}
const fullTestName = nameParts.filter(Boolean).join(" -- "); // this is how cypress joins the test title fragments
const imageUrl = `${fullTestName} (failed).png`;
addContext({ test }, imageUrl);
}
});