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
pub(crate) mod inner {
pub enum Ec {
InnerTextContains(String),
AttributeValueIs(String, String),
LocalStorageAttributeValueIs(String, String),
LocationSearchIs(String),
}
impl core::fmt::Display for Ec {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Ec::InnerTextContains(text) => write!(
f,
"HTML element innerText contains the text {:?} (`{:?}`)",
text, &self
),
Ec::AttributeValueIs(attr, value) => {
write!(
f,
"HTML element attribute {:?} value is equal to {:?} (`{:?}`)",
attr, value, &self
)
}
Ec::LocalStorageAttributeValueIs(attr, value) => {
write!(
f,
"localStorage attribute {:?} value is equal to {:?} (`{:?}`)",
attr, value, &self
)
}
Ec::LocationSearchIs(value) => {
write!(
f,
"window.location.search is equal to {:?} (`{:?}`)",
value, &self
)
}
}
}
}
impl core::fmt::Debug for Ec {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Ec::InnerTextContains(text) => write!(f, "Ec::InnerTextContains({text:?})"),
Ec::AttributeValueIs(attr, value) => {
write!(f, "Ec::AttributeValueIs({attr:?}, {value:?})")
}
Ec::LocalStorageAttributeValueIs(attr, value) => {
write!(f, "Ec::LocalStorageAttributeValueIs({attr:?}, {value:?})",)
}
Ec::LocationSearchIs(value) => write!(f, "Ec::LocationSearchIs({value:?})"),
}
}
}
}
/// Conditions to be expected while waiting.
#[allow(non_snake_case)]
pub mod Ec {
use super::inner;
/// The property `innerText` of an element contains the given text.
///
/// ```rust,ignore
/// use web_sys_ec::{Ec, Wait};
///
/// Wait(1).until(("p", Ec::InnerTextContains("text")));
/// ```
#[inline]
pub fn InnerTextContains(text: impl Into<String>) -> inner::Ec {
inner::Ec::InnerTextContains(text.into())
}
/// The attribute value of an element is equal to the given value.
///
/// ```rust,ignore
/// use web_sys_ec::{Ec, Wait};
///
/// Wait(1).until(("p", Ec::AttributeValueIs("attr", "value")));
/// ```
#[inline]
pub fn AttributeValueIs(attr: impl Into<String>, value: impl Into<String>) -> inner::Ec {
inner::Ec::AttributeValueIs(attr.into(), value.into())
}
/// The localStorage attribute value is equal to the given value.
///
/// ```rust,ignore
/// use web_sys_ec::{Ec, Wait};
///
/// Wait(1).until(Ec::LocalStorageAttributeValueIs("key", "value"));
/// ```
#[inline]
pub fn LocalStorageAttributeValueIs(
attr: impl Into<String>,
value: impl Into<String>,
) -> inner::Ec {
inner::Ec::LocalStorageAttributeValueIs(attr.into(), value.into())
}
/// The `window.location.search` is equal to the given value.
///
/// ```rust,ignore
/// use web_sys_ec::{Ec, Wait};
///
/// Wait(1).until(Ec::LocationSearchIs("?key=value"));
/// ```
#[inline]
pub fn LocationSearchIs(value: impl Into<String>) -> inner::Ec {
inner::Ec::LocationSearchIs(value.into())
}
}