thirtyfour_sync/lib.rs
1//! Thirtyfour is a Selenium / WebDriver library for Rust, for automated website UI testing.
2//!
3//! It supports the full W3C WebDriver spec.
4//! Tested with Chrome and Firefox although any W3C-compatible WebDriver
5//! should work.
6//!
7//! This crate provides a synchronous (i.e. not async) interface for `thirtyfour`.
8//! For async, see the [thirtyfour](https://docs.rs/thirtyfour) crate instead.
9//!
10//! ## Features
11//!
12//! - All W3C WebDriver and WebElement methods supported
13//! - Create new browser session directly via WebDriver (e.g. chromedriver)
14//! - Create new browser session via Selenium Standalone or Grid
15//! - Automatically close browser session on drop
16//! - Find elements (via all common selectors e.g. Id, Class, CSS, Tag, XPath)
17//! - Send keys to elements, including key-combinations
18//! - Execute Javascript
19//! - Action Chains
20//! - Get and set cookies
21//! - Switch to frame/window/element/alert
22//! - Shadow DOM support
23//! - Alert support
24//! - Capture / Save screenshot of browser or individual element as PNG
25//! - Chrome DevTools Protocol support
26//!
27//! ## Cargo features
28//! There are four `reqwest-*-tls*`-features, which enable the respective features in the `reqwest` dependency:
29//! - **reqwest-default-tls** *(enabled by default)*: Provides TLS support to connect over HTTPS.
30//! - **reqwest-native-tls**: Enables TLS functionality provided by `native-tls`.
31//! - **reqwest-native-tls-vendored**: Enables the `vendored` feature of `native-tls`.
32//! - **reqwest-rustls-tls**: Enables TLS functionality provided by `rustls`.
33//!
34//! ## Examples
35//!
36//! The following example assumes you have a selenium server running
37//! at localhost:4444, and a demo web app running at http://webappdemo
38//!
39//! You can set these up using docker-compose, as follows:
40//!
41//! ```ignore
42//! docker-compose up -d
43//! ```
44//!
45//! The included web app demo is purely for demonstration / unit testing
46//! purposes and is not required in order to use this library in other projects.
47//!
48//!
49//! ### Example (synchronous):
50//!
51//! ```rust
52//! use thirtyfour_sync::prelude::*;
53//!
54//! fn main() -> WebDriverResult<()> {
55//! let caps = DesiredCapabilities::chrome();
56//! let driver = WebDriver::new("http://localhost:4444/wd/hub", &caps)?;
57//!
58//! // Navigate to URL.
59//! driver.get("http://webappdemo")?;
60//!
61//! // Navigate to page.
62//! driver.find_element(By::Id("pagetextinput"))?.click()?;
63//!
64//! // Find element.
65//! let elem_div = driver.find_element(By::Css("div[data-section='section-input']"))?;
66//!
67//! // Find element from element.
68//! let elem_text = elem_div.find_element(By::Name("input1"))?;
69//!
70//! // Type in the search terms.
71//! elem_text.send_keys("selenium")?;
72//!
73//! // Click the button.
74//! let elem_button = elem_div.find_element(By::Tag("button"))?;
75//! elem_button.click()?;
76//!
77//! // Get text value of element.
78//! let elem_result = driver.find_element(By::Id("input-result"))?;
79//! assert_eq!(elem_result.text()?, "selenium");
80//!
81//! // Close the browser.
82//! driver.quit()?;
83//!
84//! Ok(())
85//! }
86//! ```
87//!
88//! ### Advanced element queries and explicit waits
89//!
90//! You can use `WebDriver::query()` and `WebElement::query()` to perform more advanced queries
91//! including polling and filtering. Custom filter functions are also supported.
92//!
93//! Also the `WebElement::wait_until()` method provides additional support for explicit waits
94//! using a variety of built-in predicates. You can also provide your own custom predicate if
95//! desired.
96//!
97//! See the [query](query/index.html) module documentation for more details.
98
99#![forbid(unsafe_code)]
100#![allow(clippy::needless_doctest_main)]
101
102/// Re-export common types.
103pub use thirtyfour::common::{
104 self,
105 capabilities::{
106 chrome::ChromeCapabilities, desiredcapabilities::*, edge::EdgeCapabilities,
107 firefox::FirefoxCapabilities, ie::InternetExplorerCapabilities, opera::OperaCapabilities,
108 safari::SafariCapabilities,
109 },
110 command::{By, ExtensionCommand},
111 cookie::Cookie,
112 keys::{Keys, TypingData},
113 scriptargs::ScriptArgs,
114 types::*,
115};
116pub use thirtyfour::error;
117pub use thirtyfour::SessionId;
118
119pub use alert::Alert;
120pub use session::WebDriverSession;
121pub use switch_to::SwitchTo;
122pub use webdriver::GenericWebDriver;
123pub use webdriver::WebDriver;
124pub use webdrivercommands::WebDriverCommands;
125pub use webelement::WebElement;
126
127pub mod prelude {
128 pub use crate::alert::Alert;
129 pub use crate::error::WebDriverResult;
130 pub use crate::query::{ElementQueryable, ElementWaitable};
131 pub use crate::switch_to::SwitchTo;
132 pub use crate::webdriver::WebDriver;
133 pub use crate::webdrivercommands::{ScriptRetSync, WebDriverCommands};
134 pub use crate::webelement::WebElement;
135 pub use thirtyfour::{By, Cookie, DesiredCapabilities, Keys, ScriptArgs, TypingData};
136}
137
138pub mod action_chain;
139mod alert;
140pub mod http {
141 pub mod connection_sync;
142 pub mod reqwest_sync;
143}
144mod session;
145mod switch_to;
146mod webdriver;
147mod webdrivercommands;
148mod webelement;
149
150/// Extensions for specific browsers.
151pub mod extensions {
152 /// Extensions for working with Chromium-based browsers.
153 pub mod chrome {
154 mod devtools;
155
156 pub use devtools::ChromeDevTools;
157 pub use thirtyfour::extensions::chrome::NetworkConditions;
158 }
159}
160
161/// Wrappers for specific component types.
162pub mod components {
163 /// Wrapper for `<select>` elements.
164 pub mod select;
165}
166
167// ElementQuery and ElementWaiter interfaces.
168pub mod query;