Skip to content
This repository has been archived by the owner on May 24, 2021. It is now read-only.

inconsistent screenshot filenames #10

Open
lukeapage opened this issue Apr 29, 2019 · 7 comments
Open

inconsistent screenshot filenames #10

lukeapage opened this issue Apr 29, 2019 · 7 comments
Labels

Comments

@lukeapage
Copy link

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
Copy link
Author

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)

@kuceb
Copy link
Owner

kuceb commented Apr 29, 2019

@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

@lukeapage
Copy link
Author

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

@kuceb
Copy link
Owner

kuceb commented May 1, 2019

see my edited comment here cypress-io/cypress#3968 (comment)

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

@lukeapage
Copy link
Author

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

@kuceb kuceb added the cantfix label Oct 21, 2019
@pvishnu991
Copy link

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.

@Cubo25
Copy link

Cubo25 commented Aug 4, 2020

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants