summaryrefslogtreecommitdiff
path: root/src/browser.rs
blob: 9846841fcd83ac1263f6f1ae2671616f1566174f (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
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(_) => {
            panic!("Firefox can't be opened");
        }
    };

    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(())
}