1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
//! Thirtyfour is a Selenium / WebDriver library for Rust, for automated website UI testing.
//!
//! It supports the W3C WebDriver v1 spec.
//! Tested with Chrome and Firefox, although any W3C-compatible WebDriver
//! should work.
//!
//! ## Getting Started
//!
//! Check out [The Book](https://stevepryde.github.io/thirtyfour/) 📚!
//!
//! ## Features
//!
//! - All W3C WebDriver and WebElement methods supported
//! - Async / await support (tokio only)
//! - Create new browser session directly via WebDriver (e.g. chromedriver)
//! - Create new browser session via Selenium Standalone or Grid
//! - 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 (CDP) — typed commands via [`WebDriver::cdp`]
//! (feature `cdp`, on by default), plus optional WebSocket-based event
//! subscription via the `cdp-events` feature. See the [`cdp`] module for
//! details.
//! - Powerful query interface (the recommended way to find elements) with explicit waits and various predicates
//! - Component Wrappers (similar to `Page Object Model`)
//!
//! ## Feature Flags
//!
//! * `rustls-tls`: (Default) Use rustls to provide TLS support (via reqwest).
//! * `native-tls`: Use native TLS (via reqwest).
//! * `component`: (Default) Enable the `Component` derive macro (via thirtyfour-macros).
//! * `cdp`: (Default) Typed Chrome DevTools Protocol commands via
//! [`WebDriver::cdp`] / [`WebElement::cdp_remote_object_id`] /
//! [`WebElement::cdp_backend_node_id`].
//! * `cdp-events`: WebSocket-backed CDP event subscription. Enables
//! [`cdp::CdpSession`] and pulls in `tokio-tungstenite`. Off by default.
//! * `bidi`: WebDriver BiDi (W3C bidirectional protocol) — typed commands
//! and event subscription via [`WebDriver::bidi`]. Pulls in
//! `tokio-tungstenite`. Off by default.
//!
//! ## Example
//!
//! The following example assumes you have a compatible version of Chrome
//! installed. [`WebDriver::managed`] auto-downloads the matching
//! `chromedriver`, starts it locally, and shuts it down when the session is
//! dropped.
//!
//! ```no_run
//! use thirtyfour::prelude::*;
//!
//! #[tokio::main]
//! async fn main() -> anyhow::Result<()> {
//! let caps = DesiredCapabilities::chrome();
//! let driver = WebDriver::managed(caps).await?;
//!
//! // Navigate to https://wikipedia.org.
//! driver.goto("https://wikipedia.org").await?;
//! let elem_form = driver.find(By::Id("search-form")).await?;
//!
//! // Find element from element.
//! let elem_text = elem_form.find(By::Id("searchInput")).await?;
//!
//! // Type in the search terms.
//! elem_text.send_keys("selenium").await?;
//!
//! // Click the search button.
//! let elem_button = elem_form.find(By::Css("button[type='submit']")).await?;
//! elem_button.click().await?;
//!
//! // Look for header to implicitly wait for the page to load.
//! driver.find(By::ClassName("firstHeading")).await?;
//! assert_eq!(driver.title().await?, "Selenium - Wikipedia");
//!
//! // explicitly close the browser.
//! driver.quit().await?;
//!
//! Ok(())
//! }
//! ```
//!
//! ### The browser will not close automatically
//!
//! Rust does not have [async destructors](https://boats.gitlab.io/blog/post/poll-drop/),
//! and so whenever you forget to use [`WebDriver::quit`] the webdriver will have to block the executor
//! to drop itself and will also ignore errors while dropping, so if you know when a webdriver is no longer used
//! it is recommended to more or less "asynchronously drop" via a call to [`WebDriver::quit`] as in the above example.
//! This also allows you to catch errors during quitting, and possibly panic or report back to the user
//!
//! If you do not call [`WebDriver::quit`] **your async executor will be blocked** meaning no futures can run
//! while quitting. The synchronous fallback also emits a `tracing` warning so you can spot it in logs.
//!
//! ### Element queries and explicit waits
//!
//! [`WebDriver::query`] is the recommended way to find elements. It polls
//! until the element appears, supports filtering and chained alternatives,
//! and produces clearer error messages when nothing matches. Custom filter
//! functions are also supported.
//!
//! The [`WebElement::wait_until`] method provides explicit waits using a
//! variety of built-in predicates, plus an escape hatch for custom predicates.
//!
//! See the [`query`] documentation for more details and examples.
//!
//! [`WebDriver::query`]: extensions::query::ElementQueryable::query
//! [`WebElement::wait_until`]: extensions::query::ElementWaitable::wait_until
//! [`query`]: extensions::query
//!
//! ### Components
//!
//! Components allow you to wrap a web component using smart element resolvers that can
//! automatically re-query stale elements, and much more.
//!
//! ```ignore
//! #[derive(Debug, Clone, Component)]
//! pub struct CheckboxComponent {
//! base: WebElement,
//! #[by(tag = "label", first)]
//! label: ElementResolver<WebElement>,
//! #[by(css = "input[type='checkbox']")]
//! input: ElementResolver<WebElement>,
//! }
//!
//! impl CheckBoxComponent {
//! pub async fn label_text(&self) -> WebDriverResult<String> {
//! let elem = self.label.resolve().await?;
//! elem.text().await
//! }
//!
//! pub async fn is_ticked(&self) -> WebDriverResult<bool> {
//! let elem = self.input.resolve().await?;
//! let prop = elem.prop("checked").await?;
//! Ok(prop.unwrap_or_default() == "true")
//! }
//!
//! pub async fn tick(&self) -> WebDriverResult<()> {
//! if !self.is_ticked().await? {
//! let elem = self.input.resolve().await?;
//! elem.click().await?;
//! assert!(self.is_ticked().await?);
//! }
//! Ok(())
//! }
//! }
//! ```
//!
//! See the [`components`] documentation for more details.
//!
// Re-export StringMatch if needed.
pub use stringmatch;
// Export types at root level.
pub use cookie;
pub use ;
pub use ;
pub use WebElement;
/// Allow importing the common types via `use thirtyfour::prelude::*`.
/// Action chains allow for more complex user interactions with the keyboard and mouse.
/// Alert handling.
/// WebDriver BiDi (W3C bidirectional protocol) support — typed commands and
/// event subscription over a WebSocket. Negotiated via the `webSocketUrl`
/// capability. See [`bidi`] for the API.
/// Chrome DevTools Protocol (CDP) support — typed commands, optional event
/// subscription via WebSocket. See [`cdp`] for the API.
/// Common wrappers used by both async and sync implementations.
/// Components and component wrappers.
/// Error wrappers.
/// Extensions for specific browsers.
/// Auto-download and lifetime-managed local WebDriver process management.
///
/// Available only with the default `manager` feature. See the module docs for
/// details and examples.
/// Everything related to driving the underlying WebDriver session.
/// Miscellaneous support functions for `thirtyfour` tests.
const VERSION: &str = env!;