Skip to content

Retry Tests

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 a failed test and its corresponding beforeEach/afterEach hooks, but not before/after hooks. this.retries() has no effect on failing hooks.

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 by the 3rd try", function () {
// Specify this test to only retry up to 2 times
this.retries(2);
expect($(".foo").isDisplayed()).to.eventually.be.true;
});
});