pub struct Screen { /* private fields */ }
Expand description
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.
Implementations§
Source§impl Screen
impl Screen
Sourcepub async fn build_with_testing_library(
driver: WebDriver,
) -> WebDriverResult<Self>
pub async fn build_with_testing_library( driver: WebDriver, ) -> WebDriverResult<Self>
Creates a new Screen
and loads the testing library script in the browser
Sourcepub fn build(driver: WebDriver) -> WebDriverResult<Self>
pub fn build(driver: WebDriver) -> WebDriverResult<Self>
Creates a new Screen
and but does not load the testing library script
This is useful if you want to load the script later or if you have already loaded in your frontend application by setting up the query function you need:
import {
queryAllByRole,
...
} from "@testing-library/dom"
window.__TL__ = {
queryAllByRole,
...
}
Sourcepub fn within(&self, element: WebElement) -> Screen
pub fn within(&self, element: WebElement) -> Screen
Creates a new Screen
wich will be scoped to a specific element
Sourcepub async fn get(&self, selector: impl Into<By>) -> WebDriverResult<WebElement>
pub async fn get(&self, selector: impl Into<By>) -> WebDriverResult<WebElement>
Unified get method that accepts a Selector enum and returns a single WebElement Throws an error if no elements match or if more than one match is found
Sourcepub async fn get_all(
&self,
selector: impl Into<By>,
) -> WebDriverResult<Vec<WebElement>>
pub async fn get_all( &self, selector: impl Into<By>, ) -> WebDriverResult<Vec<WebElement>>
Unified get_all method that accepts a Selector enum and returns all matching WebElements Throws an error if no elements match
Sourcepub async fn query(
&self,
selector: impl Into<By>,
) -> WebDriverResult<Option<WebElement>>
pub async fn query( &self, selector: impl Into<By>, ) -> WebDriverResult<Option<WebElement>>
Unified query method that accepts a Selector enum and returns a single WebElement Returns None if no elements match
Sourcepub async fn query_all(
&self,
selector: impl Into<By>,
) -> WebDriverResult<Vec<WebElement>>
pub async fn query_all( &self, selector: impl Into<By>, ) -> WebDriverResult<Vec<WebElement>>
Unified query_all method that accepts a Selector enum and returns all matching WebElements Returns empty Vec if no elements match
Sourcepub async fn find(&self, selector: impl Into<By>) -> WebDriverResult<WebElement>
pub async fn find(&self, selector: impl Into<By>) -> WebDriverResult<WebElement>
Unified find method that accepts a Selector enum and returns a single WebElement Waits for the element to appear and throws an error if not found
Sourcepub async fn find_all(
&self,
selector: impl Into<By>,
) -> WebDriverResult<Vec<WebElement>>
pub async fn find_all( &self, selector: impl Into<By>, ) -> WebDriverResult<Vec<WebElement>>
Unified find_all method that accepts a Selector enum and returns all matching WebElements Waits for elements to appear and throws an error if none are found
Sourcepub async fn log_testing_playground_url(
&self,
element: Option<WebElement>,
) -> WebDriverResult<String>
pub async fn log_testing_playground_url( &self, element: Option<WebElement>, ) -> WebDriverResult<String>
Logs and returns a URL that can be opened in a browser for debugging using testing-playground If element is None, logs the entire document. If element is provided, logs only that element.