Crate thirtyfour_testing_library_ext

Source
Expand description

§Thirtyfour Testing Library Extension

This crate provides Testing Library integration for the Thirtyfour WebDriver library. It allows you to query DOM elements using semantic selectors similar to React Testing Library, making your tests more maintainable and user-focused.

§Getting Started

use thirtyfour::prelude::*;
use thirtyfour_testing_library_ext::{Screen, By};

#[tokio::main]
async fn main() -> WebDriverResult<()> {
    let caps = DesiredCapabilities::chrome();
    let driver = WebDriver::new("http://localhost:9515", caps).await?;
     
    driver.goto("https://example.com").await?;
     
    // Create a screen instance
    let screen = Screen::build_with_testing_library(driver.clone()).await?;
     
    // Query by role (semantic selector)
    let button = screen.get(By::role("button")).await?;
    button.click().await?;
     
    // Query by text content
    let heading = screen.get(By::text("Welcome")).await?;
    println!("Found heading: {}", heading.text().await?);
     
    driver.quit().await?;
    Ok(())
}

§Query Methods

The Screen struct provides several query methods with different behaviors:

  • get() / get_all() - Throw errors if elements aren’t found
  • query() / query_all() - Return None / empty Vec for missing elements
  • find() / find_all() - Wait for elements to appear with retries

§Selector Types

  • By::role() - Query by ARIA role
  • By::text() - Query by text content
  • By::label_text() - Query by label text
  • By::placeholder_text() - Query by placeholder text
  • By::alt_text() - Query by alt text
  • By::title() - Query by title attribute
  • By::test_id() - Query by test ID
  • By::display_value() - Query by display value

Each selector type supports options for advanced filtering and matching.

Re-exports§

pub use options::*;

Modules§

configure
Configuration options for the testing library
options
Testing library options module Testing Library options module

Structs§

LabelTextSelector
Fluent builder for label text queries with selector and exact options
RoleSelector
Fluent builder for role-based queries with comprehensive options
Screen
A struct representing a screen in the testing library that provides DOM queries with different behaviors: get* methods throw errors if elements aren’t found, query* methods return null for missing elements, and find* methods return promises that retry until elements are found.
SimpleSelector
Fluent builder for simple queries that only support exact matching

Enums§

By
Selector enum for unified DOM queries
Options
Options enum for unified option handling