allwright/
client_locator.rs1use super::selectors::chain_selector_for_transport;
2use super::types::{
3 CommandOptions, HighlightOptions, Locator, Page, PressOptions, Result, WaitForSelectorOptions,
4};
5
6impl Locator {
7 pub fn page(&self) -> &Page {
8 &self.page
9 }
10
11 pub fn selector(&self) -> &str {
12 &self.selector
13 }
14
15 pub fn locator(&self, css_selector: impl Into<String>) -> Locator {
16 let child_selector = css_selector.into();
17 Locator {
18 page: self.page.clone(),
19 selector: chain_selector_for_transport(&self.selector, &child_selector),
20 }
21 }
22
23 pub async fn frame(&self) -> Result<Page> {
24 self.frame_with_options(CommandOptions::default()).await
25 }
26
27 pub async fn frame_with_options(&self, options: CommandOptions) -> Result<Page> {
28 self.page
29 .frame_with_options(self.selector.clone(), options)
30 .await
31 }
32
33 pub async fn click(&self) -> Result<()> {
34 self.page.click(self.selector.clone()).await
35 }
36
37 pub async fn click_with_options(&self, options: CommandOptions) -> Result<()> {
38 self.page
39 .click_with_options(self.selector.clone(), options)
40 .await
41 }
42
43 pub async fn count(&self) -> Result<u32> {
44 self.page.count(self.selector.clone()).await
45 }
46
47 pub async fn count_with_options(&self, options: CommandOptions) -> Result<u32> {
48 self.page
49 .count_with_options(self.selector.clone(), options)
50 .await
51 }
52
53 pub async fn highlight(&self) -> Result<()> {
54 self.page.highlight(self.selector.clone()).await
55 }
56
57 pub async fn highlight_with_options(&self, options: HighlightOptions) -> Result<()> {
58 self.page
59 .highlight_with_options(self.selector.clone(), options)
60 .await
61 }
62
63 pub async fn focus(&self) -> Result<()> {
64 self.page.focus(self.selector.clone()).await
65 }
66
67 pub async fn focus_with_options(&self, options: CommandOptions) -> Result<()> {
68 self.page
69 .focus_with_options(self.selector.clone(), options)
70 .await
71 }
72
73 pub async fn fill(&self, value: impl Into<String>) -> Result<()> {
74 self.page.fill(self.selector.clone(), value.into()).await
75 }
76
77 pub async fn fill_with_options(
78 &self,
79 value: impl Into<String>,
80 options: CommandOptions,
81 ) -> Result<()> {
82 self.page
83 .fill_with_options(self.selector.clone(), value.into(), options)
84 .await
85 }
86
87 pub async fn hover(&self) -> Result<()> {
88 self.page.hover(self.selector.clone()).await
89 }
90
91 pub async fn hover_with_options(&self, options: CommandOptions) -> Result<()> {
92 self.page
93 .hover_with_options(self.selector.clone(), options)
94 .await
95 }
96
97 pub async fn press(&self, key: impl Into<String>) -> Result<()> {
98 self.page.press(self.selector.clone(), key.into()).await
99 }
100
101 pub async fn press_with_options(
102 &self,
103 key: impl Into<String>,
104 options: PressOptions,
105 ) -> Result<()> {
106 self.page
107 .press_with_options(self.selector.clone(), key.into(), options)
108 .await
109 }
110
111 pub async fn text_content(&self) -> Result<Option<String>> {
112 self.page.text_content(self.selector.clone()).await
113 }
114
115 pub async fn text_content_with_options(
116 &self,
117 options: CommandOptions,
118 ) -> Result<Option<String>> {
119 self.page
120 .text_content_with_options(self.selector.clone(), options)
121 .await
122 }
123
124 pub async fn inner_text(&self) -> Result<String> {
125 self.page.inner_text(self.selector.clone()).await
126 }
127
128 pub async fn inner_text_with_options(&self, options: CommandOptions) -> Result<String> {
129 self.page
130 .inner_text_with_options(self.selector.clone(), options)
131 .await
132 }
133
134 pub async fn wait_for(&self) -> Result<()> {
135 self.wait_for_with_options(WaitForSelectorOptions {
136 visible: Some(true),
137 ..Default::default()
138 })
139 .await
140 }
141
142 pub async fn wait_for_with_options(&self, options: WaitForSelectorOptions) -> Result<()> {
143 let mut options = options;
144 if options.visible.is_none() {
145 options.visible = Some(true);
146 }
147 self.page
148 .wait_for_selector_with_options(self.selector.clone(), options)
149 .await
150 }
151}