Timeouts and the priority of settings
Playwright has nested timeouts, and the first line of the error says which one fired. By default a test has 30 s, an expect assertion 5 s, and actions and navigation have no separate limit until one is set. The most specific setting wins: a call option overrides the config. A slow step is marked precisely instead of raising a global limit, and globalTimeout and maxFailures protect CI from hangs.
Playwright · Config and CI
A test failed with “Timeout exceeded”. Which limit fired, and where do you change it?
On CI a test fails, and the first line in the log is Test timeout of 30000ms exceeded. The usual reflex is to raise timeout to two minutes. The test turns green, the run gets longer, and the real cause (a button nobody can see, or a slow endpoint) has not gone anywhere. Playwright has several timeouts, each one covers its own slice of time, and the first line of the error says which one fired. This lesson teaches how to read that and tune it precisely.
How it works and why. The limits are nested. The outer one bounds the whole run, the next one each test, and inside a test actions, navigations and assertions have counters of their own. The nesting exists for diagnostics: when an inner one fires, the error names the concrete action and shows a wait log, and when only the outer one fires, you see just "did not fit".
| Timeout | Default | Where to set |
|---|---|---|
| Test (together with beforeEach and fixture setup; afterEach and fixture teardown get a separate limit of the same length) | 30 s | timeout, test.setTimeout |
The expect assertion | 5 s | expect.timeout |
| Action (click, fill) | 0, no separate limit | use.actionTimeout |
| Navigation (goto) | 0, no separate limit | use.navigationTimeout |
| The whole run | 0, no limit | globalTimeout |
The limits are nested
Example: what the first line says. A test generates a report and waits for a button. Without actionTimeout the action waits until the whole test is used up, and the error looks like this (shortened):
Error: locator.click: Test timeout of 30000ms exceeded.
Call log:
- waiting for getByRole('button', { name: 'Generate' })
The first line says time ran out in the test, not in the action, so one stuck action ate all 30 seconds. The log shows it was waiting for the locator. The same case with actionTimeout: 10_000 looks different:
Error: locator.click: Timeout 10000ms exceeded.
The failure arrives twenty seconds earlier, and the text names the action. For an assertion the form is different (shortened):
Error: expect(locator).toBeVisible() failed
Locator: getByText('Report is ready')
Expected: visible
Timeout: 5000ms
Error: element(s) not found
Hence the diagnostic table: Test timeout of … means the whole test did not fit (look at which action is in the next line); locator.click: Timeout … means the action limit fired; expect(…) failed with a Timeout: 5000ms line means the assertion never got its condition. Settings in the config:
// playwright.config.ts
export default defineConfig({
timeout: 45_000,
expect: { timeout: 7_000 },
globalTimeout: 30 * 60_000, // stop the whole run after 30 min
maxFailures: process.env.CI ? 10 : 0,
use: {
actionTimeout: 12_000,
navigationTimeout: 30_000,
},
});
And a slow but legitimate step is marked selectively, instead of raising the limit for everyone:
test('generating a large report', async ({ page }) => {
test.slow(); // this test's timeout is three times larger
await page.goto('/reports');
await page.getByRole('button', { name: 'Generate' }).click();
// only this assertion waits longer, the others stay at 5 s
await expect(page.getByText('Report is ready')).toBeVisible({ timeout: 30_000 });
});
test.describe('slow integrations', () => {
test.describe.configure({ timeout: 90_000 });
// …
});
There is also test.setTimeout(60_000) for one test and test.slow(condition, reason) for conditional cases (say, a slow browser). A long fixture setup can have its own timeout in the fixture options: then it does not eat the test's limit. Each retry gets the test timeout afresh.
Priority of settings. The same setting can be given in several places, and the most specific one wins.
Who overrides whom
--timeout and --retries override the values from the config file.test.use cannot be called in a test body, only at file or describe level: context options are needed before the context is created. test.setTimeout and test.slow affect one test and work inside it.
Limits and alternatives. A longer timeout cures only slow but real waiting. A button covered by a banner will wait 60 seconds just as well. Protection from hangs on CI comes from globalTimeout (the run stops instead of eating hours of the runner) and maxFailures (after N failures, when the environment is obviously down). In toPass the default timeout is 0, so it is set explicitly. Cypress has defaultCommandTimeout (4 s per command) and pageLoadTimeout for this; in Selenium implicit and explicit waits are configured separately, and mixing them is discouraged.
Common mistakes.
- Raising the global
timeoutto 5 minutes to make things "pass": a slow endpoint or an extra navigation gets hidden, and every real hang now costs 5 minutes. - Adding
waitForTimeoutinstead of waiting for a condition: no flexibility and no diagnostics, and in a fast environment it is just a pause. - Confusing an assertion timeout with a test timeout: an assertion waits 5 seconds even if the test has 25 left.
- Not setting
actionTimeout: a stuck action burns the whole test, and the error does not point at it at once. - Putting
test.slow()on every test of a file "just in case": tests that really hang are allowed to hang three times longer.
Check yourself
The log says: Error: locator.click: Test timeout of 30000ms exceeded. What does that say about the cause and what do you do first?
Answer
The test timeout fired, not the action's: the click got stuck and ate all 30 seconds. Read the wait log below (is the element found, is it covered) and fix the cause. It helps to set actionTimeout, so that such an action fails earlier and is named at once.
A test has 25 seconds in reserve, yet toBeVisible() fails after 5. Is that a config malfunction?
Answer
No, that is normal: an assertion has its own expect.timeout of 5 seconds, regardless of what is left of the test. If the wait is legitimately long, increase it with the option of that particular assertion.
The config has actionTimeout: 10_000, and one call has click({ timeout: 30_000 }). How long will this click wait?
Answer
Up to 30 seconds, but no longer than what is left of the test timeout. The call option overrides the config, while the test is still the outer boundary.
actionTimeout so that a concrete action fails, and mark slow steps selectively with test.slow() or an assertion option instead of raising the global timeout. On CI I add globalTimeout and maxFailures so as not to burn resources when the environment is down.