QA Interview Hub · Knowledge base · Quizzes · Українська

Playwright › Config, projects, parallelism, CI

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".

TimeoutDefaultWhere to set
Test (together with beforeEach and fixture setup; afterEach and fixture teardown get a separate limit of the same length)30 stimeout, test.setTimeout
The expect assertion5 sexpect.timeout
Action (click, fill)0, no separate limituse.actionTimeout
Navigation (goto)0, no separate limituse.navigationTimeout
The whole run0, no limitglobalTimeout

The limits are nested

globalTimeout: whole run, unlimited by default test timeout: 30 stest + beforeEach + fixture setup action (click, fill)use.actionTimeout navigation (goto)navigationTimeout expect assertionexpect.timeout: 5 s beforeEachinside the test limit nested limits live within the test timeout
Figure 1. An action or an assertion has its own counter, but none can outlive the test timeout.

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

1 config top leveluse: { actionTimeout } 2 use of a specific projectprojects[].use 3 file or describetest.use, describe.configure 4 an action or assertion callclick({timeout}), expect(…,{timeout})
Figure 2. General on top, specific below: a lower level overrides a higher one. CLI flags such as --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 timeout to 5 minutes to make things "pass": a slow endpoint or an extra navigation gets hidden, and every real hang now costs 5 minutes.
  • Adding waitForTimeout instead 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.

In an interview. Junior: A test has 30 seconds by default, an assertion 5, and actions and navigation have no separate limit. Middle/Senior: I read the first line of the error to know which limit fired, set 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.

More articles in this chapter