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'] },
},
],
});
timeout and expect.timeout values set the upper bounds for tests and assertions, reducing the need for scattered magic numbers in specs.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.