blob: 8befc886efa781fc5b7375a15f305120b519b752 (
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
|
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<dyn Error>> {
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(())
}
|