Playwright Test writes run artifacts to a test output directory whenever tests attach files, capture traces, record videos, save screenshots, or create files through testInfo.outputPath(). Moving that directory away from the default test-results path helps keep generated debugging files in a location that CI jobs and local cleanup scripts can handle consistently.
The top-level outputDir option belongs in playwright.config.ts or playwright.config.js. During a run, Playwright creates a unique subdirectory inside that path for each test, which prevents parallel tests from writing to the same artifact files.
Use a directory reserved for generated test output because Playwright cleans the output directory at the start of a run. Keep the path out of source control, and use a short smoke spec with testInfo.outputPath() when the project does not already create traces, videos, screenshots, or other attachments.
artifacts/playwright-output/
Do not point outputDir at source files, reports, or manually curated evidence. Playwright cleans the directory before a run starts.
import { defineConfig } from "@playwright/test";
export default defineConfig({
testDir: "./tests",
outputDir: "artifacts/playwright-output",
});
$ mkdir -p tests
import { test, expect } from "@playwright/test";
import fs from "node:fs/promises";
test("writes output artifact", async ({}, testInfo) => {
const artifactPath = testInfo.outputPath("artifact.txt");
await fs.writeFile(artifactPath, "saved in custom outputDir\n");
const contents = await fs.readFile(artifactPath, "utf8");
expect(contents).toContain("custom outputDir");
});
testInfo.outputPath() returns a path inside the current test's unique output subdirectory.
$ npx playwright test tests/output-artifact.spec.ts --reporter=line Running 1 test using 1 worker [1/1] tests/output-artifact.spec.ts:4:5 › writes output artifact 1 passed (487ms)
$ find artifacts/playwright-output -name artifact.txt artifacts/playwright-output/output-artifact-writes-output-artifact/artifact.txt
The generated subdirectory name is based on the test location and title. Project names, retries, and duplicate titles can change the exact folder name.
$ rm tests/output-artifact.spec.ts