Struct Session

Source
pub struct Session {
    pub tabs: Vec<Tab>,
    /* private fields */
}
Expand description

This is the more important object. Tabs can be accessed within the session.

§Example

use lw_webdriver::{session::Session, enums::Browser};
 
let mut session = Session::new(Browser::Firefox, false).unwrap();
 
// accessing default tab
session.tabs[0].navigate("http://example.com/").unwrap();
 
// creating a new tab and access it
session.open_tab().unwrap();
session.tabs[1].navigate("https://mubelotix.dev/").unwrap();

Fields§

§tabs: Vec<Tab>

Contains every manually created tabs and default tab. Do not contains tabs created by web pages with javascript unless you call update_tabs().

Implementations§

Source§

impl Session

Source

pub fn new(browser: Browser, headless: bool) -> Result<Self, WebdriverError>

Create a session of a specific browser. Headless mean that the browser will be opened but not displayed (useful for servers). The crate will request a webdriver server at http://localhost:4444. If no webdriver is listening, one will be launched, but the program (geckodriver or chromedriver) must be located at the same place than the running program.

§Example
let mut session = Session::new(Browser::Firefox, false).unwrap();
Source

pub fn open_tab(&mut self) -> Result<usize, WebdriverError>

Create a new tab in the session. The tab will be directly accessible from the session (no call to update_tabs() needed).

§Example
let mut session = Session::new(Browser::Firefox, false).unwrap();
 
assert_eq!(session.tabs.len(), 1); // default tab is already opened
session.open_tab().unwrap();
assert_eq!(session.tabs.len(), 2); // new tab is accessible
Source

pub fn update_tabs(&mut self) -> Result<(), WebdriverError>

When a tab is created with open_tab() method, it is accessible directly. But sometimes a tab is created by someone else (from a web page with javascript) and you don’t want to care about it! This tab will not be accessible by your program because you never asked it. However if you want to access every open tab, call this function.

§Example
let mut session = Session::new(Browser::Firefox, false).unwrap();
 
// only the default tab is open
assert_eq!(session.tabs.len(), 1);
 
// load a website
session.tabs[0].navigate("https://mubelotix.dev/webdriver_tests/open_tab.html").unwrap();
 
// observe what is happening
sleep(Duration::from_secs(5));
 
// a tab has been opened by another tab but you never asked for it
// you can see two tabs displayed
// but this crate don't show the useless one
assert_eq!(session.tabs.len(), 1);
 
// if you want to access it, call this function
session.update_tabs().unwrap();
 
// now you can access two tabs!
assert_eq!(session.tabs.len(), 2);
Source

pub fn get_timeouts(&self) -> Result<Timeouts, WebdriverError>

This is a simple method getting timeouts of the session.

Source

pub fn set_timeouts(&mut self, timeouts: Timeouts) -> Result<(), WebdriverError>

This is a simple method setting timeouts of the session.

Trait Implementations§

Source§

impl Drop for Session

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl PartialEq for Session

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl WebdriverObject for Session

Source§

fn get_id(&self) -> &String

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