Lesson 86 — Playwright Configuration, In Depth · Practical QA
LESSON VIEW
A-13 · ADVANCED · PRACTICAL QA

Lesson 86 — Playwright Configuration, In Depth

Objective: Defend every line of the generated playwright.config: each major setting with what it does, its default, when to change it, and a worked example — then tune the config for a real job: staging, a mobile project, CI-proof retries.

⏱ ≈60 min full lesson · English edition — Español · العربية · বাংলা in translation

⚡ Key Points

  • Every config line is optional — know each setting's default before you judge its value.
  • Two clocks: timeout 60s (default 30) per test, fixtures and hooks included; expect.timeout 8s (default 5) per assertion. Per-test overrides: test.setTimeout, test.slow(), per-assertion { timeout }.
  • A fail-then-pass is reported flaky. CI gets retries: process.env.CI ? 2 : 0 and forbidOnly: !!process.env.CI; your desk gets neither.
  • The JSON reporter is a pipeline: test-results/results.json feeds results:excel and results:push (Jira/Trello).
  • Evidence costs: trace/screenshot/video modes trade disk for debuggability — retain-on-failure and only-on-failure are the working compromises.
  • projects multiply the suite (6 tests × 5 projects = 30); a setup project logs in once, and its dependents are skipped — not failed — when it fails.

📖 Read

The config file is a contract with defaults. Every line in it is optional: delete one, and Playwright does not break — it falls back to a documented default. That single fact organizes this whole lesson. Each setting below is taught twice: what your generated config chose, and what the default would have been. By the end you should be able to open any Playwright config — generated or hand-written — and defend every line in it.

Finding the tests. testDir names the folder the runner scans: ./tests in your config. Leave it out and the runner scans the config file's own folder, which is how helper files get mistaken for tests. Inside that folder, a file counts as a test when its name matches testMatch — by default, names ending in .spec or .test, in JavaScript or TypeScript. Its mirror, testIgnore, names patterns to skip: the standard use is a test-assets folder of data files that merely look like tests.

The two clocks. timeout is the whole-test budget — sixty seconds in your config, thirty by default — and fixtures and beforeEach hooks spend from the same budget; when it runs out, the test stops wherever it is. We proved it while making this lesson: a test told to wait three seconds with a one-second budget dies with the words “Test timeout of 1000ms exceeded.” expect.timeout is the second clock — how long a web-first assertion retries before failing: eight seconds in your config, five by default, and our failure run printed it plainly: “Timeout: 8000ms”. One test can override both: test.setTimeout replaces its budget, test.slow() triples it, and a single assertion takes its own timeout in its options.

Parallel and retries. By default, test files run in parallel and the tests inside one file run in order, in a single worker; fullyParallel: true — your config's choice — lets tests inside a file spread across workers too. workers caps how many processes run at once: unset, half your machine's logical cores; on shared CI, teams pin it, often to one. retries is how many times a failed test runs again before being reported failed: one in your config, zero by default. Fail, then pass on a retry, and the test is reported as flaky — we manufactured one, and the runner's verdict was verbatim: “1 flaky”. The professional pair is retries: process.env.CI ? 2 : 0 — retries where you cannot watch, none where you can — and forbidOnly: !!process.env.CI, so a test.only left in a commit fails the CI run on purpose.

Reporters. reporter decides what a run produces, and your config runs three at once: list narrates in your terminal; html builds the dashboard behind npm run report; json writes every result to test-results/results.json. The JSON reporter does double duty — your suite's own tools read that file: results:excel turns it into your spreadsheet, one row per test case ID, and results:push posts the same results to Jira or Trello. We ran the whole chain: one test, one results file, and the Excel tool printed “Results: 1/1 passed” and wrote the row for TC-LOCAL-001: passed, in 1.0 seconds. Leave reporter unset and Playwright chooses: list in your terminal, dot on CI.

The use block is every test's birth context. baseURL — the prefix every relative address resolves against — is built as an override pattern: TESTGEN_BASE_URL wins when set; otherwise the written address is used. We ran the suite both ways; with the variable set, the same test visited our local staging sandbox and passed. The evidence settings trade disk for debuggability: trace records a step-by-step replay (yours: retain-on-failure; on records everything and pays for it; on-first-retry records only the rerun you debug), screenshot keeps a frame (yours: only-on-failure), and video records the whole test as a movie (unset in your config — off, the common choice). In our failure run the policy was visible: the failed test carried a screenshot and a trace; the passes carried nothing. The persona settings dress the browser as a user somewhere: locale and timezoneId change dates, translations, and business hours; permissions grants powers like geolocation without a human clicking Allow; storageState starts every test in a project already signed in, from a login that already happened.

projects is the run list. Yours names five — Desktop Chrome, Firefox, Safari, iPhone 15, Pixel 7 — each a full run of the same tests under one device's rules, which is why listing the suite shows thirty tests: six tests, five projects. A project can override anything in use — its own baseURL, its own storage state — and declare dependencies: projects that must finish, and pass, before it starts. The pattern every real suite grows is a setup project whose only job is logging in and saving the storage state, with the browser projects depending on it and a teardown project, named on the setup project, cleaning up after everything. When setup fails, its dependents are skipped, not failed — nothing downstream of a broken login means anything.

Before and after everything. webServer removes the step everyone forgets: give it the command that starts your app and the address to wait for, and the runner starts the server before the tests and stops it after — we proved it with your suite, and the server was gone when the run ended. It can be a list, when the app is a frontend and a backend. globalSetup and globalTeardown are the code versions: one function before everything, one after — seeding a database, minting a test account. And outputDir is where run artifacts collect: test-results by default, wiped at the start of every run, so the evidence on disk belongs to the last run only. The closing exercise puts it together: point the suite at staging with TESTGEN_BASE_URL (no edit), add one mobile project copied from the iPhone line, and CI-proof the retries with the process.env.CI pair — then run it both ways and read the differences in the report.