pub struct Tracing { /* private fields */ }Expand description
Tracing manager for recording test execution traces.
Traces record screenshots, DOM snapshots, network activity, and action history. They can be viewed using Playwright’s Trace Viewer.
§Example
// Start tracing with screenshots
context.tracing().start(
TracingOptions::new()
.name("my-test")
.screenshots(true)
.snapshots(true)
).await?;
// ... perform test actions ...
// Stop and save trace
context.tracing().stop("trace.zip").await?;Implementations§
Source§impl Tracing
impl Tracing
Sourcepub async fn start(&self, options: TracingOptions) -> Result<(), ContextError>
pub async fn start(&self, options: TracingOptions) -> Result<(), ContextError>
Sourcepub async fn stop(&self, path: impl AsRef<Path>) -> Result<(), ContextError>
pub async fn stop(&self, path: impl AsRef<Path>) -> Result<(), ContextError>
Stop tracing and save the trace to a file.
The trace is saved as a zip file containing:
- trace.json: The trace data
- resources/: Screenshots and other resources
- network.har: Network activity in HAR format
§Errors
Returns an error if tracing is not active or saving the trace fails.
§Example
context.tracing().stop("trace.zip").await?;Sourcepub async fn stop_discard(&self) -> Result<(), ContextError>
pub async fn stop_discard(&self) -> Result<(), ContextError>
Stop tracing and discard the trace data.
Use this when you don’t need to save the trace (e.g., test passed).
§Errors
Returns an error if tracing is not active.
Sourcepub async fn start_chunk(&self) -> Result<(), ContextError>
pub async fn start_chunk(&self) -> Result<(), ContextError>
Start a new trace chunk.
This is useful for long-running tests where you want to save periodic snapshots.
§Errors
Returns an error if tracing is not active.
Sourcepub async fn stop_chunk(
&self,
path: impl AsRef<Path>,
) -> Result<(), ContextError>
pub async fn stop_chunk( &self, path: impl AsRef<Path>, ) -> Result<(), ContextError>
Stop the current trace chunk and save it.
§Errors
Returns an error if tracing is not active or saving fails.
Sourcepub async fn is_recording(&self) -> bool
pub async fn is_recording(&self) -> bool
Check if tracing is currently active.