Debugging Tests
When a test fails and you can't tell why, these are the tools to reach for — starting with the simplest and going deeper.
Start with UI mode
UI mode is the first tool I open when a test fails. It shows a timeline of every action, a DOM snapshot at each step, network requests, and console output — all in one view. You can rewind to any point and see exactly what the page looked like.
Run headed with --debug
--debug opens Playwright Inspector alongside a visible browser. The test pauses at the start and you step through it manually — action by action. Useful when you need to see exactly which element gets clicked or what state the page is in at a specific moment.
Breakpoints in the test
await page.pause() stops the test at that exact line and opens Playwright Inspector. Unlike --debug (which pauses at the start), pause() lets you run until a specific moment — skip the boring setup and stop right where the problem is.
VS Code extension
With the Playwright VS Code extension, you can run and debug tests without leaving the editor. Click the triangle next to a test name to run it, or right-click for "Debug test" to step through with breakpoints. The extension also has a Pick locator button — click it, then click any element in the browser, and the best locator is copied to your clipboard.
Traces for CI failures
When a test fails on CI and you can't reproduce locally, traces are the answer. A trace is a zip file containing every action, DOM snapshot, screenshot, network call and console log from the test run. Enable it in the config and Playwright saves it automatically on failure.
Open a saved trace with npx playwright show-trace path/to/trace.zip — it opens the same Trace Viewer you know from UI mode, but for the CI run.
Check console and network in tests
You can listen to console messages and network requests directly in a test. This helps when the UI looks correct but something in the background is going wrong — an error logged to console, a failed API call, or a redirect that shouldn't happen.