Retry Tests

优质
小牛编辑
121浏览
2023-12-01

You can choose to retry failed tests up to a certain number of times. This feature is designed to handle end-to-end tests (functional tests/Selenium…) where resources cannot be easily mocked/stubbed. It’s not recommended to use this feature for unit tests.

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

NOTE: Example below was written using Selenium webdriver (which overwrites global Mocha hooks for Promise chain).

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