Configuring Browsers and Timeouts

πŸ“‹ Table of Contents β–Ύ
  1. Browser and Project Configuration
  2. Common Mistakes

Configuring browsers, timeouts, and retries is essential for making Playwright tests stable in both local and CI environments. Thoughtful defaults reduce flakiness and make failures more meaningful.

Browser and Project Configuration

You can define multiple β€œprojects” in playwright.config to run the same tests against different browsers or devices. This is helpful for cross-browser coverage without duplicating test code.

// playwright.config.ts
import { defineConfig, devices } from '@playwright/test';

export default defineConfig({
  timeout: 30_000,
  expect: {
    timeout: 5_000,
  },
  use: {
    baseURL: 'https://demo.myshop.com',
    trace: 'on-first-retry',
    video: 'on-first-retry',
  },
  projects: [
    {
      name: 'Chromium',
      use: { ...devices['Desktop Chrome'] },
    },
    {
      name: 'Firefox',
      use: { ...devices['Desktop Firefox'] },
    },
  ],
});
Note: Global timeout and expect.timeout values set the upper bounds for tests and assertions, reducing the need for scattered magic numbers in specs.
Tip: Start with one primary browser project (for example, Chromium) during local development, and enable additional browsers primarily in CI to save time.
Warning: Setting timeouts extremely high to β€œfix” flakiness usually hides underlying issues such as missing waits or slow backends.

Retries can be configured per run or in the config file to re-run failing tests automatically. Combined with traces and videos, this makes it easier to diagnose intermittent issues.

Common Mistakes

Mistake 1 β€” Leaving all configuration at defaults without review

This may not match your app’s behaviour.

❌ Wrong: Relying solely on default timeouts even when the app is consistently slower.

βœ… Correct: Adjust global timeouts and baseURL based on real response times and environments.

Mistake 2 β€” Overusing retries to mask flaky tests

Retries are not a cure-all.

❌ Wrong: Adding many retries instead of fixing test logic or app race conditions.

βœ… Correct: Use a small number of retries plus traces to uncover and fix root causes.

🧠 Test Yourself

How should you configure browsers and timeouts in Playwright?