Overview
The Playwright Inspector is a GUI tool that allows you to step through Playwright API calls, see debug logs, explore locators, and visually inspect the DOM during test execution. It’s essential for debugging failing tests and understanding test behavior.Launching the Inspector
Debug Mode
The easiest way to use the Inspector is with the--debug flag:
- Opens the Playwright Inspector
- Runs tests in headed mode
- Sets workers to 1
- Disables timeout
- Stops at the first failure
Debug Specific Tests
Environment Variable
You can also enable debug mode using thePWDEBUG environment variable:
Inspector Interface
The Inspector window provides several key areas:Action Log
Shows all Playwright API calls with:- Method name (e.g.,
page.goto(),page.click()) - Arguments passed
- Execution time
- Success/failure status
Source Code View
Displays your test code with:- Current execution line highlighted
- Ability to click line numbers to set breakpoints
- Stack trace navigation
Toolbar Controls
Using Breakpoints
Programmatic Breakpoints
Add breakpoints directly in your test code:Conditional Breakpoints
Locator Exploration
The Inspector includes a powerful locator panel:Pick Locator
- Click the “Pick Locator” button (or press Ctrl/Cmd+Shift+C)
- Hover over elements in the browser
- Click an element to copy its locator
- Role-based selectors (preferred)
- Text content
- Test IDs
- CSS selectors (fallback)
Test Locators
Type a locator in the input field to:- See matching elements highlighted in the browser
- Verify selector specificity
- Test different locator strategies
Inspector Features
Screencasting
The Inspector provides live screencasting through theInspector API:
/home/daytona/workspace/source/packages/playwright-core/src/client/inspector.ts:31.
Console Logs
View console messages from the browser:console.log()console.error()console.warn()- Uncaught exceptions
Network Activity
Inspect network requests:- Request URL and method
- Response status
- Request/response headers
- Timing information
Debugging Best Practices
Start Small
Debug one test at a time with specific selectors using
-g flag.Use page.pause()
Add strategic pauses before actions that fail to inspect state.
Check Selectors
Use the locator panel to verify selectors match the expected elements.
Review Logs
Check console output for JavaScript errors or warnings.
Common Debugging Scenarios
Element Not Found
Timing Issues
Failed Assertions
Keyboard Shortcuts
| Shortcut | Action |
|---|---|
F8 | Resume execution |
F10 | Step over |
F11 | Step into |
Shift+F11 | Step out |
Ctrl/Cmd+Shift+C | Pick locator |
Ctrl/Cmd+\ | Toggle inspector |
Inspector vs Other Tools
The Inspector is different from browser DevTools. While DevTools shows the DOM and browser state, the Inspector shows Playwright API calls and test execution flow.
- Inspector: For Playwright-specific debugging (locators, API calls, test flow)
- DevTools: For browser-specific debugging (DOM, CSS, JavaScript)
- Trace Viewer: For post-execution analysis of completed tests
See Also
- Code Generator - Generate tests by recording actions
- Trace Viewer - Analyze test traces
- UI Mode - Interactive test runner with debugging
