Playwright · Reliable end-to-end tests
Should you use retries, and how do they work?
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.
export default defineConfig({
retries: process.env.CI ? 2 : 0,
use: {
trace: "on-first-retry",
},
});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.retryexposes the current attempt count when behaviour must differ
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();
});Follow-ups you should expect
Interviewers use these to check whether the first answer was understanding or memorisation.
- 1Why use zero retries locally?
- 2What does testInfo.retry tell you?
- 3How do retries hide real bugs?
- 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.