Answer
Running Playwright Tests from the CLI
Run All Tests
Bash
npx playwright test
Run a Specific File
Bash
npx playwright test tests/login.spec.ts
npx playwright test login
Run a Specific Test by Name
Bash
npx playwright test -g "user can log in"
npx playwright test --grep "checkout"
Run with Browser Visible (Headed)
Bash
npx playwright test --headed
Run on Specific Browser
Bash
npx playwright test --project=chromium
npx playwright test --project=firefox
npx playwright test --project=webkit
Run on Multiple Browsers
Bash
npx playwright test --project=chromium --project=firefox
Control Parallel Workers
Bash
npx playwright test --workers=4
npx playwright test --workers=1 # Sequential (no parallel)
Show Test List (Dry Run)
Bash
npx playwright test --list
Run and Open HTML Report
Bash
npx playwright test
npx playwright show-report
Debug Mode (Opens Inspector)
Bash
npx playwright test --debug
npx playwright test login.spec.ts --debug
Run with Trace
Bash
npx playwright test --trace on
Retry Failed Tests
Bash
npx playwright test --retries=3
Run in UI Mode (Interactive)
Bash
npx playwright test --ui
Sharding (for CI parallel machines)
Bash
# Machine 1 of 3
npx playwright test --shard=1/3
# Machine 2 of 3
npx playwright test --shard=2/3
Full Command Reference
Bash
npx playwright test # Run all tests
npx playwright test --headed # Show browser
npx playwright test --debug # Debug mode
npx playwright test --ui # UI mode
npx playwright test -g "login" # Filter by name
npx playwright test --project=chrome # Specific browser
npx playwright test --workers=4 # Parallelism
npx playwright test --retries=2 # Retry on fail
npx playwright test --reporter=html # HTML report
npx playwright show-report # Open last report
npx playwright codegen https://url # Record new test
