summaryrefslogtreecommitdiff
path: root/src/web.rs
blob: 1fa8a27448f9f887e0c7c311b08297f973269656 (plain) (blame)
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
use {thirtyfour::WebDriver, tokio::process::Command};

pub fn geckodriver(port: u16) -> Result<tokio::process::Child, std::io::Error> {
  Command::new("geckodriver")
    .arg(format!("--port={port}"))
    .stdout(std::process::Stdio::piped())
    .stderr(std::process::Stdio::piped())
    .spawn()
}

pub async fn webdriver(
  port: u16,
) -> Result<WebDriver, thirtyfour::error::WebDriverError> {
  let mut caps = thirtyfour::DesiredCapabilities::firefox();

  caps.set_headless().expect("failed to set headless");

  let driver = WebDriver::new(&format!("http://localhost:{port}"), caps)
    .await
    .expect("failed to connect to webdriver");

  driver
    .goto("https://due.moe/schedule")
    .await
    .expect("failed to navigate to https://due.moe/schedule");

  Ok(driver)
}