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 foundquery()
/query_all()
- ReturnNone
/ empty Vec for missing elementsfind()
/find_all()
- Wait for elements to appear with retries
§Selector Types
By::role()
- Query by ARIA roleBy::text()
- Query by text contentBy::label_text()
- Query by label textBy::placeholder_text()
- Query by placeholder textBy::alt_text()
- Query by alt textBy::title()
- Query by title attributeBy::test_id()
- Query by test IDBy::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§
- Label
Text Selector - Fluent builder for label text queries with selector and exact options
- Role
Selector - 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.
- Simple
Selector - Fluent builder for simple queries that only support exact matching