From 81c4e9c2c1d879e401c19c854cc0df429d564746 Mon Sep 17 00:00:00 2001 From: Andy Balaam Date: Thu, 16 Apr 2026 16:20:25 +0100 Subject: [PATCH] Default to 2 second wait for IfExists variants --- packages/playwright-common/src/fixtures/toasts.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/playwright-common/src/fixtures/toasts.ts b/packages/playwright-common/src/fixtures/toasts.ts index d4de827919..259eb43295 100644 --- a/packages/playwright-common/src/fixtures/toasts.ts +++ b/packages/playwright-common/src/fixtures/toasts.ts @@ -44,7 +44,9 @@ class Toasts { * * @param title - Expected title of the toast. * @param timeout - Time in ms before we give up and decide the toast does - * not exist. Defaults to `timeout` in `TestConfig.expect`. + * not exist. If `required` is true, defaults to `timeout` + * in `TestConfig.expect`. Otherwise, defaults to 2000 (2 + * seconds). * @param required - If true, fail the test (throw an exception) if the * toast is not visible. Otherwise, just return null if * the toast is not visible. @@ -58,6 +60,10 @@ class Toasts { await expect(toast).toBeVisible({ timeout }); return toast; } else { + // If we don't set a timeout, waitFor will wait forever. Since + // required is false, we definitely don't want to wait forever. + timeout = timeout ?? 2000; + try { await toast.waitFor({ state: "visible", timeout }); return toast; @@ -126,7 +132,9 @@ class Toasts { * "primary", which will accept the toast, or "secondary", * which will reject it. * @param timeout - Time in ms before we give up and decide the toast does - * not exist. Defaults to `timeout` in `TestConfig.expect`. + * not exist. If `required` is true, defaults to `timeout` + * in `TestConfig.expect`. Otherwise, defaults to 2000 (2 + * seconds). * @param required - If true, fail the test (throw an exception) if the * toast is not visible. Otherwise, just return after * `timeout` if the toast is not visible.