kuceb / cypress-plugin-retries

A Cypress plugin to retry failed tests.
MIT License
237 stars 20 forks source link

Retry with option to set intervals #52

Closed volkanogretmen closed 4 years ago

volkanogretmen commented 4 years ago

I love using this plugin! The only that could make it even better from my point of view is the need to set an interval or "cool-down-period" before commencing the next retry.

So this: Cypress.currentTest.retries(3)

Could perhaps look like this: Cypress.currentTest.retries(3, 3000)

Where 3000 stands for ms to wait until next retry is kicked-off.

kuceb commented 4 years ago

here's an example of how to do that:

/// <reference types="cypress" />

Cypress.on('test:before:run:async', () => {
  if (Cypress.currentTest.currentRetry() > 0) {
    return new Promise((resolve) => setTimeout(resolve, 2000))
  }
})

describe('Some flaky suite', () => {
  let counter = 0

  beforeEach(() => {
    Cypress.currentTest.retries(4)
  })

  it('should pass on 3rd attempt', () => {
    counter++
    expect(counter === 3, 'some flaky assertion').eq(true)
  })
})