Browser test suites sometimes fail because of timing, a busy CI worker, or a short-lived service response rather than a product regression. Playwright Test retries give a failed test a limited second chance while still labeling a retry-passed result as flaky.
The retries setting belongs in playwright.config.ts or playwright.config.js when the retry count should travel with the project. A command-line override such as --retries=1 is better for a one-time diagnostic run because it does not change the saved project policy.
Keep retry counts small and treat every flaky result as work to investigate. A retried pass still means the first attempt failed, so pair retries with traces, screenshots, or a focused debug run when the same test keeps appearing in the flaky list.
Related: How to run Playwright tests
Related: How to debug Playwright tests
Related: How to retain Playwright traces on failure
import { defineConfig } from '@playwright/test';
export default defineConfig({
testDir: './tests',
retries: 1,
});
Use retries: process.env.CI ? 2 : 0 when local runs should fail on the first attempt but CI jobs should retry transient failures.
import { test, expect } from '@playwright/test';
test('retry probe passes on retry', async ({}, testInfo) => {
expect(testInfo.retry).toBeGreaterThan(0);
});
The first attempt sees testInfo.retry as 0 and fails. The retry attempt sees 1 and passes, which gives a deterministic check of the saved retry setting.
$ npx playwright test tests/retry-probe.spec.ts --reporter=list
Running 1 test using 1 worker
✘ 1 tests/retry-probe.spec.ts:3:1 › retry probe passes on retry (6ms)
✓ 2 tests/retry-probe.spec.ts:3:1 › retry probe passes on retry (retry #1) (6ms)
##### snipped #####
1 flaky
tests/retry-probe.spec.ts:3:1 › retry probe passes on retry
The 1 flaky summary confirms that Playwright retried the first failed attempt and kept the test out of the final failed list.
Related: How to run specific Playwright tests
$ rm tests/retry-probe.spec.ts
Do not commit the probe test. It is designed to fail once so the retry path can be checked.