Skip to content

Timeouts

Timeouts define how long Playwright waits before failing. Different timeout types apply to tests, actions, navigation, and assertions.

Timeout Types

Test timeout caps total test duration. Action timeout applies to clicks, fills, etc. Expect timeout applies to assertion retries. Navigation timeout applies to goto, reload, etc.

Set global defaults in config; override per test with test.setTimeout() or per assertion with { timeout: n }.

export default defineConfig({
  timeout: 60_000,
  expect: { timeout: 10_000 },
  use: {
    actionTimeout: 15_000,
    navigationTimeout: 30_000,
  },
});

CI environments often need slightly higher expect timeouts than local.

Per-Test Overrides

test.setTimeout(120_000);
test('slow import', async ({ page }) => {
  test.slow(); // triples default timeout
  // ...
});
  • test.setTimeout() inside test file or test function.
  • test.slow() marks tests expected to take 3x longer.
  • Assertion: toBeVisible({ timeout: 20_000 }).
  • Never set infinite timeouts — fix root cause instead.

Timeout Settings Map

Where each timeout applies.

Setting Scope
timeout in config Entire test
expect.timeout All assertions
actionTimeout click, fill, etc.
navigationTimeout goto, reload, goBack
test.setTimeout() Single test or describe
test.slow() Triple test timeout

CI vs Local Timeout Tuning

Use env vars in config: timeout: process.env.CI ? 90_000 : 30_000. Investigate failures near timeout — often missing wait, not need for more time.

Separate expect Timeout

Set expect: { timeout: 10_000 } in config independently from test timeout — assertions on slow endpoints may need longer than action defaults.

Common Mistakes

  • Cranking all timeouts to maximum instead of fixing flakiness.
  • Different timeouts on each test with no documentation.
  • Ignoring action timeout while only raising expect timeout.
  • test.slow() on every test by habit.

Key Takeaways

  • Four timeout categories: test, action, navigation, expect.
  • Configure globally, override locally when justified.
  • test.slow() annotates legitimately long flows.
  • Increasing timeout should follow investigation, not precede it.

Pro Tip

When a test fails at exactly 30s or 60s, you're hitting test timeout — not assertion timeout. Split long flows or use test.step to find the slow section in traces.