microsoft / microsoft/playwright

[Feature]: Allow individual test steps to be retried

Open
#41,298 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

feature-test-runner
Dominant language
TypeScript
Stars
96.3k
Forks
6.5k
Avg merge
1d 6h
Merged PRs (30d)
180

Description

### 🚀 Feature Request

I'd like to propose adding an option `retry: boolean` to test steps.
This way a whole group of actions could be retried instead of only individual ones, using steps would also enforcing a title on what they're doing.
If `retry` is set to true playwright would automatically retry the whole step until it passes or the timeout is exceeded.

### Example

```ts
test("Reply to message", async ({ page }) => {
// If clicking the element fails, hovering will be retried as well
test.step("Reply to message", async () => {
const messageItem = page.getByText("Test Message");
await messageItem.hover({ timeout: 2_000 });
await messageItem.getByRole("button", { name: "Reply" }).click({ timeout: 2_000 });
}, { box: true, retry: true, timeout: 20_000 });
});
```

### Motivation

I recently came across the issue that I needed to hover an element and then click a button inside the tooltip which would appear during hover. However, in some cases it could happen that the hovered element would move, closing the tooltip. Playwrights automatic retries are amazing for making single interactions retrieable but lack the option to create custom "transactions" containing multiple actions.

Creating such transactions is already possible by utilizing `expect().toPass()`, but it always feels "hacky" to use an assertion just to retry something.

With this proposal creating transactions would be possible without the need to create an assertion for them.
Please let me know what you think, I'm also open for other syntax suggestions on how this might be archived. :)

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 reviewing the existing test.step API and expect().toPass(), which the issue identifies as the current workaround. Define the retry behavior, timeout handling, and step options needed for a complete transaction-level retry, with done meaning grouped actions can retry without using an assertion.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
testing-qa
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.