Rustenium
A modern, high-performance WebDriver BiDi automation library for Rust.
Rustenium provides a powerful and ergonomic API for browser automation using the WebDriver BiDi protocol. It offers both low-level control and high-level abstractions for common automation tasks.
Features
- WebDriver BiDi Protocol: Built on the modern BiDi protocol for bidirectional communication
- Chrome Support: First-class support for Chrome/Chromium browsers
- Flexible Input Methods:
- BidiMouse: Direct, precise mouse movements for fast automation
- HumanMouse: Realistic mouse movements with Bezier curves and jitter to mimic human behavior
- Keyboard: Full keyboard support with modifier keys
- Touchscreen: Multi-touch gesture support for mobile testing
- CSS & XPath Selectors: Convenient macros (
css!(),xpath!()) for element location - Screenshot Capture: Take screenshots of elements or entire pages
- Network Interception: Monitor and intercept network requests
- Event System: Subscribe to browser events in real-time
- Type-Safe API: Leverages Rust's type system for compile-time safety
Installation
Add Rustenium to your Cargo.toml:
[]
= "0.1.0"
= { = "1", = ["full"] }
Quick Start
use ;
use css;
async
Examples
Browser Setup and Navigation
use ;
// Create custom configuration
let mut config = default;
config.headless = true;
// Configure capabilities
let mut caps = default;
caps.add_arg
.add_arg
.accept_insecure_certs;
// Create browser with custom config
let browser = create_chrome_browser.await?;
// Navigate and wait for load
browser.navigate.await?;
Finding Elements
use css;
use xpath;
// Using CSS selectors
let element = browser.find_element.await?;
let buttons = browser.find_elements.await?;
// Using XPath
let header = browser.find_element.await?;
Mouse Input - Precise Movements
use ;
let mouse = new;
// Instant, precise movements
mouse.move_to.await?;
mouse.click.await?;
// Double-click
mouse.click.await?;
Mouse Input - Human-Like Movements
use ;
let bidi_mouse = new;
let human_mouse = new;
// Realistic movements with Bezier curves and jitter
human_mouse.move_to.await?;
human_mouse.click.await?;
// Scroll with natural delays
human_mouse.wheel.await?;
Keyboard Input
use Keyboard;
let keyboard = new;
// Type text
keyboard.type_text.await?;
// Press special keys
keyboard.press.await?;
keyboard.press.await?;
// Modifier key combinations
keyboard.down.await?;
keyboard.press.await?; // Ctrl+A
keyboard.up.await?;
Multi-Touch Gestures
use Touchscreen;
use Arc;
let touchscreen = new;
// Pinch gesture with two fingers
let touch1 = touchscreen.touch_start.await?;
let touch2 = touchscreen.touch_start.await?;
// Move fingers closer together
touch1.move_to.await?;
touch2.move_to.await?;
// Release touches
touch1.end.await?;
touch2.end.await?;
Screenshots
use OriginUnion;
// Capture full viewport
browser.screenshot.await?;
// Capture specific element
let element = browser.find_element.await?;
element.screenshot.await?;
Network Interception
// Intercept and handle network requests
browser.on_request_bidi.await?;
// Add authentication handler
browser.add_authentication.await?;
Documentation
Full API documentation is available on docs.rs.
Browser Support
Currently supported browsers:
- Chrome/Chromium (stable, beta, dev, canary)
Support for Firefox and other browsers is planned for future releases.
Requirements
- Rust 1.75 or later
- Chrome/Chromium browser installed (for Chrome automation)
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.