How to set Playwright test match patterns

Playwright projects can contain browser tests, helper files, setup tests, and experimental specs in the same repository. Setting a testMatch pattern tells Playwright Test which file names should be collected as executable tests, so local runs and CI jobs stay on the intended suite.

The testMatch option belongs in playwright.config.ts or playwright.config.js. By default, Playwright collects JavaScript and TypeScript files with .spec or .test suffixes; an explicit pattern replaces that discovery rule for the affected config or project.

Glob strings are matched against absolute file paths, so nested tests need a recursive pattern such as **/*.e2e.ts. Use npx playwright test --list after changing the config to catch patterns that are too broad, too narrow, or missing a directory level.

Steps to set Playwright test match patterns:

  1. Open playwright.config.ts in the Playwright project root.
  2. Set testMatch to the file naming pattern that should run.
    import { defineConfig } from '@playwright/test';
    
    export default defineConfig({
      testDir: './tests',
      testMatch: ['**/*.e2e.ts'],
    });
  3. List the collected tests.
    $ npx playwright test --list
    Listing tests:
      home.e2e.ts:3:5 › home page shows ready state
    Total: 1 test in 1 file

    The output should omit files that do not match the chosen pattern. Use an array such as ['**/*.e2e.ts', '**/*.smoke.ts'] when more than one suffix should run.

  4. Run the matched test set.
    $ npx playwright test
    
    Running 1 test using 1 worker
    
      ✓  1 tests/home.e2e.ts:3:5 › home page shows ready state (9ms)
    
      1 passed (775ms)