← Back to library
Playwrightwaitadvancedv1.30+

Retry assertions with a custom timeout

Override the per-assertion timeout and use toPass() for complex retry scenarios.

1test('toast auto-dismisses and status becomes Ready', async ({ page }) => {
2  await page.goto('/notifications');
3  await page.getByRole('button', { name: 'Trigger notification' }).click();
4
5  // Extend the default timeout for this specific assertion
6  await expect(page.getByTestId('toast')).toBeHidden({ timeout: 10_000 });
7
8  // toPass() retries the callback until it stops throwing — great for
9  // composite assertions that can't use a single locator
10  await expect(async () => {
11    const text = await page.locator('[data-testid="status"]').textContent();
12    expect(text).toBe('Ready');
13  }).toPass({ timeout: 15_000, intervals: [500, 1000, 2000] });
14});
#timeout#retry#toPass#custom wait#polling