Playwright Config

A thermostat controls the temperature of a whole house from one small panel. The Playwright config file works the same way. One file decides which browsers run, how long tests wait, where reports land, and which website address every test visits. Changing a single line in that file changes the behavior of the entire test suite.

Where the Config File Lives

The installer places a file named playwright.config.ts in the project root. Playwright reads it before every run. Tests never import it directly. The runner loads the file silently and applies each setting to every test.

The Settings Map

Project Root
   |
   +-- playwright.config.ts   (the settings panel)
   |        |
   |        +-- testDir    -> folder that holds the tests
   |        +-- timeout    -> maximum time for one test
   |        +-- retries    -> reruns after a failure
   |        +-- reporter   -> style of the final report
   |        +-- use        -> options shared by every test
   |        +-- projects   -> browsers and devices to run
   |
   +-- tests/

A Starter Config

import { defineConfig } from '@playwright/test';

export default defineConfig({
  testDir: './tests',
  timeout: 30000,
  retries: 1,
  reporter: 'html',
  use: {
    baseURL: 'https://example.com',
    headless: true,
    screenshot: 'only-on-failure',
  },
});

What Each Setting Does

testDir

This setting points to the folder that holds test files. Playwright scans that folder and ignores everything else in the project.

timeout

The value sets the maximum time in milliseconds for a single test. A value of 30000 gives each test thirty seconds to finish.

retries

A failed test runs again up to the given number of times before Playwright marks it as failed. Retries absorb random hiccups such as a slow network.

reporter

The reporter controls how results appear. Common choices include list for a line per test, dot for a compact view, and html for a browsable report.

use

The use block holds options that every test shares, such as the base address, headless mode, screen size, and screenshot rules.

Why baseURL Saves Time

With baseURL set, a test writes a short path instead of a long web address.

await page.goto('/login');   // opens https://example.com/login

Pointing the whole suite at a different server takes one edit in the config. The tests stay untouched.

Config for Several Browsers

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

export default defineConfig({
  projects: [
    { name: 'chromium', use: { ...devices['Desktop Chrome'] } },
    { name: 'firefox',  use: { ...devices['Desktop Firefox'] } },
  ],
});

Each project runs the full suite in its own browser. Two projects produce two complete result sets from the same test files.

A Real-World Scenario

A support team at an online bookstore tests the staging site every morning. Staging servers respond slowly before nine o'clock, and a handful of tests fail with timeout errors. The engineer raises timeout from 30000 to 60000 in the config file. All 200 tests gain extra breathing room with one edit.

Quick Practice Task

Open playwright.config.ts in your project. Set retries to 2 and screenshot to 'only-on-failure'. Write a test that fails on purpose, run it, and look inside the test-results folder for the saved screenshot.

Common Questions

Can a test override a config value?

Yes. A test file can call test.use() to change options such as the viewport or locale for that file only. The rest of the suite keeps the global values.

Should the config hold secrets?

Secrets stay out of the config file. Read passwords and tokens from environment variables, because the config file travels with the shared code.

What happens when the config has a typo?

Playwright stops before the first test and prints the line with the error. Read that message carefully, since it usually names the exact setting.

Key Takeaways

  • The config file controls the behavior of the whole test suite from one place.
  • The use block shares options such as baseURL across every test.
  • The projects list runs the same tests in several browsers.
  • Small edits in the config replace many edits across test files.