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
impl Session
Sourcepub fn new(browser: Browser, headless: bool) -> Result<Self, WebdriverError>
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();
Sourcepub fn open_tab(&mut self) -> Result<usize, WebdriverError>
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
Sourcepub fn update_tabs(&mut self) -> Result<(), WebdriverError>
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);
Sourcepub fn get_timeouts(&self) -> Result<Timeouts, WebdriverError>
pub fn get_timeouts(&self) -> Result<Timeouts, WebdriverError>
This is a simple method getting timeouts of the session.
Sourcepub fn set_timeouts(&mut self, timeouts: Timeouts) -> Result<(), WebdriverError>
pub fn set_timeouts(&mut self, timeouts: Timeouts) -> Result<(), WebdriverError>
This is a simple method setting timeouts of the session.