Why can't I take screenshots with Cypress + TypeScript?

Why can’t I use Cypress + TypeScript to take screenshots?

Hi Matthew!

You can configure your TypeScript Cypress repo to take screenshots automatically with test failures on LT by adding the below snippet to their test cases:

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

}

});

ref: https://github.com/mayank2193/Cypress-Typescript