use std::{process::Command, error::Error, fs, env, time::Duration, path::Path}; use fantoccini::{ClientBuilder, Locator}; use log::info; use tokio::time; use clap::Parser; static PROFILE_ROOT: &str = "/tmp/geckodriver-dashboard"; /// Simple program to greet a person #[derive(Parser, Debug)] #[command(author, version, about, long_about = None)] struct Args { /// Output path for png image. #[arg(short, long)] path: String, } // 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(); let args = Args::parse(); 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?; let output_path = Path::new(&args.path); let tmp_path = output_path.join(".tmp"); fs::write(&tmp_path, img)?; fs::rename(&tmp_path, output_path)?; time::sleep(Duration::from_secs(15)).await; } // c.close().await?; // geckodriver.kill()?; // Ok(()) }