cypress-plugin-retries
cypress-plugin-retries copied to clipboard
inconsistent screenshot filenames
With the older retry mechanism we could clear screenshots for a spec before retrying that spec.. however with this plugin, old screenshots are not deleted before retrying the spec, which means the new screenshot just gets (1) after it and you end up with different screenshots than when the tests pass without retries
Note this is not about the (failed) screenshots which I am fine with, its about cypress not overwriting screenshots but saving to a new file with an appended (1)
@lukeapage thanks! I think we should rename the screenshots on retry, so we don't lose them. Maybe a naming scheme with (attempt 1) or something
Cool, that would work for me (easy to ignore “(attempt...”)
see my edited comment here https://github.com/cypress-io/cypress/pull/3968#issuecomment-487565281
Looks like we will not rename any screenshots after they're saved, so you may have to grep for the screenshots with the final attempt number
I did it with this plugin with this:
// in plugins
const currentScreenshots = [];
on('task', {
testStart() {
currentScreenshots.length = 0;
return null;
},
clearPreviousAttemptScreenshots() {
currentScreenshots.forEach((path) => {
fs.unlinkSync(path);
});
currentScreenshots.length = 0;
return null;
},
});
on('after:screenshot', (details) => {
currentScreenshots.push(details.path);
});
// in support
let lastTest;
beforeEach(() => {
if (lastTest === Cypress.currentTest.id) {
cy.task('clearPreviousAttemptScreenshots');
} else {
cy.task('testStart');
}
lastTest = Cypress.currentTest.id;
});
I did it with this plugin with this:
// in plugins const currentScreenshots = []; on('task', { testStart() { currentScreenshots.length = 0; return null; }, clearPreviousAttemptScreenshots() { currentScreenshots.forEach((path) => { fs.unlinkSync(path); }); currentScreenshots.length = 0; return null; }, }); on('after:screenshot', (details) => { currentScreenshots.push(details.path); });
// in support let lastTest; beforeEach(() => { if (lastTest === Cypress.currentTest.id) { cy.task('clearPreviousAttemptScreenshots'); } else { cy.task('testStart'); } lastTest = Cypress.currentTest.id; });
excellent piece of work @lukeapage . This basically worked like a charm for me.
@lukeapage Man thanks a lot ! It saved us on our project