viewpoint_core/context/tracing_access/
mod.rs

1//! Tracing access for BrowserContext.
2//!
3//! This module provides the tracing controller access method.
4
5use super::trace::Tracing;
6use super::BrowserContext;
7
8impl BrowserContext {
9    /// Get a tracing controller for recording test execution traces.
10    ///
11    /// Traces capture screenshots, DOM snapshots, and network activity
12    /// for debugging test failures. The resulting trace files are compatible
13    /// with Playwright's Trace Viewer.
14    ///
15    /// # Example
16    ///
17    /// ```ignore
18    /// use viewpoint_core::{Browser, context::TracingOptions};
19    ///
20    /// let browser = Browser::launch().await?;
21    /// let context = browser.new_context().await?;
22    ///
23    /// // Start tracing with screenshots
24    /// context.tracing().start(
25    ///     TracingOptions::new()
26    ///         .screenshots(true)
27    ///         .snapshots(true)
28    /// ).await?;
29    ///
30    /// // Perform test actions
31    /// let page = context.new_page().await?;
32    /// page.goto("https://example.com").goto().await?;
33    ///
34    /// // Stop and save trace
35    /// context.tracing().stop("trace.zip").await?;
36    /// ```
37    pub fn tracing(&self) -> Tracing {
38        // The session_ids will be populated dynamically - the tracing listener
39        // will be attached to page sessions via the context's pages list
40        Tracing::new(
41            self.connection.clone(),
42            self.context_id.clone(),
43            self.pages.clone(),
44        )
45    }
46}