Playwright provides a comprehensive suite of developer tools for debugging, analyzing, and interacting with tests during development and debugging. These tools enable developers to inspect test execution in real-time, analyze recorded traces, and debug failing tests efficiently.
This page covers the interactive debugging and analysis tools provided by Playwright. For information about test execution architecture, see Test Execution Architecture. For details about reporting test results, see Reporting System.
Playwright's developer tools consist of three main components:
BrowserContext. Activated via --debug, PWDEBUG=1, or page.pause(). Used for recording user interactions as test code, picking element locators, recording assertions, and stepping through test execution. See page 5.1 for details.npx playwright test --ui. Provides test tree navigation, live trace preview, status filtering, project selection, and file-watch-triggered re-runs. See page 5.2 for details..zip trace archives, launched via npx playwright show-trace. Shows DOM snapshots, action timelines, network traffic, console output, and source context. See page 5.3 for details.Developer Tools: Entry Points and Code Entities
Sources: packages/playwright-core/src/server/recorder.ts72-169 packages/playwright-core/src/server/recorder/recorderApp.ts48-131 packages/playwright/src/runner/testServer.ts45-63 packages/playwright-core/src/server/trace/viewer/traceViewer.ts81-119 packages/trace-viewer/src/ui/uiModeView.tsx77-553 packages/trace-viewer/src/ui/workbench.tsx65-404
UI Mode is an interactive web-based test runner that enables developers to run, debug, and watch tests through a browser interface. It is launched via the --ui command-line option.
Sources: packages/playwright/src/program.ts219-236 packages/playwright/src/runner/testServer.ts273-291 packages/trace-viewer/src/ui/uiModeView.tsx77-553
The test server exposes a typed interface for test operations through WebSocket communication:
Sources: packages/playwright/src/isomorphic/testServerInterface.ts25-138 packages/playwright/src/runner/testServer.ts90-271 packages/playwright/src/isomorphic/testServerConnection.ts88-282
Key protocol methods:
| Method | Purpose | Parameters | Return |
|---|---|---|---|
initialize() | Setup connection and options | interceptStdio, watchTestDirs | void |
listTests() | Enumerate test cases | projects, locations, grep | report[], status |
runTests() | Execute selected tests | testIds, locations, trace, workers | status |
stopTests() | Interrupt test execution | none | void |
watch() | Enable file watching | fileNames | void |
Sources: packages/playwright/src/isomorphic/testServerInterface.ts25-121 packages/playwright/src/runner/testServer.ts127-233
The UIModeView component manages the UI state and coordinates between the test list, filters, and trace viewer:
Sources: packages/trace-viewer/src/ui/uiModeView.tsx79-112 packages/trace-viewer/src/ui/uiModeView.tsx248-258
UI Mode supports automatic test re-execution when files change:
Sources: packages/trace-viewer/src/ui/uiModeView.tsx316-378 packages/playwright/src/runner/testServer.ts214-216
The Trace Viewer is a standalone application for analyzing recorded test traces. It can be launched via npx playwright show-trace or accessed at https://trace.playwright.dev.
Sources: packages/playwright-core/src/server/trace/viewer/traceViewer.ts81-162 packages/trace-viewer/src/ui/workbenchLoader.tsx26-246 packages/trace-viewer/src/sw/main.ts54-262
The Trace Viewer uses a service worker to enable offline operation and efficient trace loading:
Sources: packages/trace-viewer/src/sw/main.ts61-262 packages/trace-viewer/src/sw/traceLoaderBackends.ts
The Trace Viewer captures and renders DOM snapshots at various points during test execution:
| Snapshot Type | When Captured | Purpose |
|---|---|---|
beforeSnapshot | Before action execution | Shows initial state |
inputSnapshot | During input actions | Shows target element |
afterSnapshot | After action completes | Shows result state |
Sources: packages/trace-viewer/src/ui/snapshotTab.tsx323-416
The snapshot rendering process:
Sources: packages/trace-viewer/src/ui/snapshotTab.tsx102-192 packages/playwright-core/src/server/trace/recorder/snapshotterInjected.ts34-570
The frameSnapshotStreamer function (injected into snapshot iframes) handles:
kShadowAttributekValueAttribute, kCheckedAttribute, kSelectedAttributekScrollTopAttribute, kScrollLeftAttributekStyleSheetAttributekCustomElementsAttributeSources: packages/playwright-core/src/server/trace/recorder/snapshotterInjected.ts40-53
The Playwright Inspector is an interactive window that attaches to an inspected BrowserContext. It provides code recording, element picking, locator generation, assertion recording, and step-through debugging.
Activation:
| Method | Mechanism |
|---|---|
npx playwright test --debug | Sets overrides.debug = true and PWDEBUG=1; pauses before first action |
PWDEBUG=1 env variable | Detected at BrowserContext creation; opens Inspector automatically |
page.pause() | Calls Debugger.pauseOnNextStatement(); blocks execution until resumed |
Inspector Component Architecture
Sources: packages/playwright-core/src/server/recorder.ts72-235 packages/playwright-core/src/server/recorder/recorderApp.ts48-131 packages/playwright-core/src/server/debugController.ts1-50 packages/recorder/src/recorder.tsx37-101
The Recorder class tracks the current mode in this._mode. The injected pollingRecorderSource polls __pw_recorderState() each animation frame to keep the in-page overlay synchronized.
| Mode | Description |
|---|---|
'none' | Inactive, overlay hidden |
'standby' | Overlay visible, not recording |
'inspecting' | Element picker active |
'recording' | Capturing user actions to generate code |
'recording-inspecting' | Recording + element picker simultaneously |
'assertingText' | Waiting for click to record a text assertion |
'assertingVisibility' | Waiting for click to record a visibility assertion |
'assertingValue' | Waiting for click to record a value assertion |
'assertingSnapshot' | Waiting for click to record an ARIA snapshot assertion |
Sources: packages/playwright-core/src/server/recorder.ts248-263 packages/recorder/src/recorder.tsx158-178
| Class | File | Responsibility |
|---|---|---|
Recorder | packages/playwright-core/src/server/recorder.ts | Attaches to BrowserContext as an InstrumentationListener; manages mode, processes in-page actions via bindings, fires RecorderEvent.* to listeners |
RecorderApp | packages/playwright-core/src/server/recorder/recorderApp.ts | Launches the Inspector browser window; wires Recorder events to RecorderFrontend and handles RecorderBackend dispatcher commands |
DebugController | packages/playwright-core/src/server/debugController.ts | Manages Recorder instances across multiple contexts; exposes setRecorderMode, resetForReuse, highlight; used by the VS Code extension |
Recorder (React) | packages/recorder/src/recorder.tsx | Inspector UI: toolbar (Record, Pick locator, Assert *), code editor (CodeMirrorWrapper), call log (CallLogView), locator/ARIA-snapshot tabs |
Sources: packages/playwright-core/src/server/recorder.ts72-113 packages/playwright-core/src/server/recorder/recorderApp.ts48-82 packages/playwright-core/src/server/debugController.ts1-50 packages/recorder/src/recorder.tsx37-50
For details on language-specific code generators, the RecorderSignalProcessor, and the injected script internals, see page 5.1.
The Playwright CLI provides commands for launching developer tools:
Sources: docs/src/test-cli-js.md262-292
The show-trace command is implemented by runTraceViewerApp() which:
startTraceViewerServer()installRootRedirect()openTraceViewerApp()Sources: packages/playwright-core/src/server/trace/viewer/traceViewer.ts154-162
Sources: docs/src/test-cli-js.md60-64 packages/playwright/src/program.ts219-236
The --ui option triggers runUIMode() which:
innerRunTestServer()/trace/uiMode.htmlSources: packages/playwright/src/runner/testServer.ts273-291
Traces are recorded during test execution via the tracing API on BrowserContext:
The trace recording system uses:
frameSnapshotStreamer injected scriptSources: tests/library/trace-viewer.spec.ts40-93 packages/playwright-core/src/server/trace/recorder/snapshotter.ts
Trace files are ZIP archives containing:
| File | Content |
|---|---|
trace.trace | Action events and metadata (JSON lines) |
trace.network | Network request/response data |
resources/ | Screenshots, snapshots, network bodies |
src/ | Source code files (when sources: true) |
Sources: packages/trace-viewer/src/sw/main.ts91-109
Developer tools integrate with the test runner through several mechanisms:
When tests are run in UI Mode, tracing is automatically enabled:
Sources: packages/trace-viewer/src/ui/uiModeView.tsx293-303
UI Mode can display traces for running tests by polling the trace directory:
Sources: packages/trace-viewer/src/ui/uiModeTraceView.tsx44-91
The test server intercepts stdio to display in UI Mode:
Sources: packages/playwright/src/runner/testServer.ts235-270
This allows UI Mode to display console output and errors in real-time while tests are executing.
Refresh this wiki
This wiki was recently refreshed. Please wait 2 days to refresh again.