🔭 Want to automate and scale your Playwright end-to-end tests?
Head over to Better Stack and start monitoring in 5 minutes.
Playwright offers a variety of timeout configurations for different operations. The standard timeout for each test is set to 30 seconds, and for each assertion, it's 5 seconds.
Encountering errors like the ones below could indicate that your timeout settings may require adjustments:
example.spec.ts:3:1 › sample test ===========================
Timeout of 30000ms exceeded.
example.spec.ts:3:1 › sample test ===========================
Error: expect(received).toHaveText(expected)
Expected string: "my text"
Received string: ""
Call log:
- expect.toHaveText with timeout 5000ms
- waiting for "locator('button')"
To alter the default global timeout for all tests, do the following:
import { defineConfig } from '@playwright/test';
export default defineConfig({
timeout: 60 * 1000, // 60 seconds
});
Similarly, to modify the default global timeout for expect assertions, use this approach:
import { defineConfig } from '@playwright/test';
export default defineConfig({
expect: {
timeout: 10 * 1000, // 10 seconds
},
});
For adjusting the timeout of a single test, apply the following methods:
import { test, expect } from '@playwright/test';
test('slow test', async ({ page }) => {
// Triples the test timeout (90 seconds by default)
test.slow();
});
test('really slow test', async ({ page }) => {
// set timeout to 120 seconds
test.setTimeout(120 * 1000);
});
Likewise, you can change the timeout for a specific assertion like this:
import { test, expect } from '@playwright/test';
test('basic test', async ({ page }) => {
await expect(page.getByRole('button')).toHaveText('Sign in', {
timeout: 10000,
});
});
Playwright also allows for customization of timeout settings for actions, navigation, test hooks, and the overall test suite. Comprehensive details can be found in the test timeout documentation.
Thanks for reading, and happy coding!
Head over to Better Stack and start monitoring in 5 minutes.
Checking or asserting on the value of any element is straightforward in Playwright
Retrieving attributes on web page elements is really straightforward through the `getAttribute()` method
Retrieving the current page's URL is straightforward in Playwright using `page.url()`
Manually pausing Playwright tests is only recommended when troubleshooting a test. Here's how to do with with the `waitForTimeout()` method