I’ve been writing Playwright tests for a while now, and I’m consistently surprised when I watch someone else’s screen and see them running npx playwright test with no flags, then clicking around the HTML report to find what failed.
There’s a lot more in the CLI than the docs emphasize. Here’s what I use regularly.
--last-failed
Run only the tests that failed in the previous run:
npx playwright test --last-failed
This is absurdly useful during debugging. You fix a test, you run just that one. No waiting for 400 other tests to pass.
--grep with regex
Filter tests by name pattern. Supports full regex:
npx playwright test --grep "checkout|payment"
npx playwright test --grep-invert "slow"
--grep-invert is the one people forget about. Great for skipping known-flaky tests during a quick smoke check.
UI mode
If you haven’t used UI mode yet, stop reading and go try it:
npx playwright test --ui
It’s a full test runner GUI in the browser. You get a timeline view, screenshot diffs, network logs, and the ability to step through test execution. It replaced my need for 80% of the --debug sessions I used to do.
--trace on
Traces are Playwright’s answer to “what was the state of the page when this failed?”:
npx playwright test --trace on
They capture DOM snapshots, network, console, and screenshots at every step. Combined with npx playwright show-trace trace.zip, you can replay a failure without a re-run.
Shard your test suite
Split a long test run across multiple machines or CI jobs:
# In CI job 1 of 4:
npx playwright test --shard=1/4
# In CI job 2 of 4:
npx playwright test --shard=2/4
Sharding is the fastest path to dramatically cutting your CI time without changing a single test.
None of these are secret — they’re all in the docs. But the docs don’t tell you which ones to actually reach for first. These are mine.
What CLI flags do you use that aren’t obvious? Drop me a line at hello@mak.codes.