Back to All Questions
Question 46 of 100
Configuration
Intermediate
How can users change the default timeout for assertions in Playwright?
The Answer
The assertion timeout (how long Web-First assertions retry) defaults to 5 seconds. You can change it globally in `playwright.config.ts` or per-assertion.
Deep Dive Explanation
Never set timeouts too high as a workaround for slow apps β it inflates test execution time. Instead, investigate WHY the element is slow to appear (API delay? animation?) and address the root cause. Use per-assertion overrides only for known slow operations like file processing or email delivery.
example.spec.ts
// 1. Global: playwright.config.ts
export default defineConfig({
expect: {
timeout: 10000, // All assertions wait up to 10s
},
});
// 2. Per-assertion override
await expect(page.locator('.slow-widget')).toBeVisible({ timeout: 30000 });
// 3. Change default globally at runtime
expect.configure({ timeout: 15000 });
// 4. Reset to default
expect.configure({ timeout: 5000 });