Skip to main content

Overview

Playwright provides comprehensive debugging tools to help you understand test failures and optimize test execution. From interactive inspectors to detailed trace viewers, you have multiple options for debugging at different stages.

Playwright Inspector

The Playwright Inspector is a GUI tool that lets you step through tests, live edit locators, and inspect actionability logs.

Debug Mode

Run tests in debug mode to open the Inspector:
When --debug flag is used, tests run in headed mode and default timeout is set to 0 (no timeout).

Inspector Features

1

Step through tests

Use the step controls to execute your test line by line:
  • Step Over: Execute current line and move to next
  • Step Into: Enter function calls
  • Step Out: Complete current function
  • Continue: Run until next breakpoint
2

Pick locators

Click the “Pick Locator” button, then click elements in the browser to generate locators automatically.
3

View actionability logs

See why actions succeed or fail with detailed logs showing:
  • Element visibility
  • Element position
  • Element state
4

Edit locators live

Modify locators in the inspector and see them highlighted in the browser in real-time.

VS Code Debugger

Using the VS Code Extension

The Playwright VS Code extension provides the best debugging experience:
1

Install the extension

Install the official Playwright Test for VSCode extension.
2

Set breakpoints

Click next to line numbers to set breakpoints (red dots appear).
3

Run in debug mode

Right-click the line number next to a test and select “Debug Test”.
4

Use debug controls

Use VS Code’s debug toolbar to step through code, inspect variables, and evaluate expressions.

Debug Configuration

Create a .vscode/launch.json for custom debug configurations:

Trace Viewer

Enable Trace Recording

Configure trace recording in playwright.config.ts:

View Traces

Open trace files after test execution:
Or view all traces from the HTML report:

Trace Viewer Features

The trace viewer provides comprehensive debugging information:
  • Action timeline: See every action taken during the test
  • Screenshots: Visual snapshots at each step
  • DOM snapshots: Explore the DOM state at any point
  • Network activity: Inspect all network requests and responses
  • Console logs: View console output
  • Source code: See which line of code triggered each action
  • Call stack: Understand the execution flow

Console Output

Page Console Logs

Capture browser console messages:

Debug with console.log

Verbose Logging

Enable detailed Playwright logs:
Or set specific debug channels:

Pause Execution

Using page.pause()

Pause test execution at any point:
This opens the Playwright Inspector where you can:
  • Inspect the current page state
  • Try out locators
  • Step through remaining test code
  • Resume execution

Conditional Breakpoints

Headed Mode

Run tests with visible browser for visual debugging:
Or configure in playwright.config.ts:

Screenshots and Videos

Debug with Screenshots

Automatic Failure Screenshots

Debugging Best Practices

Use Trace Viewer First: For failed tests in CI, download and view traces before trying to reproduce locally.
  • Start with traces: The trace viewer provides the most comprehensive debugging information
  • Use VS Code extension: For local development, the VS Code extension offers the best DX
  • Add strategic page.pause(): Insert pauses before complex operations
  • Enable verbose logging: Use DEBUG environment variable for detailed logs
  • Slow down execution: Use slowMo option to watch actions in real-time
  • Capture screenshots: Take screenshots at key points in your test
  • Monitor network: Check network tab in trace viewer for API issues

Common Debugging Scenarios

Element Not Found

Timeout Issues

Flaky Tests

Debugging in CI

Upload Artifacts

Configure CI to upload debugging artifacts:

View CI Traces

  1. Download the playwright-report artifact from your CI run
  2. Extract the archive
  3. Run: npx playwright show-report playwright-report/
Always record traces and screenshots in CI to debug failures without needing to reproduce them locally.

Troubleshooting

Inspector not opening

Verify you’re using the --debug flag:

VS Code extension not working

Reload the VS Code window and ensure tests are detected:
  1. Open Command Palette (Cmd+Shift+P)
  2. Run “Playwright: Reload”

Traces not being recorded

Verify trace configuration in playwright.config.ts: