#web-driver #selenium #chromedriver #automation #geckodriver #api-bindings

thirtyfour

Thirtyfour is a Selenium / WebDriver library for Rust, for automated website UI testing. Tested on Chrome and Firefox, but any webdriver-capable browser should work

93 releases

new 0.33.0-alpha.1 Apr 15, 2024
0.32.0-rc.10 Feb 19, 2024
0.32.0-rc.8 Jun 4, 2023
0.32.0-rc.6 Dec 29, 2022
0.1.0 Nov 30, 2019

#12 in HTTP client

Download history 2219/week @ 2023-12-24 3552/week @ 2023-12-31 5303/week @ 2024-01-07 4450/week @ 2024-01-14 4544/week @ 2024-01-21 3481/week @ 2024-01-28 4552/week @ 2024-02-04 4583/week @ 2024-02-11 5160/week @ 2024-02-18 5278/week @ 2024-02-25 6255/week @ 2024-03-03 4472/week @ 2024-03-10 4123/week @ 2024-03-17 3913/week @ 2024-03-24 5444/week @ 2024-03-31 2900/week @ 2024-04-07

16,495 downloads per month
Used in 24 crates (19 directly)

MIT/Apache

395KB
6.5K SLoC

thirtyfour

Crates.io docs.rs Build Status codecov

Thirtyfour is a Selenium / WebDriver library for Rust, for automated website UI testing.

It supports the W3C WebDriver v1 spec. Tested with Chrome and Firefox although any W3C-compatible WebDriver should work.

Why is it called "thirtyfour" ?

Thirty-four (34) is the atomic number for the Selenium chemical element (Se) ⚛️.

Getting Started

Check out The Book 📚!

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) support (limited)
  • Advanced query interface including 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 the Component derive macro (via thirtyfour_macros).

Examples

The examples assume you have chromedriver running on your system.

You can use Selenium (see instructions below) or you can use chromedriver directly by downloading the chromedriver that matches your Chrome version, from here: https://chromedriver.chromium.org/downloads

Then run it like this:

chromedriver

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::new("http://localhost:9515", caps).await?;

     // Navigate to https://wikipedia.org.
     driver.goto("https://wikipedia.org").await?;
     let elem_form = driver.find(By::Id("search-form")).await?;

     // Find element from element.
     let elem_text = elem_form.find(By::Id("searchInput")).await?;

     // Type in the search terms.
     elem_text.send_keys("selenium").await?;

     // Click the search button.
     let elem_button = elem_form.find(By::Css("button[type='submit']")).await?;
     elem_button.click().await?;

     // Look for header to implicitly wait for the page to load.
     driver.find(By::ClassName("firstHeading")).await?;
     assert_eq!(driver.title().await?, "Selenium - Wikipedia");
    
     // Always explicitly close the browser.
     driver.quit().await?;

     Ok(())
}

Minimum Supported Rust Version

The MSRV for thirtyfour is currently 1.66 and will be updated as needed by dependencies.

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

Dependencies

~10–25MB
~351K SLoC