microsoft / microsoft/playwright

[Feature]: Conditional retries

Open
#42,725 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

needs-triage-mac P3-collecting-feedback
Dominant language
TypeScript
Stars
96.3k
Forks
6.5k
Avg merge
1d 6h
Merged PRs (30d)
180

Description

🚀 Feature Request

Ability to provide a custom function that can decide whether the test should be retried or not, based on previous attempts.

Nice to have: ability to provide custom retry strategy as well.

Example

Usage example could be sth like this:

{
  retries: 3, // max number of retries
  retryStrategy: 'immediate',
  retryIf: (testInfo, errors) => {
    if (testInfo.retry <= 1) return true; // always retry at least once

    const errorsToRetry = [/Target crashed/, /browser has been closed/, /* ... */];
    for(const pattern of errorsToRetry) {
      if (errors.at(-1).match(pattern)) return [true, 'isolated']; // retry with strategy "isolated" if the error seems to be caused by env instability
    }
    return false; // don't retry more than once on other errors
  }
}
Motivation

In projects where lots of tests are being run periodically (my case: ~6000), sometimes it's just the remote cluster having hiccups and the entire run fails because of it. It disrupts devs' work and takes unnecessary time to keep checking those errors and retrying the entire ~2h pipeline because of an unexpected browser crash.

Why not just put retries: 5 or so? Because then it eats up unnecessary time and resources when there are genuine failures, especially on pipelines like ones checking PRs etc, that are expected to just have lots of genuinely failing tests.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing Playwright's existing retry configuration and test-runner retry handling. Use the issue's retryIf and retryStrategy example to define the supported callback inputs, return values, and strategy behavior, then verify that conditional retries and custom strategies work without adding unnecessary retries for genuine failures.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
testing-qa
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.