| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Thirtyfour is a Selenium / WebDriver library for Rust, for automated website UI testing.
Documentation is available as the Thirtyfour book, llms.txt, and llms-full.txt. If you are porting existing automation, start with the Selenium and Playwright translation guide.
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 elem_text = elem_form
.query(By::Id("searchInput"))
.desc("Wikipedia search input")
.single()
.await?;
// Type in the search terms.
elem_text.send_keys("selenium").await?;
// Click the search button.
let elem_button = elem_form
.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(())
}For test functions, prefer run_browser_test. It attempts driver.quit().await after successful tests, early error returns, and panicking assertions, and preserves both errors when the test and cleanup fail. Call quit() directly for application flows that do not use the runner.
When you control the application under test, give important elements stable data-testid hooks and select them with By::Testid:
let save_button = driver
.query(By::Testid("settings-save"))
.desc("settings save button")
.single()
.await?;Prefer app-owned test IDs first, then stable semantic CSS selectors. Match visible text when the copy itself is part of the behavior you are testing, and use XPath only when CSS cannot reasonably express the target. The Wikipedia example above uses the stable selectors that third-party page actually exposes.
See the Element Queries chapter for the full selector guidance.
Rust 1.88.
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
| Back | FazBrowse Home | New Git URL |