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
//! [](https://crates.io/crates/web-sys-ec)
//! [](https://github.com/mondeja/web-sys-ec/blob/master/LICENSE)
//! [](https://github.com/mondeja/web-sys-ec/actions)
//! [](https://docs.rs/web-sys-ec)
//! [](https://crates.io/crates/web-sys-ec)
//!
//! Expected conditions in Selenium-like style for WASM targets using [`web-sys`].
//!
//! # Rationale
//!
//! When you test your apps with `wasm-pack test`, you may want to use the
//! [`web-sys`] crate to interact with the DOM. This is a great way to test your
//! app in a real browser environment.
//!
//! However, actions in a browser are asynchronous, and you may want to wait for
//! certain conditions to be met while testing. This is where `web-sys-ec` comes
//! in.
//!
//! Provides an interface to interact with the DOM waiting for certain conditions
//! to be met. It is inspired by the Selenium syntax, where you can wait for
//! certain expected conditions to be met before proceeding with your tests.
//!
//! # Disclaimer
//!
//! I've created this library to help me with my own testing needs and it's far
//! away from being complete. Feel free to open pull requests or issues if you
//! find any bugs or have suggestions for improvements and I'll be happy to
//! review them.
//!
//! # Installation
//!
//! Add `web-sys-ec` to your `Cargo.toml`:
//!
//! ```toml
//! [dependencies]
//! web-sys-ec = "0.1"
//! ```
//!
//! # Usage
//!
//! Wait 10 seconds for a `<p>` HTML element to contain the text `"Select a language:"`:
//!
//! ```rust,ignore
//! use web_sys_ec::{By, Ec, Wait};
//!
//! Wait(10)
//! .until((
//! By::TagName("p"),
//! Ec::InnerTextContains("Select a language:"),
//! ))
//! .await;
//! ```
//!
//! Wait 1 second for the `<html>` HTML element to have the `lang` attribute set to
//! `"es"`:
//!
//! ```rust,ignore
//! use web_sys_ec::{By, Ec, Wait};
//!
//! Wait(1)
//! .until((
//! By::TagName("html"),
//! Ec::AttributeValueIs("lang", "es"),
//! ))
//! .await;
//! ```
//!
//! Wait 1 second for the local storage to have the `language` key set to `"es"`:
//!
//! ```rust,ignore
//! use web_sys_ec::{Ec, Wait};
//!
//! Wait(1).until(Ec::LocalStorageAttributeValueIs("language","es")).await;
//! ```
//!
//! Wait 200 milliseconds for a `<p id="foo">` HTML element to exist in the DOM:
//!
//! ```rust,ignore
//! use web_sys_ec::{By, Wait};
//!
//! Wait(0.2).until("p#foo").await;
//! ```
//!
//! If a condition is not met, it will panic with a message like:
//!
//! <!-- markdownlint-disable MD013 -->
//!
//! ```txt
//! Expected condition has not been met in the given time:
//! - Caller: tests/end2end/tests/csr_complete.rs:54:10
//! - Selector: HTML element with tag name 'html' (`By::TagName("html")`)
//! - Condition: HTML element attribute 'lang' value is equal to 'es' (`Ec::AttributeValueIs("lang", "es")`)
//! - Duration: 1s
//! - Poll frecuency: 20ms
//! - Number of attempts: 51
//! ```
//!
//! <!-- markdownlint-enable MD013 -->
//!
//! Note that the `Caller: ...` line will only be shown if you're using the `nightly`
//! toolchain and the `nightly` feature is enabled.
//!
//! # Features
//!
//! - `nightly`: Enables nightly toolchain support, which is currently needed to
//! provide caller tracking.
//!
//! [`web-sys`]: https://crates.io/crates/web-sys
pub
pub
pub use By;
pub use Condition;
pub use Ec;
pub use ;
pub use Wait;
pub use Wait as Waiter;
pub use WaitOptions;