Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

_currentRetry value in beforeEach hook is always 0 #14783

Closed
adesko opened this issue Jan 27, 2021 · 5 comments
Closed

_currentRetry value in beforeEach hook is always 0 #14783

adesko opened this issue Jan 27, 2021 · 5 comments
Labels
type: duplicate This issue or pull request already exists

Comments

@adesko
Copy link

adesko commented Jan 27, 2021

The issue

We use a command to reset the database before each spec is run. Unfortunately, it is quite slow (takes about 7 seconds to reset DB fixtures), so we can't really execute it in a beforeEach hook as that would slow down the tests significantly. However, if a test fails mid-execution, it can make some changes in the database that will prevent the test from retrying.
I wanted to make a workaround where i would execute the DB reset command in a beforeEach hook if the current attempt counter is above 0, but that didn't work (see current behavior below).
If there is any other way to make this work, please let me know.

Current behavior

When accessing attempt counter in the beforeEach hook (as described here), the attempts counter is 0 regardless of actual attempt count.

изображение

Desired behavior

Since the beforeEach hook is executed for each test attempt, i expected the attempt counter to contain current attempt counter.

Test code to reproduce

describe('Home page', () => {
    beforeEach(() => {
        console.log('---Start new attempt---');
        const attempt = cy.state('runnable')._currentRetry;
        console.log('Attempt count in "beforeEach": ' + attempt);
    });
    it.only('Opens homepage', {
        retries: {
            openMode: 1,
        },
    }, () => {
        cy.visit('https://github.com');
        cy.contains('not github');
        const attempt = cy.state('runnable')._currentRetry;
        console.log('Attempt count in test: ' + attempt);
    });
});

Versions

6.3.0

@B4Art
Copy link

B4Art commented Jan 27, 2021

I am not an expert, but I am missing somethin like:

const retries = cy.state('runnable')._retries

or:

const retries = Cypress._.get(cy.state('runnable'), '_retries', 0)

Which is on the page you are referring to. Does that have anything todo with this?

@adesko
Copy link
Author

adesko commented Jan 28, 2021

I am not an expert, but I am missing somethin like:

const retries = cy.state('runnable')._retries

or:

const retries = Cypress._.get(cy.state('runnable'), '_retries', 0)

Which is on the page you are referring to. Does that have anything todo with this?

I'm pretty sure this is just to access the total number of retries possible, and has nothing to do with what i'm describing

@MDG-JHowley
Copy link

@adesko I have testing using this solution and it seems to work: #8404 (comment)

perhaps the documentation should be expanded to reference this? FYI cy.state has open ticket for documentation... (cypress-io/cypress-documentation#108)

@adesko
Copy link
Author

adesko commented Feb 18, 2021

@MDjhowley Thanks for the reply! However, i already implemented another solution using the cypress module that re-runs failed specs.

@sainthkh
Copy link
Contributor

sainthkh commented May 4, 2021

Sorry for the late reply. Closing in favor of #8404.

@sainthkh sainthkh closed this as completed May 4, 2021
@sainthkh sainthkh added the type: duplicate This issue or pull request already exists label May 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

4 participants