Added Chrome Job Profiling and Handling
This commit is contained in:
parent
5b99621044
commit
e4e454960e
5 changed files with 90 additions and 40 deletions
|
|
@ -62,6 +62,7 @@ impl HeadlessManager {
|
|||
let page = self.browser.new_page("about:blank").await?;
|
||||
Ok(PageHandle { page })
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl PageHandle {
|
||||
|
|
@ -198,48 +199,60 @@ impl PageHandle {
|
|||
}
|
||||
}
|
||||
|
||||
pub async fn run_test(ip: &str, log: broadcast::Sender<String>) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let _ = log.send(format!("[Headless] Starte Test für {ip}"));
|
||||
/// Startet einen Setup-Job mit eigenem Chrome-Profilverzeichnis.
|
||||
/// `profile_dir` zeigt auf z. B. runtime/chrome-profiles/job-<id>
|
||||
pub async fn run_test(
|
||||
ip: &str,
|
||||
log: broadcast::Sender<String>,
|
||||
profile_dir: &Path,
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
log.send(format!("[Headless] Starte Test für {ip}")).ok();
|
||||
|
||||
// Config + Chrome-Binärdatei laden
|
||||
let exe_dir = std::env::current_exe()?.parent().unwrap().to_path_buf();
|
||||
let cfg = crate::config::read_config(&exe_dir)?;
|
||||
let chrome_exe = std::path::Path::new(&cfg.chrome.path);
|
||||
log.send(format!("[Headless] Chrome: {}", chrome_exe.display())).ok();
|
||||
|
||||
let _ = log.send(format!("[Headless] Chrome: {}", chrome_exe.display()));
|
||||
let manager = HeadlessManager::new(chrome_exe, &cfg.chrome.args).await?;
|
||||
// Basis-Args aus Config + Job-spezifische Isolation
|
||||
let mut args = cfg.chrome.args.clone();
|
||||
args.push(format!("--user-data-dir={}", profile_dir.display()));
|
||||
args.push("--remote-debugging-port=0".to_string());
|
||||
|
||||
// Browser starten (mit Job-Args) und neue Seite öffnen
|
||||
let manager = crate::headless::HeadlessManager::new(chrome_exe, &args).await?;
|
||||
let page = manager.new_page().await?;
|
||||
|
||||
page.goto("https://192.168.178.240/hp/device/SignIn/Index").await?;
|
||||
// --- Login ---
|
||||
page.goto(&format!("https://{}/hp/device/SignIn/Index", ip)).await?;
|
||||
page.wait_for_selector("#PasswordTextBox", 5000).await?;
|
||||
let _ = log.send("PasswordTextBox gefunden".to_string());
|
||||
log.send("PasswordTextBox gefunden".to_string()).ok();
|
||||
|
||||
page.type_text("#PasswordTextBox", "Pa55w.rt").await?;
|
||||
let _ = log.send("Passwort erfolgreich eingetragen".to_string());
|
||||
log.send("Passwort erfolgreich eingetragen".to_string()).ok();
|
||||
|
||||
page.wait_for_selector("#signInOk", 5000).await?;
|
||||
let _ = log.send("Login-Button gefunden, klicke …".to_string());
|
||||
log.send("Login-Button gefunden, klicke …".to_string()).ok();
|
||||
|
||||
page.click_and_wait_navigation("#signInOk", 15_000).await?;
|
||||
let _ = log.send("Login erfolgreich, warte auf Menü".to_string());
|
||||
log.send("Login erfolgreich, warte auf Menü".to_string()).ok();
|
||||
page.wait_for_dom_quiet(8_000).await?;
|
||||
|
||||
|
||||
|
||||
|
||||
page.goto("https://192.168.178.240/hp/device/SleepSchedule/Index").await?;
|
||||
// --- Sleep Schedule setzen ---
|
||||
page.goto(&format!("https://{}/hp/device/SleepSchedule/Index", ip)).await?;
|
||||
page.wait_for_selector("#SleepDelayTimeLimit", 5000).await?;
|
||||
let _ = log.send("Eingabefeld 'SleepDelayTimeLimit' gefunden".to_string());
|
||||
log.send("Eingabefeld 'SleepDelayTimeLimit' gefunden".to_string()).ok();
|
||||
|
||||
page.set_input_value_by_id("SleepDelayTimeLimit", "15").await?;
|
||||
let _ = log.send("SleepDelayTimeLimit = 15 eingetragen".to_string());
|
||||
log.send("SleepDelayTimeLimit = 15 eingetragen".to_string()).ok();
|
||||
|
||||
page.wait_for_selector("#FormButtonSubmit", 5000).await?;
|
||||
let _ = log.send("Submit-Button gefunden, sende Formular …".to_string());
|
||||
log.send("Submit-Button gefunden, sende Formular …".to_string()).ok();
|
||||
|
||||
page.click_and_wait_navigation("#FormButtonSubmit", 15_000).await?;
|
||||
let _ = log.send("Formular erfolgreich gesendet ✅".to_string());
|
||||
log.send("Formular erfolgreich gesendet ✅".to_string()).ok();
|
||||
page.wait_for_dom_quiet(8_000).await?;
|
||||
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue