Crate thirtyfour_sync

Crate thirtyfour_sync 

Source
Expand description

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

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

This crate provides a synchronous (i.e. not async) interface for thirtyfour. For async, see the thirtyfour crate instead.

§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
  • Automatically close browser session on drop
  • 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 support

§Cargo features

There are four reqwest-*-tls*-features, which enable the respective features in the reqwest dependency:

  • reqwest-default-tls (enabled by default): Provides TLS support to connect over HTTPS.
  • reqwest-native-tls: Enables TLS functionality provided by native-tls.
  • reqwest-native-tls-vendored: Enables the vendored feature of native-tls.
  • reqwest-rustls-tls: Enables TLS functionality provided by rustls.

§Examples

The following example assumes you have a selenium server running at localhost:4444, and a demo web app running at http://webappdemo

You can set these up using docker-compose, as follows:

docker-compose up -d

The included web app demo is purely for demonstration / unit testing purposes and is not required in order to use this library in other projects.

§Example (synchronous):

use thirtyfour_sync::prelude::*;

fn main() -> WebDriverResult<()> {
    let caps = DesiredCapabilities::chrome();
    let driver = WebDriver::new("http://localhost:4444/wd/hub", &caps)?;

    // Navigate to URL.
    driver.get("http://webappdemo")?;

    // Navigate to page.
    driver.find_element(By::Id("pagetextinput"))?.click()?;

    // Find element.
    let elem_div = driver.find_element(By::Css("div[data-section='section-input']"))?;

    // Find element from element.
    let elem_text = elem_div.find_element(By::Name("input1"))?;

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

    // Click the button.
    let elem_button = elem_div.find_element(By::Tag("button"))?;
    elem_button.click()?;

    // Get text value of element.
    let elem_result = driver.find_element(By::Id("input-result"))?;
    assert_eq!(elem_result.text()?, "selenium");

    // Close the browser.
    driver.quit()?;

    Ok(())
}

§Advanced element queries and explicit waits

You can use WebDriver::query() and WebElement::query() to perform more advanced queries including polling and filtering. Custom filter functions are also supported.

Also the WebElement::wait_until() method provides additional support for explicit waits using a variety of built-in predicates. You can also provide your own custom predicate if desired.

See the query module documentation for more details.

Modules§

action_chain
common
Re-export common types. Common types used by both async and sync implementations.
components
Wrappers for specific component types.
error
Error types.
extensions
Extensions for specific browsers.
http
prelude
query
Advanced query interface featuring powerful filtering and polling options.

Structs§

Alert
Struct for managing alerts.
ChromeCapabilities
Re-export common types.
Cookie
Re-export common types.
DesiredCapabilities
Re-export common types. The DesiredCapabilities struct provides a generic way to construct capabilities as well as helper methods that create specific capabilities structs for the various browsers.
EdgeCapabilities
Re-export common types.
ElementId
Re-export common types.
ElementRect
Re-export common types.
ElementRef
Re-export common types.
FirefoxCapabilities
Re-export common types.
GenericWebDriver
NOTE: For WebDriver method documentation, see the WebDriverCommands trait.
InternetExplorerCapabilities
Re-export common types.
OperaCapabilities
Re-export common types.
OptionRect
Re-export common types.
Rect
Re-export common types.
SafariCapabilities
Re-export common types.
ScriptArgs
Re-export common types. Helper struct for constructing arguments for WebDriver::execute_script() and WebDriver::execute_async_script().
SessionId
SwitchTo
Struct for switching between frames/windows/alerts.
TimeoutConfiguration
Re-export common types.
TypingData
Re-export common types.
WebDriverSession
WebElement
The WebElement struct encapsulates a single element on a page.
WindowHandle
Re-export common types.

Enums§

AlertBehaviour
Re-export common types.
By
Re-export common types.
Keys
Re-export common types.
PageLoadStrategy
Re-export common types.
Proxy
Re-export common types.
ScrollBehaviour
Re-export common types.
WindowType
Re-export common types.

Traits§

Capabilities
Re-export common types.
ExtensionCommand
Re-export common types.
WebDriverCommands
All browser-level W3C WebDriver commands are implemented under this trait.

Functions§

make_w3c_caps
Re-export common types.

Type Aliases§

WebDriver
The WebDriver struct represents a browser session.