class Playwright::Tracing
“‘
context.tracing.stop(path = “trace.zip”)
page.goto(“playwright.dev”)
page = context.new_page()
context.tracing.start(screenshots=True, snapshots=True)
context = browser.new_context()
browser = chromium.launch()
“`python sync
Start recording a trace before performing actions. At the end, stop tracing and save it to a file.
The `context.tracing` API captures browser operations and network activity, but it doesn’t record test assertions (like ‘expect` calls). We recommend [enabling tracing through Playwright Test configuration](playwright.dev/docs/api/class-testoptions#test-options-trace), which includes those assertions and provides a more complete trace for debugging test failures.
NOTE: You probably want to [enable tracing in your config file](playwright.dev/docs/api/class-testoptions#test-options-trace) instead of using `context.tracing`.
API for collecting and saving Playwright traces. Playwright traces can be opened in [Trace Viewer](../trace-viewer.md) after Playwright script runs.
def event_emitter_proxy
def event_emitter_proxy _emitter_proxy ||= EventEmitterProxy.new(self, @impl)
def group(name, location: nil)
page.context.tracing.group_end()
page.get_by_role("link", name="API").click()
page.goto("https://playwright.dev/")
page.context.tracing.group("Open Playwright.dev > API")
# will be shown in the trace viewer as a group.
# All actions between group and group_end
```python sync
**Usage**
Creates a new group within the trace, assigning any subsequent API calls to this group, until [`method: Tracing.groupEnd`] is called. Groups can be nested and will be visible in the trace viewer.
**NOTE**: Use `test.step` instead when available.
def group(name, location: nil) wrap_impl(@impl.group(unwrap_impl(name), location: unwrap_impl(location))) end
def group_end
def group_end wrap_impl(@impl.group_end) end
def off(event, callback)
-- inherited from EventEmitter --
def off(event, callback) event_emitter_proxy.off(event, callback) end
def on(event, callback)
-- inherited from EventEmitter --
def on(event, callback) event_emitter_proxy.on(event, callback) end
def once(event, callback)
-- inherited from EventEmitter --
def once(event, callback) event_emitter_proxy.once(event, callback) end
def start(
context.tracing.stop(path = "trace.zip")
page.goto("https://playwright.dev")
page = context.new_page()
context.tracing.start(screenshots=True, snapshots=True)
```python sync
**Usage**
The `context.tracing` API captures browser operations and network activity, but it doesn't record test assertions (like `expect` calls). We recommend [enabling tracing through Playwright Test configuration](https://playwright.dev/docs/api/class-testoptions#test-options-trace), which includes those assertions and provides a more complete trace for debugging test failures.
**NOTE**: You probably want to [enable tracing in your config file](https://playwright.dev/docs/api/class-testoptions#test-options-trace) instead of using `Tracing.start`.
Start tracing.
def start( name: nil, screenshots: nil, snapshots: nil, sources: nil, title: nil) wrap_impl(@impl.start(name: unwrap_impl(name), screenshots: unwrap_impl(screenshots), snapshots: unwrap_impl(snapshots), sources: unwrap_impl(sources), title: unwrap_impl(title))) end
def start_chunk(name: nil, title: nil)
context.tracing.stop_chunk(path = "trace2.zip")
# Save a second trace file with different actions.
page.goto("http://example.com")
context.tracing.start_chunk()
context.tracing.stop_chunk(path = "trace1.zip")
# Everything between start_chunk and stop_chunk will be recorded in the trace.
page.get_by_text("Get Started").click()
context.tracing.start_chunk()
page.goto("https://playwright.dev")
page = context.new_page()
context.tracing.start(screenshots=True, snapshots=True)
```python sync
**Usage**
Start a new trace chunk. If you'd like to record multiple traces on the same `BrowserContext`, use [`method: Tracing.start`] once, and then create multiple trace chunks with [`method: Tracing.startChunk`] and [`method: Tracing.stopChunk`].
def start_chunk(name: nil, title: nil) wrap_impl(@impl.start_chunk(name: unwrap_impl(name), title: unwrap_impl(title))) end
def stop(path: nil)
def stop(path: nil) wrap_impl(@impl.stop(path: unwrap_impl(path))) end
def stop_chunk(path: nil)
def stop_chunk(path: nil) wrap_impl(@impl.stop_chunk(path: unwrap_impl(path))) end