GenericWebDriver

Struct GenericWebDriver 

Source
pub struct GenericWebDriver<T: WebDriverHttpClientSync> {
    pub session: WebDriverSession,
    /* private fields */
}
Expand description

NOTE: For WebDriver method documentation, see the WebDriverCommands trait.

The thirtyfour crate uses a generic struct that implements the WebDriverCommands trait. The generic struct is then implemented for a specific HTTP client.

This GenericWebDriver struct encapsulates a synchronous Selenium WebDriver browser session. For the async driver, see GenericWebDriver.

§Example:

use thirtyfour_sync::prelude::*;

fn main() -> WebDriverResult<()> {
    let caps = DesiredCapabilities::chrome();
    let driver = WebDriver::new("http://localhost:4444/wd/hub", &caps)?;
    driver.get("http://webappdemo")?;
    driver.quit()?;
    Ok(())
}

Fields§

§session: WebDriverSession

Implementations§

Source§

impl<T> GenericWebDriver<T>
where T: WebDriverHttpClientSync + 'static,

Source

pub fn new<C>(server_url: &str, capabilities: C) -> WebDriverResult<Self>
where C: Serialize,

The GenericWebDriver struct is not intended to be created directly.

Instead you would use the WebDriver struct, which wires up the GenericWebDriver with a HTTP client for making requests to the WebDriver server.

Create a new WebDriver as follows:

§Example
let caps = DesiredCapabilities::chrome();
let driver = WebDriver::new("http://localhost:4444/wd/hub", &caps)?;

NOTE: If the webdriver appears to hang or give no response, please check that the capabilities object is of the correct type for that webdriver.

Source

pub fn new_with_timeout<C>( server_url: &str, capabilities: C, timeout: Option<Duration>, ) -> WebDriverResult<Self>
where C: Serialize,

Creates a new GenericWebDriver just like the new function. Allows a configurable timeout for all HTTP requests including the session creation.

Create a new WebDriver as follows:

§Example
let caps = DesiredCapabilities::chrome();
let driver = WebDriver::new_with_timeout("http://localhost:4444/wd/hub", &caps, Some(Duration::from_secs(120)))?;
Source

pub fn capabilities(&self) -> DesiredCapabilities

Return a clone of the capabilities as returned by Selenium.

Source

pub fn session_id(&self) -> &SessionId

Source

pub fn config(&self) -> &WebDriverConfig

Source

pub fn config_mut(&mut self) -> &mut WebDriverConfig

Source

pub fn quit(self) -> WebDriverResult<()>

End the webdriver session.

Source

pub fn set_request_timeout(&mut self, timeout: Duration) -> WebDriverResult<()>

Set the request timeout for the HTTP client.

§Example
let caps = DesiredCapabilities::chrome();
let mut driver = WebDriver::new("http://localhost:4444/wd/hub", &caps)?;
driver.set_request_timeout(Duration::from_secs(180))?;
Source§

impl<T> GenericWebDriver<T>
where T: WebDriverHttpClientSync + 'static,

Source

pub fn set_query_poller(&mut self, poller: ElementPoller)

Trait Implementations§

Source§

impl<T: Debug + WebDriverHttpClientSync> Debug for GenericWebDriver<T>

Source§

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

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

impl<T> Drop for GenericWebDriver<T>

Source§

fn drop(&mut self)

Close the current session when the WebDriver struct goes out of scope.

Source§

impl<T> WebDriverCommands for GenericWebDriver<T>

Source§

fn session(&self) -> &WebDriverSession

Get the current session and http client. Read more
Source§

fn cmd(&self, command: Command) -> WebDriverResult<Value>

Convenience wrapper for running WebDriver commands. Read more
Source§

fn close(&self) -> WebDriverResult<()>

Close the current window or tab. Read more
Source§

fn get<S: Into<String>>(&self, url: S) -> WebDriverResult<()>

Navigate to the specified URL. Read more
Source§

fn current_url(&self) -> WebDriverResult<String>

Get the current URL as a String. Read more
Source§

fn page_source(&self) -> WebDriverResult<String>

Get the page source as a String. Read more
Source§

fn title(&self) -> WebDriverResult<String>

Get the page title as a String. Read more
Source§

fn find_element(&self, by: By<'_>) -> WebDriverResult<WebElement<'_>>

Search for an element on the current page using the specified selector. Read more
Source§

fn find_elements(&self, by: By<'_>) -> WebDriverResult<Vec<WebElement<'_>>>

Search for all elements on the current page that match the specified selector. Read more
Source§

fn execute_script(&self, script: &str) -> WebDriverResult<ScriptRetSync<'_>>

Execute the specified Javascript synchronously and return the result. Read more
Source§

fn execute_script_with_args( &self, script: &str, args: &ScriptArgs, ) -> WebDriverResult<ScriptRetSync<'_>>

Execute the specified Javascript synchronously and return the result. Read more
Source§

fn execute_async_script( &self, script: &str, ) -> WebDriverResult<ScriptRetSync<'_>>

Execute the specified Javascrypt asynchronously and return the result. Read more
Source§

fn execute_async_script_with_args( &self, script: &str, args: &ScriptArgs, ) -> WebDriverResult<ScriptRetSync<'_>>

Execute the specified Javascrypt asynchronously and return the result. Read more
Source§

fn current_window_handle(&self) -> WebDriverResult<WindowHandle>

Get the current window handle. Read more
Source§

fn window_handles(&self) -> WebDriverResult<Vec<WindowHandle>>

Get all window handles for the current session. Read more
Source§

fn maximize_window(&self) -> WebDriverResult<()>

Maximize the current window. Read more
Source§

fn minimize_window(&self) -> WebDriverResult<()>

Minimize the current window. Read more
Source§

fn fullscreen_window(&self) -> WebDriverResult<()>

Make the current window fullscreen. Read more
Source§

fn get_window_rect(&self) -> WebDriverResult<Rect>

Get the current window rectangle, in pixels. Read more
Source§

fn set_window_rect(&self, rect: OptionRect) -> WebDriverResult<()>

Set the current window rectangle, in pixels. Read more
Source§

fn back(&self) -> WebDriverResult<()>

Go back. This is equivalent to clicking the browser’s back button. Read more
Source§

fn forward(&self) -> WebDriverResult<()>

Go forward. This is equivalent to clicking the browser’s forward button. Read more
Source§

fn refresh(&self) -> WebDriverResult<()>

Refresh the current page. Read more
Source§

fn get_timeouts(&self) -> WebDriverResult<TimeoutConfiguration>

Get all timeouts for the current session. Read more
Source§

fn set_timeouts(&self, timeouts: TimeoutConfiguration) -> WebDriverResult<()>

Set all timeouts for the current session. Read more
Source§

fn set_implicit_wait_timeout( &self, time_to_wait: Duration, ) -> WebDriverResult<()>

Set the implicit wait timeout. This is how long the WebDriver will wait when querying elements. Read more
Source§

fn set_script_timeout(&self, time_to_wait: Duration) -> WebDriverResult<()>

Set the script timeout. This is how long the WebDriver will wait for a Javascript script to execute. Read more
Source§

fn set_page_load_timeout(&self, time_to_wait: Duration) -> WebDriverResult<()>

Set the page load timeout. This is how long the WebDriver will wait for the page to finish loading. Read more
Source§

fn action_chain(&self) -> ActionChain<'_>

Create a new action chain for this session. Action chains can be used to simulate more complex user input actions involving key combinations, mouse movements, mouse click, right-click, and more. Read more
Source§

fn get_cookies(&self) -> WebDriverResult<Vec<Cookie>>

Get all cookies. Read more
Get the specified cookie. Read more
Delete the specified cookie. Read more
Source§

fn delete_all_cookies(&self) -> WebDriverResult<()>

Delete all cookies. Read more
Add the specified cookie. Read more
Source§

fn screenshot_as_base64(&self) -> WebDriverResult<String>

Take a screenshot of the current window and return it as a base64-encoded String.
Source§

fn screenshot_as_png(&self) -> WebDriverResult<Vec<u8>>

Take a screenshot of the current window and return it as PNG bytes.
Source§

fn screenshot(&self, path: &Path) -> WebDriverResult<()>

Take a screenshot of the current window and write it to the specified filename.
Source§

fn switch_to(&self) -> SwitchTo<'_>

Return a SwitchTo struct for switching to another window or frame.
Source§

fn set_window_name(&self, window_name: &str) -> WebDriverResult<()>

Set the current window name. Useful for switching between windows/tabs using driver.switch_to().window_name(name). Read more
Source§

fn extension_command<T: ExtensionCommand + Send + Sync + 'static>( &self, ext_cmd: T, ) -> WebDriverResult<Value>

Running an extension command. Extension commands are browser specific commands and using browser specific endpoints and parameters. Read more
Source§

fn in_new_tab<F, T>(&self, f: F) -> WebDriverResult<T>
where F: FnOnce() -> WebDriverResult<T>,

Execute the specified function in a new browser tab, closing the tab when complete. The return value will be that of the supplied function, unless an error occurs while opening or closing the tab. Read more

Auto Trait Implementations§

§

impl<T> Freeze for GenericWebDriver<T>

§

impl<T> RefUnwindSafe for GenericWebDriver<T>
where T: RefUnwindSafe,

§

impl<T> Send for GenericWebDriver<T>

§

impl<T> Sync for GenericWebDriver<T>

§

impl<T> Unpin for GenericWebDriver<T>
where T: Unpin,

§

impl<T> UnwindSafe for GenericWebDriver<T>
where T: UnwindSafe,

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<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> ErasedDestructor for T
where T: 'static,