9 releases

0.1.3 May 23, 2023
0.1.2 May 23, 2023
0.1.0-beta8 Jul 1, 2023
0.1.0-beta7 Jun 14, 2023

#1249 in Web programming


Used in 2 crates (via wda)

MIT OR GPL-3.0-or-later

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:

  1. Standard Compliance: it tracks both classical WebDriver and modern BiDi standards.

  2. Low Overhead: it has no runtime dependencies.

  3. 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.7–4.5MB
~85K SLoC