_currentRetry value in beforeEach hook is always 0
See original GitHub issueThe 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
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:5
@adesko I have testing using this solution and it seems to work: https://github.com/cypress-io/cypress/issues/8404#issuecomment-680122825
perhaps the documentation should be expanded to reference this? FYI
cy.state
has open ticket for documentation… (https://github.com/cypress-io/cypress-documentation/issues/108)Sorry for the late reply. Closing in favor of #8404.