viewpoint_core/wait/
mod.rs

1//! # Wait System
2//!
3//! This module provides Playwright-compatible load states and auto-waiting
4//! functionality for reliable browser automation.
5//!
6//! ## Document Load States
7//!
8//! The [`DocumentLoadState`] enum represents different stages of page loading:
9//!
10//! - [`DocumentLoadState::Commit`] - Navigation has started (response headers received)
11//! - [`DocumentLoadState::DomContentLoaded`] - DOM is ready, but resources may still be loading
12//! - [`DocumentLoadState::Load`] - Page is fully loaded including resources
13//! - [`DocumentLoadState::NetworkIdle`] - No network activity for 500ms
14//!
15//! ## Usage in Navigation
16//!
17//! ```no_run
18//! use viewpoint_core::{Browser, DocumentLoadState};
19//!
20//! # async fn example() -> Result<(), viewpoint_core::CoreError> {
21//! # let browser = Browser::launch().headless(true).launch().await?;
22//! # let context = browser.new_context().await?;
23//! # let page = context.new_page().await?;
24//! // Wait for DOM to be ready (fastest)
25//! page.goto("https://example.com")
26//!     .wait_until(DocumentLoadState::DomContentLoaded)
27//!     .goto()
28//!     .await?;
29//!
30//! // Wait for full load (default)
31//! page.goto("https://example.com")
32//!     .wait_until(DocumentLoadState::Load)
33//!     .goto()
34//!     .await?;
35//!
36//! // Wait for network to be idle (slowest, most reliable for SPAs)
37//! page.goto("https://example.com")
38//!     .wait_until(DocumentLoadState::NetworkIdle)
39//!     .goto()
40//!     .await?;
41//! # Ok(())
42//! # }
43//! ```
44//!
45//! ## Choosing the Right Load State
46//!
47//! | State | When to Use |
48//! |-------|-------------|
49//! | `Commit` | When you only need the response headers |
50//! | `DomContentLoaded` | When DOM interaction is needed, but not full resources |
51//! | `Load` | General use, waits for images and stylesheets |
52//! | `NetworkIdle` | For SPAs or pages with async data fetching |
53//!
54//! ## Auto-Waiting in Locators
55//!
56//! The [`Locator`](crate::page::Locator) API automatically waits for elements
57//! to be actionable before performing actions. This includes waiting for:
58//!
59//! - Element to be attached to DOM
60//! - Element to be visible
61//! - Element to be stable (not animating)
62//! - Element to be enabled (for form elements)
63//! - Element to receive events (not obscured)
64//!
65//! ```no_run
66//! use viewpoint_core::Browser;
67//!
68//! # async fn example() -> Result<(), viewpoint_core::CoreError> {
69//! # let browser = Browser::launch().headless(true).launch().await?;
70//! # let context = browser.new_context().await?;
71//! # let page = context.new_page().await?;
72//! // This automatically waits for the button to be clickable
73//! page.locator("button").click().await?;
74//!
75//! // This waits for the input to be visible and enabled
76//! page.locator("input").fill("text").await?;
77//! # Ok(())
78//! # }
79//! ```
80
81mod load_state;
82mod navigation_waiter;
83mod waiter;
84
85pub use load_state::DocumentLoadState;
86pub use navigation_waiter::NavigationWaiter;
87pub use waiter::{LoadStateWaiter, NavigationResponseData};