Selenium WebDriver client for Rust, for automated testing of websites
thirtyfour
Thirtyfour is a Selenium / WebDriver library for Rust, for automated website UI testing.
Features
- All W3C WebDriver and WebElement methods supported
- Create new browser session directly via WebDriver (e.g. chromedriver)
- Create new browser session via Selenium Standalone or Grid
- Find elements (via all common selectors e.g. Id, Class, CSS, Tag, XPath)
- Send keys to elements, including key-combinations
- Execute Javascript
- Action Chains
- Get and set cookies
- Switch to frame/window/element/alert
- Shadow DOM support
- Alert support
- Capture / Save screenshot of browser or individual element as PNG
- Chrome DevTools Protocol (CDP) โ typed commands plus optional WebSocket-based event subscription via the
cdp-eventsfeature - WebDriver BiDi (W3C bidirectional protocol) โ typed commands and event subscription cross-browser, opt-in via the
bidifeature - Powerful query interface (the recommended way to find elements) with explicit waits and various predicates
- Component Wrappers (similar to
Page Object Model)
Feature Flags
rustls-tls: (Default) Use rustls to provide TLS support (via reqwest).native-tls: Use native TLS (via reqwest).component: (Default) Enable theComponentderive macro (via
Component / ElementResolver from the
prelude.
cdp: (Default) Typed Chrome DevTools Protocol commands.cdp-events: WebSocket-backed CDP event subscription.bidi: WebDriver BiDi (W3C) โ typed commands and event subscription
WebDriver::bidi(). Opt in by calling caps.enable_bidi() before
starting the session.
Example (async):
To run this example:
cargo run --example tokio_async
use thirtyfour::prelude::*;
#[tokio::main] async fn main() -> WebDriverResult<()> { let caps = DesiredCapabilities::chrome(); let driver = WebDriver::managed(caps).await?;
// Navigate to https://wikipedia.org. driver.goto("https://wikipedia.org").await?; let elem_form = driver .query(By::Id("search-form")) .desc("Wikipedia search form") .single() .await?;
// Querying from an element scopes the search to its subtree. let elemtext = elemform .query(By::Id("searchInput")) .desc("Wikipedia search input") .single() .await?;
// Type in the search terms. elemtext.sendkeys("selenium").await?;
// Click the search button. let elembutton = elemform .query(By::Css("button[type='submit']")) .desc("Wikipedia search button") .single() .await?; elem_button.click().await?;
// Wait for the unique article heading before checking the title. driver .query(By::ClassName("firstHeading")) .desc("Wikipedia article heading") .single() .await?; assert_eq!(driver.title().await?, "Selenium - Wikipedia");
// Always explicitly close the browser. driver.quit().await?;
Ok(()) }
Minimum Supported Rust Version
Rust 1.88.
LICENSE
This work is dual-licensed under MIT or Apache 2.0. You can choose either license if you use this work.
See the NOTICE file for more details.
SPDX-License-Identifier: MIT OR Apache-2.0