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.

Steps to set Playwright output directory:

  1. Open a terminal at the Playwright project root.
  2. Add the custom output directory to .gitignore.
    artifacts/playwright-output/

    Do not point outputDir at source files, reports, or manually curated evidence. Playwright cleans the directory before a run starts.

  3. Set outputDir in the Playwright configuration file.
    playwright.config.ts
    import { defineConfig } from "@playwright/test";
     
    export default defineConfig({
      testDir: "./tests",
      outputDir: "artifacts/playwright-output",
    });
  4. Create the test directory if the project does not already have one.
    $ mkdir -p tests
  5. Create a temporary smoke spec that writes into the configured output directory.
    tests/output-artifact.spec.ts
    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.

  6. Run the smoke spec.
    $ 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)
  7. Find the generated file under the custom output directory.
    $ 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.

  8. Remove the temporary proof spec after the output path is confirmed.
    $ rm tests/output-artifact.spec.ts