How to capture the screen automatically when TypeScript Cypress fails?

How to capture the screen automatically when TypeScript Cypress fails?

Hi Ian,

Here is the code snippet to capture the screen automatically when TypeScript Cypress fails:

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);
}
});