Playwright projects often separate end-to-end specs from unit tests, helper files, and generated fixtures. Setting a dedicated test directory tells Playwright Test where to collect spec files so routine runs do not sweep unrelated folders.
The testDir setting lives in playwright.config.ts or playwright.config.js. Playwright scans that directory recursively, applies testMatch inside it, and reports listed files relative to the configured directory.
Use one directory string for testDir, such as ./e2e. If a project must collect several separate folders, keep a shared parent as testDir and narrow discovery with testMatch instead of trying to list multiple directories.
$ mkdir -p e2e
$ mv tests/home.spec.ts e2e/home.spec.ts
Update relative imports, fixture paths, and snapshot paths after moving test files. A spec that imports helpers with ../ paths may fail even when Playwright discovers it.
import { defineConfig } from '@playwright/test';
export default defineConfig({
testDir: './e2e',
});
Relative testDir values resolve from the directory that contains the Playwright configuration file.
$ npx playwright test --list Listing tests: home.spec.ts:3:5 › home page shows ready state Total: 1 test in 1 file
The listed path is relative to ./e2e because testDir is set there. If the total is 0 tests, check the directory path and the file suffix used by testMatch.
$ npx playwright test Running 1 test using 1 worker · 1 passed (716ms)
Related: How to run Playwright tests