Description
We all know that flakiness may happen from time to time, ideally, the only flakiness that we should face, is the one regarding external factors as slow machines or network issues.
With Cypress we have the test retries functionality enabled. Test retries has been configured with 1 retry attempt, Cypress will retry a failed test an additional time (for a total of 2 attempts) before potentially being marked as a failed test. When a test is re-executed, the each
hooks will be re-run as well, however, failures in before
and after
hooks will not trigger a retry and the test will be marked as failure.
So in order to have 'retriable' tests, we should get rid off the before
and after
hooks in favor of the beforeEach
and afterEach
hook. Or at least make sure that the code executed in the before
and after
hook is not prone to fail (i.e. es_archiver).
Another thing we need to take into consideration to guarantee that a test can be retried is to make sure that the data that the test might generate is properly cleaned.
Each spec file is executed on a clean environment, but, retries are not. Retries are executed on the same environment the execution was initiated, this is why is pretty important to make sure that the data the test may generate is cleaned at the beginning.