Skip to main content

Ctx

Struct Ctx 

Source
pub struct Ctx<E> {
    pub env: Arc<E>,
    pub driver: WebDriver,
    pub name: String,
    /* private fields */
}

Fields§

§env: Arc<E>§driver: WebDriver§name: String

Name of the test, as the runner lists it.

Implementations§

Source§

impl<E: Env> Ctx<E>

Source

pub fn url(&self, path: &str) -> String

Source

pub async fn open(&self, path: &str) -> Result<()>

Loads path and waits for the app to take over the server-rendered page.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub async fn js(&self, script: &str) -> Result<Value>

Source

pub async fn js_with(&self, script: &str, args: Vec<Value>) -> Result<Value>

Source

pub async fn page_text(&self) -> Result<String>

Visible text of the page, with whitespace normalized.

Source

pub async fn wait_for_text(&self, text: &str) -> Result<()>

Source

pub async fn wait_for_no_text(&self, text: &str) -> Result<()>

Source

pub async fn find(&self, by: By) -> Result<WebElement>

First match; waits for it to appear.

Source

pub async fn find_all(&self, by: By) -> Result<Vec<WebElement>>

All matches at the moment, without waiting.

Source

pub async fn wait_for_none(&self, by: By) -> Result<()>

Source

pub async fn testid(&self, id: &str) -> Result<WebElement>

Source

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.

Source

pub async fn text_of(&self, by: By) -> Result<String>

Normalized text of the first match.

Source

pub async fn wait_for_text_of(&self, by: By, expected: &str) -> Result<()>

Waits until the first match has exactly the expected text.

Source

pub async fn texts(&self, by: By) -> Result<Vec<String>>

Texts of all current matches.

Source

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.

Source

pub async fn hrefs(&self, css: &str) -> Result<Vec<String>>

Hrefs of all current matches, as written in the markup.

Source

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.

Source

pub async fn value(&self, element: &WebElement) -> Result<String>

Source

pub async fn wait_for_value(&self, by: By, expected: &str) -> Result<()>

Waits until the first match is a field with the expected value.

Source

pub async fn wait_for_displayed(&self, by: By, displayed: bool) -> Result<()>

Waits until the first match is shown or hidden (display, visibility, size).

Source

pub async fn style( &self, element: &WebElement, property: &str, ) -> Result<String>

Computed style property (in CSS spelling, f. ex. font-weight) of element.

Source

pub async fn path(&self) -> Result<String>

Path and query of the current URL.

Source

pub async fn wait_for_path(&self, expected: &str) -> Result<()>

Source

pub async fn wait_for_title(&self, expected: &str) -> Result<()>

Source

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.

Source

pub async fn assert_same_document(&self) -> Result<()>

Source

pub async fn scroll_y(&self) -> Result<f64>

Source

pub async fn hydration_report(&self) -> Result<HydrationReport>

Source

pub async fn answer_dialog(&self, expected: &str, accept: bool) -> Result<()>

Waits for a window.confirm/alert, checks its text and answers it.

Source

pub fn allow_console(&self, pattern: &str)

Console errors (SEVERE entries) containing pattern don’t fail the test.

Methods from Deref<Target = WebDriver>§

Source

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()).

Source

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.

Source

pub fn set_poller(&self, poller: Arc<dyn IntoElementPoller + Sync + Send>)

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.

Source

pub 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

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.

Source

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).

Source

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”.

Source

pub fn on_driver_log<F>(&self, f: F) -> Option<DriverLogSubscription>
where F: Fn(&DriverLogLine) + Send + Sync + 'static,

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§

Source§

impl<E> Clone for Ctx<E>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<E> Deref for Ctx<E>

Source§

type Target = WebDriver

The resulting type after dereferencing.
Source§

fn deref(&self) -> &WebDriver

Dereferences the value.

Auto Trait Implementations§

§

impl<E> !RefUnwindSafe for Ctx<E>

§

impl<E> !UnwindSafe for Ctx<E>

§

impl<E> Freeze for Ctx<E>
where Arc<E>: Freeze,

§

impl<E> Send for Ctx<E>
where Arc<E>: Send,

§

impl<E> Sync for Ctx<E>
where Arc<E>: Sync,

§

impl<E> Unpin for Ctx<E>
where Arc<E>: Unpin,

§

impl<E> UnsafeUnpin for Ctx<E>
where Arc<E>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more