Rayrun

How do I enable test retries in Playwright after a failure?

Answer

To enable test retries in @playwright/test after a failure, you can use the --retries flag when running tests or configure retries in the playwright.config.ts file.

Using the --retries flag

Run your tests with the --retries flag followed by the number of retry attempts you want to allow. For example, to give failing tests three retry attempts, run:

npx playwright test --retries=3

Configuring retries in playwright.config.ts

Set the number of retries in your playwright.config.ts file:

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

const config: PlaywrightTestConfig = {
  retries: 3,
};

export default config;

This will give failing tests three retry attempts.

Understanding test categories

@playwright/test categorizes tests as "passed", "flaky", or "failed". Tests that pass on the first run are "passed". Tests that fail initially but pass when retried are "flaky". Tests that fail on all retries are "failed".

Retries and worker processes

When a test fails and retries are enabled, @playwright/test discards the worker process along with the browser and starts a new one. Testing continues in the new worker process, starting with the next test. The second worker process begins by retrying the failed test and continues from there.

Accessing retry information

You can detect retries at runtime with testInfo.retry, which is accessible to any test, hook, or fixture. You can also specify retries for a specific group of tests or a single file using test.describe.configure().

Thank you!
Was this helpful?
Still have questions?

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

TwitterGitHubLinkedIn
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.