blob: de7efaf83dcf75ffe228098d3e586c5ef8a91a92 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
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() -> WebDriver {
let driver = match WebDriver::new("http://localhost:4444", 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(())
}
|