Class: Playwright::Tracing
- Inherits:
-
PlaywrightApi
- Object
- PlaywrightApi
- Playwright::Tracing
- Defined in:
- lib/playwright_api/tracing.rb
Overview
API for collecting and saving Playwright traces. Playwright traces can be opened in [Trace Viewer](../trace-viewer.md) after Playwright script runs.
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.
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.
Start recording a trace before performing actions. At the end, stop tracing and save it to a file.
“‘python sync browser = chromium.launch() context = browser.new_context() context.tracing.start(screenshots=True, snapshots=True) page = context.new_page() page.goto(“playwright.dev”) context.tracing.stop(path = “trace.zip”) “`
Instance Method Summary collapse
-
#group(name, location: nil) ⇒ Object
NOTE: Use
test.stepinstead when available. -
#group_end ⇒ Object
Closes the last group created by [‘method: Tracing.group`].
-
#off(event, callback) ⇒ Object
– inherited from EventEmitter –.
-
#on(event, callback) ⇒ Object
– inherited from EventEmitter –.
-
#once(event, callback) ⇒ Object
– inherited from EventEmitter –.
-
#start(live: nil, name: nil, screenshots: nil, snapshots: nil, sources: nil, title: nil) ⇒ Object
Start tracing.
-
#start_chunk(name: nil, title: nil) ⇒ Object
Start a new trace chunk.
-
#stop(path: nil) ⇒ Object
Stop tracing.
-
#stop_chunk(path: nil) ⇒ Object
Stop the trace chunk.
Methods inherited from PlaywrightApi
Constructor Details
This class inherits a constructor from Playwright::PlaywrightApi
Instance Method Details
#group(name, location: nil) ⇒ Object
NOTE: Use test.step instead when available.
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.
Usage
“‘python sync # All actions between group and group_end # will be shown in the trace viewer as a group. page.context.tracing.group(“Open Playwright.dev > API”) page.goto(“playwright.dev/”) page.get_by_role(“link”, name=“API”).click() page.context.tracing.group_end() “`
85 86 87 |
# File 'lib/playwright_api/tracing.rb', line 85 def group(name, location: nil) wrap_impl(@impl.group(unwrap_impl(name), location: unwrap_impl(location))) end |
#group_end ⇒ Object
Closes the last group created by [‘method: Tracing.group`].
91 92 93 |
# File 'lib/playwright_api/tracing.rb', line 91 def group_end wrap_impl(@impl.group_end) end |
#off(event, callback) ⇒ Object
– inherited from EventEmitter –
115 116 117 |
# File 'lib/playwright_api/tracing.rb', line 115 def off(event, callback) event_emitter_proxy.off(event, callback) end |
#on(event, callback) ⇒ Object
– inherited from EventEmitter –
109 110 111 |
# File 'lib/playwright_api/tracing.rb', line 109 def on(event, callback) event_emitter_proxy.on(event, callback) end |
#once(event, callback) ⇒ Object
– inherited from EventEmitter –
121 122 123 |
# File 'lib/playwright_api/tracing.rb', line 121 def once(event, callback) event_emitter_proxy.once(event, callback) end |
#start(live: nil, name: nil, screenshots: nil, snapshots: nil, sources: nil, title: nil) ⇒ Object
Start tracing.
NOTE: You probably want to [enable tracing in your config file](playwright.dev/docs/api/class-testoptions#test-options-trace) instead of using Tracing.start.
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.
Usage
“‘python sync context.tracing.start(screenshots=True, snapshots=True) page = context.new_page() page.goto(“playwright.dev”) context.tracing.stop(path = “trace.zip”) “`
36 37 38 39 40 41 42 43 44 |
# File 'lib/playwright_api/tracing.rb', line 36 def start( live: nil, name: nil, screenshots: nil, snapshots: nil, sources: nil, title: nil) wrap_impl(@impl.start(live: unwrap_impl(live), name: unwrap_impl(name), screenshots: unwrap_impl(screenshots), snapshots: unwrap_impl(snapshots), sources: unwrap_impl(sources), title: unwrap_impl(title))) end |
#start_chunk(name: nil, title: nil) ⇒ Object
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`].
Usage
“‘python sync context.tracing.start(screenshots=True, snapshots=True) page = context.new_page() page.goto(“playwright.dev”)
context.tracing.start_chunk() page.get_by_text(“Get Started”).click() # Everything between start_chunk and stop_chunk will be recorded in the trace. context.tracing.stop_chunk(path = “trace1.zip”)
context.tracing.start_chunk() page.goto(“example.com”) # Save a second trace file with different actions. context.tracing.stop_chunk(path = “trace2.zip”) “‘
66 67 68 |
# File 'lib/playwright_api/tracing.rb', line 66 def start_chunk(name: nil, title: nil) wrap_impl(@impl.start_chunk(name: unwrap_impl(name), title: unwrap_impl(title))) end |
#stop(path: nil) ⇒ Object
Stop tracing.
97 98 99 |
# File 'lib/playwright_api/tracing.rb', line 97 def stop(path: nil) wrap_impl(@impl.stop(path: unwrap_impl(path))) end |
#stop_chunk(path: nil) ⇒ Object
Stop the trace chunk. See [‘method: Tracing.startChunk`] for more details about multiple trace chunks.
103 104 105 |
# File 'lib/playwright_api/tracing.rb', line 103 def stop_chunk(path: nil) wrap_impl(@impl.stop_chunk(path: unwrap_impl(path))) end |