Selenium Manager provides comprehensive browser management capabilities including automatic browser discovery, version detection, and browser downloading when needed.
Automatically discovers the version of browsers installed on the system.
trait SeleniumManager {
fn discover_browser_version(&mut self) -> Result<Option<String>, Error>;
}Parameters: None
Returns: Result<Option<String>, Error> - The discovered browser version or None if not found
Description: Scans the system to detect the installed browser version
Detects the path to browser executables on the system.
trait SeleniumManager {
fn detect_browser_path(&mut self) -> Option<PathBuf>;
}Parameters: None
Returns: Option<PathBuf> - Path to the browser executable or None if not found
Description: Locates browser executable in standard installation paths
Gets a list of browser names found in the system PATH.
trait SeleniumManager {
fn get_browser_names_in_path(&self) -> Vec<&str>;
}Parameters: None
Returns: Vec<&str> - List of browser executable names found in PATH
Description: Searches PATH environment variable for browser executables
Creates a mapping of browser names to their executable paths.
trait SeleniumManager {
fn get_browser_path_map(&self) -> HashMap<BrowserPath, &str>;
}Parameters: None
Returns: HashMap<BrowserPath, &str> - Mapping of browser types to paths
Description: Creates a comprehensive map of available browsers and their locations
Downloads and installs a specific version of a browser.
trait SeleniumManager {
fn download_browser(&mut self, browser_version: &str) -> Result<Option<PathBuf>, Error>;
}Parameters:
browser_version: &str - The specific browser version to downloadReturns: Result<Option<PathBuf>, Error> - Path to the downloaded browser or None if not needed
Description: Downloads the specified browser version and returns the installation path
Returns the name of the browser managed by this manager.
trait SeleniumManager {
fn get_browser_name(&self) -> &str;
}Parameters: None
Returns: &str - The browser name (e.g., "chrome", "firefox", "edge")
Description: Gets the canonical name of the browser this manager handles
use selenium_manager::{get_manager_by_browser, SeleniumManager};
use anyhow::Result;
fn discover_browser() -> Result<()> {
let mut manager = get_manager_by_browser("chrome".to_string())?;
// Discover installed browser version
if let Some(version) = manager.discover_browser_version()? {
println!("Found Chrome version: {}", version);
} else {
println!("Chrome not found on system");
}
// Detect browser path
if let Some(path) = manager.detect_browser_path() {
println!("Chrome located at: {}", path.display());
}
Ok(())
}use selenium_manager::{get_manager_by_browser, SeleniumManager};
use anyhow::Result;
fn ensure_browser_available() -> Result<()> {
let mut manager = get_manager_by_browser("firefox".to_string())?;
// Check if browser is available
if manager.discover_browser_version()?.is_none() {
println!("Firefox not found, downloading latest version...");
// Download latest stable version
if let Some(download_path) = manager.download_browser("stable")? {
println!("Firefox downloaded to: {}", download_path.display());
}
}
Ok(())
}use selenium_manager::{get_manager_by_browser, SeleniumManager};
use anyhow::Result;
fn map_available_browsers() -> Result<()> {
let manager = get_manager_by_browser("chrome".to_string())?;
// Get all browsers in PATH
let browsers_in_path = manager.get_browser_names_in_path();
println!("Browsers in PATH: {:?}", browsers_in_path);
// Get detailed path mapping
let browser_paths = manager.get_browser_path_map();
for (browser_type, path) in browser_paths {
println!("{:?}: {}", browser_type, path);
}
Ok(())
}Selenium Manager supports different browser release channels:
Browser management operations return Result<T, Error> types. Common error scenarios: