cypress-plugin-retries icon indicating copy to clipboard operation
cypress-plugin-retries copied to clipboard

inconsistent screenshot filenames

Open lukeapage opened this issue 5 years ago • 7 comments

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

lukeapage avatar Apr 29 '19 04:04 lukeapage

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 avatar Apr 29 '19 04:04 lukeapage

@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

kuceb avatar Apr 29 '19 12:04 kuceb

Cool, that would work for me (easy to ignore “(attempt...”)

lukeapage avatar Apr 29 '19 12:04 lukeapage

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

kuceb avatar May 01 '19 16:05 kuceb

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

lukeapage avatar May 02 '19 09:05 lukeapage

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.

pvishnu991 avatar Aug 04 '20 10:08 pvishnu991

@lukeapage Man thanks a lot ! It saved us on our project

Cubo25 avatar Aug 04 '20 10:08 Cubo25