diff --git a/src/web/browser.rs b/src/web/browser.rs index fd835f5..3dc2595 100644 --- a/src/web/browser.rs +++ b/src/web/browser.rs @@ -206,11 +206,35 @@ impl Browser { pub async fn new(config: BrowserConfig) -> Result { let caps = config.build_capabilities(); - let client = ClientBuilder::native() + log::info!("Connecting to WebDriver at {}", config.webdriver_url); + log::debug!( + "Capabilities: {}", + serde_json::to_string_pretty(&caps).unwrap_or_default() + ); + + // Give chromedriver a moment to be fully ready + tokio::time::sleep(Duration::from_millis(500)).await; + + let client = match ClientBuilder::native() .capabilities(caps.as_object().cloned().unwrap_or_default()) .connect(&config.webdriver_url) .await - .context("Failed to connect to WebDriver")?; + { + Ok(c) => { + log::info!("Successfully connected to WebDriver"); + c + } + Err(e) => { + log::error!("WebDriver connection error: {:?}", e); + log::error!("WebDriver URL: {}", config.webdriver_url); + log::error!("Browser type: {:?}", config.browser_type); + log::error!("Headless: {}", config.headless); + if let Some(ref binary) = config.binary_path { + log::error!("Binary path: {}", binary); + } + return Err(anyhow::anyhow!("Failed to connect to WebDriver: {:?}", e)); + } + }; Ok(Self { client, config }) } diff --git a/tests/e2e/mod.rs b/tests/e2e/mod.rs index 3ee96b8..471a442 100644 --- a/tests/e2e/mod.rs +++ b/tests/e2e/mod.rs @@ -86,17 +86,32 @@ impl E2ETestContext { }; let chromedriver = match ChromeDriverService::start(CHROMEDRIVER_PORT).await { - Ok(cd) => Some(cd), + Ok(cd) => { + log::info!("ChromeDriver started on port {}", CHROMEDRIVER_PORT); + Some(cd) + } Err(e) => { - log::warn!("Failed to start ChromeDriver: {}", e); + log::error!("Failed to start ChromeDriver: {}", e); + eprintln!("Failed to start ChromeDriver: {}", e); None } }; let browser = if chromedriver.is_some() { let config = browser_config(); - Browser::new(config).await.ok() + match Browser::new(config).await { + Ok(b) => { + log::info!("Browser created successfully"); + Some(b) + } + Err(e) => { + log::error!("Failed to create browser: {}", e); + eprintln!("Failed to create browser: {}", e); + None + } + } } else { + log::warn!("ChromeDriver not available, skipping browser"); None }; @@ -142,12 +157,13 @@ pub fn browser_config() -> BrowserConfig { let webdriver_url = std::env::var("WEBDRIVER_URL") .unwrap_or_else(|_| format!("http://localhost:{}", CHROMEDRIVER_PORT)); - // Detect Brave browser path + // Detect Brave browser path - need actual binary, not wrapper script let brave_paths = [ - "/usr/bin/brave-browser", - "/usr/bin/brave", - "/snap/bin/brave", - "/opt/brave.com/brave/brave-browser", + "/opt/brave.com/brave-nightly/brave", // Brave Nightly actual binary + "/opt/brave.com/brave/brave", // Brave stable actual binary + "/snap/brave/current/opt/brave.com/brave/brave", // Snap installation + "/usr/bin/google-chrome", // Chrome as fallback + "/usr/bin/chromium-browser", // Chromium as fallback ]; let mut config = BrowserConfig::default()