pub struct Chromedriver { /* private fields */ }Expand description
A handle to a spawned chromedriver process plus its resolved Chrome / ChromeDriver binaries.
Terminates automatically when dropped, using the budget configured via
ChromedriverRunConfig::graceful_shutdown. The on-drop automation keeps tests safe in the
face of panics. Call Self::terminate to drive the same shutdown explicitly and surface any
error.
Drive browser sessions through Self::session. Sessions are independent, so multiple of them
can run concurrently against the same chromedriver via tokio::join! or tokio::spawn on a
multi-thread runtime.
Implementations§
Source§impl Chromedriver
impl Chromedriver
Sourcepub async fn run_default() -> Result<Chromedriver, Report<ChromeForTestingManagerError>>
pub async fn run_default() -> Result<Chromedriver, Report<ChromeForTestingManagerError>>
Convenience: resolve, download, and launch chromedriver using
ChromedriverRunConfig::default. Equivalent to
Chromedriver::run(ChromedriverRunConfig::default()).await.
§Errors
Returns an error if the runtime is not multithreaded, version resolution fails, the download fails, or the chromedriver process cannot be spawned.
Sourcepub async fn run(
config: ChromedriverRunConfig,
) -> Result<Chromedriver, Report<ChromeForTestingManagerError>>
pub async fn run( config: ChromedriverRunConfig, ) -> Result<Chromedriver, Report<ChromeForTestingManagerError>>
Resolve, download, and launch a chromedriver process.
§Errors
Returns an error if the runtime is not multithreaded, version resolution fails, the download fails, or the chromedriver process cannot be spawned.
Sourcepub fn port(&self) -> Port
pub fn port(&self) -> Port
The port the chromedriver process is listening on.
When constructed with PortRequest::Any this reflects the OS-assigned port.
Sourcepub async fn terminate(
self,
) -> Result<ExitStatus, Report<ChromeForTestingManagerError>>
pub async fn terminate( self, ) -> Result<ExitStatus, Report<ChromeForTestingManagerError>>
Gracefully terminate the chromedriver process with the configured GracefulShutdown,
configurable via the graceful_shutdown field of ChromedriverRunConfig.
§Errors
Returns an error if the process cannot be terminated within the configured graceful-shutdown budget.
Sourcepub fn session(&self) -> SessionBuilder<'_, DefaultCaps, DefaultConfig>
pub fn session(&self) -> SessionBuilder<'_, DefaultCaps, DefaultConfig>
Start building a scoped thirtyfour crate::Session against this chromedriver.
This is the primary entry point for running a browser test. The returned
SessionBuilder is a fluent, chainable builder with three steps:
- (optional)
SessionBuilder::with_capsmutates thethirtyfour::ChromeCapabilitiesused to create the session (e.g. unset headless, add Chrome args, register extensions). - (optional)
SessionBuilder::with_configreceives thethirtyfour::WebDriverBuilderand may set client-side options such as the element poller, request timeout, user-agent, or keep-alive flag before the session is opened. - (required, terminal)
SessionBuilder::runopens the session, awaits the user closure, and tears the session down once the closure resolves or panics.
Sessions are independent. Multiple sessions can run concurrently against the same
Chromedriver via tokio::join! or tokio::spawn on a multi-thread runtime.
§Examples
Smallest case (default headless capabilities, default client config):
use chrome_for_testing_manager::Chromedriver;
use rootcause::Report;
Chromedriver::run_default()
.await?
.session()
.run(async |session| {
session.goto("https://wikipedia.org").await?;
Ok::<(), thirtyfour::error::WebDriverError>(())
})
.await?;With both setup steps:
use chrome_for_testing_manager::Chromedriver;
use rootcause::Report;
use std::time::Duration;
use thirtyfour::ChromiumLikeCapabilities;
Chromedriver::run_default()
.await?
.session()
.with_caps(ChromiumLikeCapabilities::unset_headless)
.with_config(|b| b.request_timeout(Duration::from_secs(30)))
.run(async |session| {
session.goto("https://wikipedia.org").await?;
Ok::<(), thirtyfour::error::WebDriverError>(())
})
.await?;