Skip to main content

Session

Struct Session 

Source
pub struct Session { /* private fields */ }
Expand description

A browser session. Used to control the browser.

When using thirtyfour (feature), this has a Deref impl to thirtyfour::WebDriver, so this session can be seen as the driver.

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 clone_with_config(&self, config: WebDriverConfig) -> WebDriver

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.

This is useful in cases where you want to specify a custom poller configuration (or some other configuration option) for only one instance of WebDriver.

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 Debug for Session

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Deref for Session

Source§

type Target = WebDriver

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.

Auto Trait Implementations§

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<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<O> ObjectMarkerFor<Local> for O
where O: 'static,

Source§

impl<O> ObjectMarkerFor<SendSync> for O
where O: 'static + Send + Sync,

Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: 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: 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<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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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

impl<T> Sink for T
where T: Send + 'static,