Two Playwright runs in one CI job keep overwriting `playwright-report`; how do you give each its own folder?
answer
- The folder is emptied, not appended
- Default path is shared by every run
- One config option, one environment variable
- Vary it per invocation, not per config
- Serve the folder to read it
basics
~20 sThe html reporter clears its folder before each run, so the second run replaces the first. Point each run somewhere else with the outputFolder option, or set PLAYWRIGHT_HTML_OUTPUT_DIR per command, and archive each folder separately.
solid answer
~40 sPlaywright's `html` reporter owns one folder - `playwright-report` by default - and clears it before writing, so two runs against the same configuration leave only the second run's results. Fix it at whichever scope varies: `['html', { outputFolder: 'reports/regression' }]` in `playwright.config.ts` when the folder is fixed for that config, or `PLAYWRIGHT_HTML_OUTPUT_DIR=reports/smoke npx playwright test tests/smoke` when two commands share one config - in Playwright 1.63 the environment variable overrides the option for that invocation. Keep the folder distinct from the runner's `outputDir`, which holds per-test artifacts and is managed separately. Read a report from a non-default folder with `npx playwright show-report reports/regression`, and archive the whole folder: attachments sit beside `index.html`.
code
bash · 3 linesPLAYWRIGHT_HTML_OUTPUT_DIR=reports/payroll-smoke npx playwright test tests/smoke
PLAYWRIGHT_HTML_OUTPUT_DIR=reports/payroll-full npx playwright test tests/regression
npx playwright show-report reports/payroll-fullgo deeper
Remember that the HTML report goes to playwright-report and that the folder is cleared each run. Use outputFolder or the PLAYWRIGHT_HTML_OUTPUT_DIR variable to send a run somewhere else.
Explain the two scopes: the config option is fixed for every run of that config, the environment variable varies per invocation and overrides it, which is what makes two runs in one job possible.
Diagnose the vanished report from the clearing behaviour rather than guessing, and make the pipeline archive whole folders so a reader can open any run's report without a rerun.
Decide the artifact naming and retention convention across jobs, so any run's report is findable months later and storage does not grow without a policy behind it.
## Why the second run wins The `html` reporter writes into one folder — `playwright-report` unless you say otherwise — and it **clears that folder before writing** into it. Two runs in the same job with the same configuration therefore do not accumulate: the second run empties the folder and leaves only its own results, and the artifact the job uploads is whatever the last run produced. Nothing is corrupted and no warning is worth waiting for; the first report is simply gone. ## Give each run its own folder There are two levers, and they work at different scopes. | Lever | Where it lives | Scope | | --- | --- | --- | | `outputFolder` | the reporter entry in `playwright.config.ts` | every run using that config | | `PLAYWRIGHT_HTML_OUTPUT_DIR` | the environment of one command | that invocation only | For two runs from one config, the environment variable is the right lever, because it varies per command without a second config file: ```bash PLAYWRIGHT_HTML_OUTPUT_DIR=reports/smoke npx playwright test tests/smoke PLAYWRIGHT_HTML_OUTPUT_DIR=reports/regression npx playwright test tests/regression ``` In Playwright 1.63 that variable overrides the `outputFolder` option for the run it is set on, so a config that names `reports/default` still writes wherever the environment points. ## Keep the report folder off the test output folder The runner's `outputDir` (default `test-results`) holds per-test artifacts — screenshots, traces, files written by tests — and the runner manages it. The HTML report folder is the reporter's own and is wiped on every run. Point them at one path and each will destroy the other's contents, so give the reporter a folder nothing else owns. ## Reading a report that is not in the default place - `npx playwright show-report reports/regression` starts a local web server for that folder and opens it; `--host` and `--port` are there for a container or a remote box. - `open: 'never'` in the reporter entry stops Playwright from opening the report itself after a failing run, which is what you want on any machine that has no browser to open. - Archive the **whole folder**. `index.html` is the shell; the copied attachments and traces sit beside it, and an archive of one file loses them. - The env vars `PLAYWRIGHT_HTML_OPEN`, `PLAYWRIGHT_HTML_HOST` and `PLAYWRIGHT_HTML_PORT` mirror the same options for jobs that would rather not edit the config. ## A payroll pipeline checklist 1. One folder per invocation, named after what ran: `reports/payroll-smoke`, `reports/payroll-full`. 2. `open: 'never'` in the config so no run ever tries to spawn a viewer. 3. Upload each folder as its own artifact, so a reader picks the run they care about. 4. Keep `outputDir` separate and let it stay ephemeral; the report folder is the thing humans open. 5. If the same folder must be reused, copy it aside before the next run starts — the reporter will not do that for you. ## The wider habit The report is written at the end of the run, into a folder the reporter believes it owns. Every mistake in this area comes from one of two assumptions: that the folder accumulates, or that it is shared with something else. Neither is true, and naming the folder explicitly per run is cheaper than discovering that the smoke report vanished during triage.
- Why should the html report folder never be the same path as the runner's outputDir?`outputDir` (default `test-results`) holds per-test artifacts the runner writes and manages, while the report folder is cleared and rewritten by the reporter at the end of the run. Sharing one path means each wipes the other's contents, and the report ends up missing exactly the files it is meant to link to. Give the reporter a folder nothing else owns.
- What does open: 'never' change on a developer machine versus a CI runner?Locally it stops Playwright launching the report in a browser after a failing run, so the command returns straight to the shell and you open the report with `show-report` when you want it. On CI it is mostly insurance - there is nothing to open - but it removes any chance of a job stalling on a spawned viewer.
saying these in an interview costs you the question
- Assumes the html report folder accumulates runs
- Points the html reporter at the test outputDir
- Archives only index.html and loses the attachments
- Thinks two runs merge into one report automatically
- Sets the output folder in config when it must vary per command