summaryrefslogtreecommitdiff
path: root/src/browser.rs
diff options
context:
space:
mode:
authorSanto Cariotti <santo@dcariotti.me>2021-07-29 16:53:42 +0200
committerSanto Cariotti <santo@dcariotti.me>2021-07-29 16:53:42 +0200
commit7f3f9f0bf18ba9c48b7b62d4825a2932b6b0c68d (patch)
treeaaa1a67935e8a129db43007716a5b92d04326682 /src/browser.rs
parentb5256b0f78a91101f19c6ffdf462e06d05d5c2ad (diff)
feat: make login
Diffstat (limited to 'src/browser.rs')
-rw-r--r--src/browser.rs41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/browser.rs b/src/browser.rs
new file mode 100644
index 0000000..4c06aeb
--- /dev/null
+++ b/src/browser.rs
@@ -0,0 +1,41 @@
+use crate::config::Config;
+use std::{thread, time};
+use thirtyfour::prelude::{By, WebDriverResult};
+use thirtyfour::{FirefoxCapabilities, WebDriver, WebDriverCommands};
+
+pub async fn init() -> WebDriver {
+ let driver = match WebDriver::new("http://localhost:4444", FirefoxCapabilities::new()).await {
+ Ok(driver) => driver,
+ Err(e) => {
+ panic!(e);
+ }
+ };
+
+ return driver;
+}
+
+pub async fn login(driver: &WebDriver, credentials: &Config) -> WebDriverResult<()> {
+ driver
+ .get("https://studenti.smartedu.unict.it/WorkFlow2011/Logon/Logon.aspx")
+ .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?;
+
+ Ok(())
+}