#selenium #webdriver #testing #test

thirtyfour

Selenium webdriver client for Rust, inspired by the python selenium library, and named after the atomic number for Selenium (Se)

6 releases

✓ Uses Rust 2018 edition

new 0.2.1 Dec 7, 2019
0.2.0 Dec 5, 2019
0.1.2 Dec 3, 2019
0.1.0 Nov 30, 2019

#7 in #webdriver

28 downloads per month

Apache-2.0

70KB
1.5K SLoC

thirtyfour

Selenium webdriver client for Rust, inspired by the python selenium library.

Named after the atomic number for the Selenium chemical element (Se).

Status: Very early stages, but I hope to get this up and running by early 2020.

Example

Here's what it looks like right now (synchronous version):

let caps = serde_json::json!({
    "browserName": "chrome",
    "version": "",
    "platform": "any"
});

let driver = WebDriver::new("http://localhost:4444/wd/hub", caps)?;
driver.get("https://mozilla.org");
println!("Title: {}", driver.title()?);
let elem = driver.find_element(By::Tag("input"))?;

Both sync and async versions are supported.


lib.rs:

Selenium client for working with W3C-compatible WebDriver implmentations.

NOTE: This project is still WIP and not yet ready for production.

The API is roughly modeled after the python selenium library.

Synchronous and asynchronous APIs are provided (see examples below).

The following examples assume you have a selenium server running at localhost:4444.

i.e.

java -jar selenium-server-standalone-3.141.59.jar

Async example:

use std::thread;
use std::time::Duration;
use thirtyfour::error::WebDriverResult;
use thirtyfour::{By, WebDriver, common::keys::TypingData};
use tokio;

#[tokio::main]
async fn main() {
    webtest().await.expect("Something went wrong");
}

async fn webtest() -> WebDriverResult<()> {
    let caps = serde_json::json!({
        "browserName": "chrome",
        "version": "",
        "platform": "any"
    });

    let driver = WebDriver::new("http://localhost:4444/wd/hub", caps).await?;

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

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

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

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

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

    Ok(())
}

Sync example:

use std::thread;
use std::time::Duration;
use thirtyfour::error::WebDriverResult;
use thirtyfour::{By, sync::WebDriver, common::keys::TypingData};

fn main() {
    webtest().expect("Something went wrong");
}

fn webtest() -> WebDriverResult<()> {
    let caps = serde_json::json!({
        "browserName": "chrome",
        "version": "",
        "platform": "any"
    });

    let driver = WebDriver::new("http://localhost:4444/wd/hub", caps)?;

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

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

    // Type in the search terms.
    elem_text.send_keys(TypingData::from("selenium"))?;

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

    // Look for header to implicitly wait for the page to load.
    driver.find_element(By::ClassName("firstHeading"))?;
    assert_eq!(driver.title()?, "Selenium - Wikipedia");

    Ok(())
}

Dependencies

~5.5–8MB
~180K SLoC