How do I enable test retries in Playwright Test and detect retries at runtime?


To enable test retries in @playwright/test, you can configure them in the configuration file or use the command line option --retries=<number of retries>. This allows failing tests to be retried multiple times until they pass or reach the maximum number of retries.

For example, in your playwright.config.ts file, you can set the retries option:

import { PlaywrightTestConfig } from '@playwright/test';

const config: PlaywrightTestConfig = {
  retries: 3,

export default config;

Alternatively, you can use the command line option:

npx playwright test --retries=3

To detect retries at runtime, you can access testInfo.retry in any test, hook, or fixture. This can be useful for clearing server-side state before a retry. For example:

import { test } from '@playwright/test';

test('My Test', async ({ page, testInfo }) => {
  if (testInfo.retry) {
    // Clear server-side state before retry
    await page.goto('https://ray.run/clear-state');

  await page.goto('https://ray.run');
  // Perform your test actions

Remember, you can also reuse a single Page object between multiple tests by creating your own in test.beforeAll() and closing it in test.afterAll(). This allows you to share state between tests and reduce setup time.

Thank you!
Was this helpful?
Still have questions?

If you still have questions, please ask a question and I will try to answer it.

AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email luc@ray.run.