diff options
author | Santo Cariotti <santo@dcariotti.me> | 2021-07-30 19:24:41 +0200 |
---|---|---|
committer | Santo Cariotti <santo@dcariotti.me> | 2021-07-30 19:24:41 +0200 |
commit | 99968c72a5efbd535362e050baf314f9e0cff709 (patch) | |
tree | 910f43a609186a5719b345632fc80d218cb7b627 /src/browser.rs | |
parent | bba0f862251c737e576c949320f2eecf15a74057 (diff) |
refactor: browser as modular funcs
Diffstat (limited to 'src/browser.rs')
-rw-r--r-- | src/browser.rs | 43 |
1 files changed, 0 insertions, 43 deletions
diff --git a/src/browser.rs b/src/browser.rs deleted file mode 100644 index 4900f6c..0000000 --- a/src/browser.rs +++ /dev/null @@ -1,43 +0,0 @@ -use crate::config::Config; -use std::{thread, time}; -use thirtyfour::prelude::{By, WebDriverResult}; -use thirtyfour::{FirefoxCapabilities, WebDriver, WebDriverCommands}; - -const LOGIN_URL: &str = "https://studenti.smartedu.unict.it/WorkFlow2011/Logon/Logon.aspx"; - -pub async fn init(driver_url: &String) -> WebDriver { - let driver = match WebDriver::new(driver_url, FirefoxCapabilities::new()).await { - Ok(driver) => driver, - Err(_) => { - panic!("Firefox can't be opened"); - } - }; - - return driver; -} - -pub async fn login(driver: &WebDriver, credentials: &Config) -> WebDriverResult<()> { - driver.get(LOGIN_URL).await?; - - let cf_input = driver - .find_element(By::Name("ctl01$contents$UserName")) - .await?; - cf_input.send_keys(&credentials.cf).await?; - - let psw_input = driver - .find_element(By::Name("ctl01$contents$UserPassword")) - .await?; - psw_input.send_keys(&credentials.password).await?; - - thread::sleep(time::Duration::from_millis(1000)); - - driver - .find_element(By::Name("ctl01$contents$LogonButton")) - .await? - .click() - .await?; - - thread::sleep(time::Duration::from_millis(2000)); - - Ok(()) -} |