Skip to main content

allwright/
client_locator.rs

1use super::selectors::chain_selector_for_transport;
2use super::types::{
3    ClickResult, CountResult, ElementResult, FillResult, HighlightResult, Locator, Page,
4    PressResult, Result, TextResult, WaitForSelectorResult,
5};
6
7impl Locator {
8    pub fn page(&self) -> &Page {
9        &self.page
10    }
11
12    pub fn selector(&self) -> &str {
13        &self.selector
14    }
15
16    pub fn locator(&self, css_selector: impl Into<String>) -> Locator {
17        let child_selector = css_selector.into();
18        Locator {
19            page: self.page.clone(),
20            selector: chain_selector_for_transport(&self.selector, &child_selector),
21        }
22    }
23
24    pub async fn click(&self) -> Result<ClickResult> {
25        self.page.click(self.selector.clone()).await
26    }
27
28    pub async fn count(&self) -> Result<CountResult> {
29        self.page.count(self.selector.clone()).await
30    }
31
32    pub async fn highlight(&self) -> Result<HighlightResult> {
33        self.page.highlight(self.selector.clone()).await
34    }
35
36    pub async fn focus(&self) -> Result<ElementResult> {
37        self.page.focus(self.selector.clone()).await
38    }
39
40    pub async fn fill(&self, value: impl Into<String>) -> Result<FillResult> {
41        self.page.fill(self.selector.clone(), value.into()).await
42    }
43
44    pub async fn hover(&self) -> Result<ElementResult> {
45        self.page.hover(self.selector.clone()).await
46    }
47
48    pub async fn press(&self, key: impl Into<String>) -> Result<PressResult> {
49        self.page.press(self.selector.clone(), key.into()).await
50    }
51
52    pub async fn text_content(&self) -> Result<TextResult> {
53        self.page.text_content(self.selector.clone()).await
54    }
55
56    pub async fn inner_text(&self) -> Result<TextResult> {
57        self.page.inner_text(self.selector.clone()).await
58    }
59
60    pub async fn wait_for(&self) -> Result<WaitForSelectorResult> {
61        self.page.wait_for_selector(self.selector.clone()).await
62    }
63}