pub struct Ctx<E> {
pub env: Arc<E>,
pub driver: WebDriver,
pub name: String,
/* private fields */
}Fields§
§env: Arc<E>§driver: WebDriver§name: StringName of the test, as the runner lists it.
Implementations§
Source§impl<E: Env> Ctx<E>
impl<E: Env> Ctx<E>
pub fn url(&self, path: &str) -> String
Sourcepub async fn open(&self, path: &str) -> Result<()>
pub async fn open(&self, path: &str) -> Result<()>
Loads path and waits for the app to take over the server-rendered page.
Sourcepub async fn reload(&self) -> Result<()>
pub async fn reload(&self) -> Result<()>
Reloads the page, waits for the new document to replace the old one and for its app to start.
Sourcepub async fn wait_for_new_document(&self) -> Result<()>
pub async fn wait_for_new_document(&self) -> Result<()>
Waits for a document other than the one mark_document marked to replace it, and for
its app to start.
Sourcepub async fn wait_booted(&self) -> Result<()>
pub async fn wait_booted(&self) -> Result<()>
Until the WASM app mounts, the server-rendered page doesn’t react to clicks or typing the way the app does, so tests interact with a page only after this. Hydration publishes its report when the first DOM batch of the app arrives.
Sourcepub async fn wait_for<T>(
&self,
what: &str,
check: impl AsyncFnMut() -> Result<Option<T>>,
) -> Result<T>
pub async fn wait_for<T>( &self, what: &str, check: impl AsyncFnMut() -> Result<Option<T>>, ) -> Result<T>
Polls check until it returns a value. Errors count as “not yet” (an element vertigo
replaced in the meantime is stale) until the time limit passes.
pub async fn js(&self, script: &str) -> Result<Value>
pub async fn js_with(&self, script: &str, args: Vec<Value>) -> Result<Value>
Sourcepub async fn page_text(&self) -> Result<String>
pub async fn page_text(&self) -> Result<String>
Visible text of the page, with whitespace normalized.
pub async fn wait_for_text(&self, text: &str) -> Result<()>
pub async fn wait_for_no_text(&self, text: &str) -> Result<()>
Sourcepub async fn find(&self, by: By) -> Result<WebElement>
pub async fn find(&self, by: By) -> Result<WebElement>
First match; waits for it to appear.
Sourcepub async fn find_all(&self, by: By) -> Result<Vec<WebElement>>
pub async fn find_all(&self, by: By) -> Result<Vec<WebElement>>
All matches at the moment, without waiting.
pub async fn wait_for_none(&self, by: By) -> Result<()>
pub async fn testid(&self, id: &str) -> Result<WebElement>
Sourcepub async fn by_text(&self, tag: &str, text: &str) -> Result<WebElement>
pub async fn by_text(&self, tag: &str, text: &str) -> Result<WebElement>
First tag whose whole text is text. The client splits adjacent texts into separate
nodes while SSR merges them, so this compares the element’s normalized text, not its
text nodes.
pub async fn click_link(&self, text: &str) -> Result<()>
Sourcepub async fn wait_for_text_of(&self, by: By, expected: &str) -> Result<()>
pub async fn wait_for_text_of(&self, by: By, expected: &str) -> Result<()>
Waits until the first match has exactly the expected text.
Sourcepub async fn children_texts(&self, xpath: &str) -> Result<Vec<Vec<String>>>
pub async fn children_texts(&self, xpath: &str) -> Result<Vec<Vec<String>>>
For each current match of xpath, the texts of its child elements. Read by one script,
so vertigo can’t replace a node halfway through.
Sourcepub async fn hrefs(&self, css: &str) -> Result<Vec<String>>
pub async fn hrefs(&self, css: &str) -> Result<Vec<String>>
Hrefs of all current matches, as written in the markup.
Sourcepub async fn retype(&self, element: &WebElement, text: &str) -> Result<()>
pub async fn retype(&self, element: &WebElement, text: &str) -> Result<()>
Replaces the value of a field the way a user does. WebDriver’s clear() doesn’t send an
input event, so vertigo would keep the old value.
Selects all with the keyboard, in the same send_keys as the rest: chromedriver moves the
caret to the end before typing into a field it takes for unfocused, which a field of a
window without the system focus is (with E2E_HEADLESS=0, the windows of parallel tests
take it from each other). A selection made earlier would be gone.
pub async fn value(&self, element: &WebElement) -> Result<String>
Sourcepub async fn wait_for_value(&self, by: By, expected: &str) -> Result<()>
pub async fn wait_for_value(&self, by: By, expected: &str) -> Result<()>
Waits until the first match is a field with the expected value.
Sourcepub async fn wait_for_displayed(&self, by: By, displayed: bool) -> Result<()>
pub async fn wait_for_displayed(&self, by: By, displayed: bool) -> Result<()>
Waits until the first match is shown or hidden (display, visibility, size).
Sourcepub async fn style(
&self,
element: &WebElement,
property: &str,
) -> Result<String>
pub async fn style( &self, element: &WebElement, property: &str, ) -> Result<String>
Computed style property (in CSS spelling, f. ex. font-weight) of element.
pub async fn wait_for_path(&self, expected: &str) -> Result<()>
pub async fn wait_for_title(&self, expected: &str) -> Result<()>
Sourcepub async fn mark_document(&self) -> Result<()>
pub async fn mark_document(&self) -> Result<()>
Marks the current document; assert_same_document then tells navigation inside the
app from a full page load.
pub async fn assert_same_document(&self) -> Result<()>
pub async fn scroll_y(&self) -> Result<f64>
pub async fn hydration_report(&self) -> Result<HydrationReport>
Sourcepub async fn answer_dialog(&self, expected: &str, accept: bool) -> Result<()>
pub async fn answer_dialog(&self, expected: &str, accept: bool) -> Result<()>
Waits for a window.confirm/alert, checks its text and answers it.
Sourcepub fn allow_console(&self, pattern: &str)
pub fn allow_console(&self, pattern: &str)
Console errors (SEVERE entries) containing pattern don’t fail the test.
Methods from Deref<Target = WebDriver>§
Sourcepub fn handle(&self) -> &Arc<SessionHandle> ⓘ
pub fn handle(&self) -> &Arc<SessionHandle> ⓘ
Returns a reference to the underlying SessionHandle. Useful for
extension code that needs to clone the handle (e.g. building a
WebElement from a JSON value via WebElement::from_json).
Most users won’t need this — methods on SessionHandle are already
reachable through Deref (e.g. driver.session_id()).
Sourcepub fn set_config(&self, config: WebDriverConfig)
pub fn set_config(&self, config: WebDriverConfig)
Atomically replace the configuration used by this driver session.
The new configuration is shared by all clones and elements associated
with this session. Changing WebDriverConfig::request_timeout does
not reconfigure the existing HTTP client because its timeout is fixed
when the client is created.
Sourcepub fn set_poller(&self, poller: Arc<dyn IntoElementPoller + Send + Sync>)
pub fn set_poller(&self, poller: Arc<dyn IntoElementPoller + Send + Sync>)
Atomically replace the default element poller used by this driver session.
The new poller is shared by all clones and elements associated with this session. Queries and waiters that have already been created keep their existing poller.
Sourcepub fn clone_with_config(&self, config: WebDriverConfig) -> WebDriver
👎Deprecated since 0.37.4: configure WebDriverBuilder or WebDriverManagerBuilder before creating the session; clone_with_config() creates a separate SessionHandle that can tear down the shared session when dropped
pub fn clone_with_config(&self, config: WebDriverConfig) -> WebDriver
configure WebDriverBuilder or WebDriverManagerBuilder before creating the session; clone_with_config() creates a separate SessionHandle that can tear down the shared session when dropped
Clone this WebDriver keeping the session handle, but supplying a new WebDriverConfig.
This still uses the same underlying client, and still controls the same browser
session, but uses a different WebDriverConfig for this instance.
Prefer configuring WebDriverBuilder or
WebDriverManagerBuilder before creating the
session. For query-specific polling behavior, use
ElementQuery::with_poller.
This method creates a separate SessionHandle that participates in synchronous teardown
when dropped, so dropping either driver can terminate the shared browser session.
Sourcepub fn cdp(&self) -> Cdp
pub fn cdp(&self) -> Cdp
Get a Chrome DevTools Protocol handle for this session.
Cheap to call (just clones the underlying Arc<SessionHandle>).
Works on any Chromium-based driver session (chromedriver,
msedgedriver, Brave, Opera, etc.) — non-Chromium drivers will return
errors when CDP commands are issued.
§Example
let driver = WebDriver::new("http://localhost:4444", DesiredCapabilities::chrome()).await?;
let info = driver.cdp().browser().get_version().await?;
println!("user agent: {}", info.user_agent);For event subscription, upgrade to [crate::cdp::CdpSession] via
Cdp::connect (feature cdp-events).
Sourcepub fn driver_id(&self) -> Option<DriverId>
pub fn driver_id(&self) -> Option<DriverId>
Identifier of the driver process serving this session, if it was
launched via WebDriverManager. Returns None for sessions
constructed with WebDriver::new (i.e. talking to an externally-
managed driver server).
This identifier matches the DriverLogLine::driver_id field on log
events emitted via WebDriverManager::on_driver_log, so a closure
registered manager-wide can filter to “just this session’s driver”.
Sourcepub fn on_driver_log<F>(&self, f: F) -> Option<DriverLogSubscription>
pub fn on_driver_log<F>(&self, f: F) -> Option<DriverLogSubscription>
Subscribe to log lines from just this session’s driver process. Returns
None if this session wasn’t launched via WebDriverManager;
otherwise an RAII subscription whose drop unsubscribes.
Lines also continue flowing to any subscribers attached at the manager
level (via WebDriverManager::on_driver_log).
Trait Implementations§
Auto Trait Implementations§
impl<E> !RefUnwindSafe for Ctx<E>
impl<E> !UnwindSafe for Ctx<E>
impl<E> Freeze for Ctx<E>
impl<E> Send for Ctx<E>
impl<E> Sync for Ctx<E>
impl<E> Unpin for Ctx<E>
impl<E> UnsafeUnpin for Ctx<E>where
Arc<E>: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more