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.
Note: At least one page must exist in the context before starting tracing.
The tracing state is shared across all context.tracing() calls within the
same context, so you can call start() and stop() from separate tracing()
invocations.
§Example
use viewpoint_core::context::TracingOptions;
// Create a page first (required before starting tracing)
let page = context.new_page().await.unwrap();
// Start tracing with screenshots
context.tracing().start(
TracingOptions::new()
.name("my-test")
.screenshots(true)
.snapshots(true)
).await.unwrap();
// Perform test actions...
page.goto("https://example.com").goto().await.unwrap();
// Stop and save trace (state persists across tracing() calls)
context.tracing().stop("/tmp/trace.zip").await.unwrap();Implementations§
Source§impl Tracing
impl Tracing
Sourcepub async fn start(&self, options: TracingOptions) -> Result<(), ContextError>
pub async fn start(&self, options: TracingOptions) -> Result<(), ContextError>
Start recording a trace.
§Requirements
At least one page must exist in the context before starting tracing.
Create a page with context.new_page().await first.
§Errors
Returns an error if:
- Tracing is already active
- No pages exist in the context
- CDP commands fail
§Example
use viewpoint_core::{Browser, TracingOptions};
// Create a page first
let page = context.new_page().await?;
// Then start tracing
context.tracing().start(
TracingOptions::new()
.screenshots(true)
.snapshots(true)
).await?;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
use viewpoint_core::Browser;
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.
Sourcepub async fn add_source_file(
&self,
path: impl Into<String>,
content: impl Into<String>,
)
pub async fn add_source_file( &self, path: impl Into<String>, content: impl Into<String>, )
Add a source file to include in the trace.
Source files are shown in the Trace Viewer for debugging.
§Example
use viewpoint_core::Browser;
context.tracing().add_source_file(
"tests/my_test.rs",
"// test source code"
).await;