Playwright · Reliable end-to-end tests

Should you use retries, and how do they work?

Mediumretriesflaky testsciUpdated Oct 2026
Quiz this track

Short answer

Retries rerun failed tests to absorb infrastructure noise, but they can hide real bugs. Use a small count, capture a trace on the first retry, and track flaky tests instead of accepting them.

A retry is a second attempt at a failed test. It is useful when the failure came from infrastructure such as a slow network or a temporarily unavailable service. It is harmful when it turns a genuine product defect into a passing run.

ts
export default defineConfig({
  retries: process.env.CI ? 2 : 0,
  use: {
    trace: "on-first-retry",
  },
});
A small CI retry count with trace on the first retry gives evidence without masking every failure.

Rules of thumb

  • Use zero retries locally so flakes are visible during development
  • Use a small count in CI, often one or two, and alert when it is exhausted
  • Record a trace and screenshot on the retry, not on every passing run
  • Track which tests needed a retry and fix the root cause
  • Never use retries to make an order-dependent suite look stable
  • testInfo.retry exposes the current attempt count when behaviour must differ
ts
test("uploads a report", async ({ page }, testInfo) => {
  if (testInfo.retry > 0) {
    await page.context().clearCookies();
  }

  await page.goto("/reports");
  await page.getByLabel("File").setInputFiles("fixtures/report.csv");
  await page.getByRole("button", { name: "Upload" }).click();

  await expect(page.getByText("Upload complete")).toBeVisible();
});
Retry-aware setup should be rare; if a test needs it, that is a strong signal of a state leak.
A retried pass is still a flaky test. Report it even when the pipeline is green, otherwise the team learns to ignore the problem until it becomes an outage.

Follow-ups you should expect

Interviewers use these to check whether the first answer was understanding or memorisation.

  1. 1Why use zero retries locally?
  2. 2What does testInfo.retry tell you?
  3. 3How do retries hide real bugs?
  4. 4What should you record when a retry happens?

Say it in the interview

I use retries as a small buffer for infrastructure noise, usually zero locally and one or two in CI. I record a trace on the first retry so there is evidence, and I track tests that only pass on retry instead of treating the green run as success. Retries should never be a substitute for fixing an order dependency or a race. If a test needs retry-specific setup, I look for the state leak.

Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.

Related questions

Reading is step one

Now say it out loud.

Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live Playwright mock interview and get scored feedback on depth, clarity and confidence.