You have written a test. Now you need to know every way to run it. This is like knowing all the gears in a car -- you will use different ones in different situations.
# Run ALL tests across ALL browsers (projects)
npx playwright test
# Run a specific test file
npx playwright test my-first.spec.ts
# Run tests that match a name pattern
npx playwright test --grep "has title"
# Run tests that do NOT match a pattern
npx playwright test --grep-invert "slow test"# Run in headed mode -- see the browser window
npx playwright test --headed
# Run only on Chromium (skip Firefox and WebKit)
npx playwright test --project=chromium
# Run only on Firefox
npx playwright test --project=firefox
# Run on multiple specific projects
npx playwright test --project=chromium --project=firefox# Debug mode -- opens Playwright Inspector
npx playwright test --debug
# Debug a specific test file
npx playwright test my-first.spec.ts --debug
# Open the UI mode (visual test runner)
npx playwright test --ui
# Show HTML report after tests finish
npx playwright show-report| Flag | What It Does | When to Use |
|---|---|---|
| --headed | Shows the browser window during tests | When you want to see what the test is doing |
| --project=name | Runs tests only on the specified browser | When debugging a browser-specific issue |
| --grep "pattern" | Runs only tests matching the pattern | When you want to run one specific test |
| --debug | Opens Playwright Inspector with step-by-step controls | When a test fails and you need to investigate |
| --ui | Opens the visual test runner | During development for a better workflow |
| --workers=1 | Runs tests sequentially (no parallelism) | When debugging test interference |
| --repeat-each=3 | Runs each test 3 times | When checking for flaky tests |
| --reporter=list | Shows detailed output in terminal | When you want verbose console output |
During active development, use --ui mode. It is faster than running from the terminal because it keeps the browser open between runs. Change your test code, click Run, and see results in under a second. No cold start.
By default, tests run headless -- no browser window appears. This is faster but you cannot see what is happening. Use --headed when writing new tests or debugging. Use headless (default) in CI.
Key Point: npx playwright test is your base command. Add --headed to see the browser, --debug to step through, --project to pick a browser, --grep to filter tests. Memorize these five flags.
Key Point: Know your flags: --headed to see the browser, --debug for Inspector, --project for browser selection, --grep to filter, --ui for visual mode.