Skip to main content
The Tracing class enables recording detailed traces of test execution, including screenshots, snapshots, network activity, and console logs. Traces can be viewed in the Playwright Trace Viewer.

Overview

Access tracing through the browser context:

Methods

start

Starts tracing.
string
Trace name. If not specified, the trace name is generated from the test file name and title.
string
Trace title to display in the Trace Viewer.
boolean
default:"false"
Whether to capture screenshots during tracing.
boolean
default:"false"
Whether to capture DOM snapshots during tracing.
boolean
default:"false"
Whether to include source files in the trace.
Returns: Promise<void>

startChunk

Starts a new trace chunk. Useful for recording traces in multiple segments.
string
Chunk name.
string
Chunk title to display in the Trace Viewer.
Returns: Promise<void>

stopChunk

Stops the current trace chunk and optionally saves it to a file.
string
Path to save the trace file. If not specified, the trace is discarded.
Returns: Promise<void>

stop

Stops tracing and optionally saves it to a file.
string
Path to save the trace file. If not specified, the trace is discarded.
Returns: Promise<void>

group

Creates a logical group in the trace for better organization.
string
required
Group name.
{ file: string, line?: number, column?: number }
Source code location for the group.
Returns: Promise<void>

groupEnd

Ends the current trace group.
Returns: Promise<void>

Examples

Basic tracing

Tracing with chunks

Grouping trace actions

Conditional tracing

Tracing with source files

Trace on failure

Viewing traces

After collecting traces, view them using the Playwright Trace Viewer:
Or start the trace viewer server:

Configuration

Configure tracing in playwright.config.ts:
Options:
  • 'on': Record trace for each test
  • 'off': Do not record trace
  • 'retain-on-failure': Record trace for each test, but remove it if test passes
  • 'on-first-retry': Record trace only when retrying a test for the first time