From 0a8bf0cbb82f16bce7b05e74dc1b85ca16dc15a5 Mon Sep 17 00:00:00 2001 From: Kjetil Orbekk Date: Sat, 8 Jul 2023 12:57:41 -0400 Subject: initial commit --- src/main.rs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/main.rs (limited to 'src') diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..8befc88 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,36 @@ +use std::{process::Command, error::Error, fs, env, time::Duration}; + +use fantoccini::{ClientBuilder, Locator}; +use log::info; +use tokio::time; + +static PROFILE_ROOT: &str = "/tmp/geckodriver-dashboard"; + +// let's set up the sequence of steps we want the browser to take +#[tokio::main] +async fn main() -> Result<(), Box> { + pretty_env_logger::init(); + info!("Current directory: {}", env::current_dir()?.display()); + fs::create_dir(PROFILE_ROOT).ok(); + let mut geckodriver = Command::new("geckodriver") + .env("MOZ_REMOTE_SETTINGS_DEVTOOLS", "1") + .arg("--profile-root").arg("/tmp/geckodriver-dashboard").spawn()?; + + let c = ClientBuilder::native().connect("http://localhost:4444").await.expect("failed to connect to WebDriver"); + + loop { + let path = fs::canonicalize("index.html")?; + info!("Opening {}", path.display()); + c.goto(&format!("file://{}", path.display())).await?; + + let e = c.find(Locator::Css("#app")).await?; + let img = e.screenshot().await?; + + fs::write("index.png", img)?; + time::sleep(Duration::from_secs(15)).await; + } + + c.close().await?; + geckodriver.kill()?; + Ok(()) +} -- cgit v1.2.3