9 releases
0.1.3 |
|
---|---|
0.1.2 |
|
0.1.0-beta8 | Jul 1, 2023 |
0.1.0-beta7 | Jun 14, 2023 |
#1982 in Web programming
40 downloads per month
Used in 2 crates
(via wda)
455KB
11K
SLoC
A WebDriver Client library.
Overview
WebDriver is a widely-adopted W3C standard for web browser automation. It defines algorithms in a platform-, language-independent manner. It opens the possibility of using system programming languages such as Rust or C/C++ for WebUI testing/browser automation, which leads to better performance, efficiency, and safety.
This crate provides a pure Rust implementation of the client-side WebDriver, with the following goals:
-
Standard Compliance: it tracks both classical WebDriver and modern BiDi standards.
-
Low Overhead: it has no runtime dependencies.
-
Excellent Performance: it strives for zero-copy operations.
Examples:
Note: Assume using GeckoDriver, with default settings.
Navigate to website:
use wdc::{GeckoDriver, WdcError, WebDrvClient};
go_w3c().unwrap();
fn go_w3c() -> Result<(), WdcError> {
let wdc: WebDrvClient<GeckoDriver> = wdc::init("127.0.0.1", 4444, 10)?;
let url = "https://www.w3.org/standards";
wdc.navi_to(url)?;
// ...whatever tests/automation on "w3.org"
Ok(())
}
Run Javascript on website:
use wdc::{GeckoDriver, WdcError, WebDrvClient};
check_out_w3c_history().unwrap();
fn check_out_w3c_history() -> Result<(), WdcError> {
let wdc: WebDrvClient<GeckoDriver> = wdc::init("127.0.0.1", 4444, 10)?;
let url = "https://www.w3.org/Consortium/facts.html";
let js_result = wdc.navi_to(url)?.exec_sync(
"return document.getElementById('history').nextElementSibling.innerText;",
vec![],
)?;
let w3c_history = String::from_utf8_lossy(&js_result);
assert!(w3c_history.contains("Tim Berners-Lee"));
assert!(w3c_history.contains("World Wide Web"));
assert!(w3c_history.contains("HTML"));
Ok(())
}
Dependencies
~2.8–4.5MB
~89K SLoC