question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Retries and before each not working

See original GitHub issue

When having an integration/e2e test it might happen that beforeEach could fail. In the example from the documentation: https://mochajs.org/#retry-tests

describe('retries', function() {
  // Retry all tests in this suite up to 4 times
  this.retries(4);

  beforeEach(function() {
    browser.get('http://www.yahoo.com');
  });

  it('should succeed on the 3rd try', function() {
    // Specify this test to only retry up to 2 times
    this.retries(2);
    expect($('.foo').isDisplayed()).to.eventually.be.true;
  });
});

It could happen that browser.get fails and we need a retry. Currently, one could have “browser.get” inside the it, but that does not allow to reuse code across tests.

I’d be interested in doing:

beforeEach(function() {
    this.retries(2)
    browser.get('http://www.yahoo.com');
  });

Not sure that it makes 100% sense. If it does not make sense, maybe it would be possible to change the documentation, since it can be slightly misleading:

This feature does re-run beforeEach/afterEach hooks but not before/after hooks.

It could either mean that retries affect beforeEach, or what it actually means, that if the test fails then beforeEach will be executed again.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
juergbacommented, Feb 7, 2020

this.retries() has no effect on failing hooks. No hooks or tests will be re-run.

this.retries() does re-run a failing test it()

  • incl. its corresponding beforeEach and afterEach hooks
  • excl. before and after hooks
0reactions
juergbacommented, Feb 10, 2020

We updated our docs accordingly, thank you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cypress E2E: Before hook not working on retries
As a workaround you can use a beforeEach: let isError = false; beforeEach(() => { cy.once('fail', (err) => { isError = true; throw ......
Read more >
Test Retries - Cypress Documentation
However, failures in before and after hooks will not trigger a retry. The following is a detailed step-by-step example of how test retries...
Read more >
Getting Started - CodeceptJS
If you have a step which often fails, you can retry execution for this single step. Use the retry() function before an action...
Read more >
Retry Flaky Tests - WebdriverIO
In order to use the this.retries() method, the suite block describe must use an unbound function function(){} instead of a fat arrow function ......
Read more >
Timeouts, retries and backoff with jitter - AWS
To avoid this problem, we employ jitter. This is a random amount of time before making or retrying a request to help prevent...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found