tasks.rs
1 use crate::actor::{Result, Task}; 2 use playwright_rs::Page; 3 4 pub fn base_url() -> String { 5 std::env::var("WEB_BASE_URL").unwrap_or_else(|_| "http://localhost:8080".to_string()) 6 } 7 8 pub struct Navigate; 9 10 impl Navigate { 11 pub fn to(path: &'static str) -> NavigateTo { 12 NavigateTo { path } 13 } 14 } 15 16 pub(crate) struct NavigateTo { 17 path: &'static str, 18 } 19 20 impl Task for NavigateTo { 21 async fn perform(self, page: &Page) -> Result { 22 let url = if self.path.starts_with("http") { 23 self.path.to_string() 24 } else { 25 format!("{}{}", base_url(), self.path) 26 }; 27 page.goto(&url, None).await?; 28 Ok(()) 29 } 30 }