Skip to main content

automata_windows/
element_stub.rs

1// ── Non-Windows stubs ─────────────────────────────────────────────────────────
2
3/// No-op `Browser` stub for non-Windows platforms.
4pub struct NoBrowser;
5
6impl ui_automata::Browser for NoBrowser {
7    fn ensure(&self) -> Result<(), ui_automata::AutomataError> {
8        Err(ui_automata::AutomataError::Platform("Windows only".into()))
9    }
10    fn open_tab(&self, _url: Option<&str>) -> Result<String, ui_automata::AutomataError> {
11        Err(ui_automata::AutomataError::Platform("Windows only".into()))
12    }
13    fn close_tab(&self, _tab_id: &str) -> Result<(), ui_automata::AutomataError> {
14        Err(ui_automata::AutomataError::Platform("Windows only".into()))
15    }
16    fn activate_tab(&self, _tab_id: &str) -> Result<(), ui_automata::AutomataError> {
17        Err(ui_automata::AutomataError::Platform("Windows only".into()))
18    }
19    fn navigate(&self, _tab_id: &str, _url: &str) -> Result<(), ui_automata::AutomataError> {
20        Err(ui_automata::AutomataError::Platform("Windows only".into()))
21    }
22    fn eval(&self, _tab_id: &str, _expr: &str) -> Result<String, ui_automata::AutomataError> {
23        Err(ui_automata::AutomataError::Platform("Windows only".into()))
24    }
25    fn tab_info(&self, _tab_id: &str) -> Result<ui_automata::TabInfo, ui_automata::AutomataError> {
26        Err(ui_automata::AutomataError::Platform("Windows only".into()))
27    }
28    fn tabs(&self) -> Result<Vec<(String, ui_automata::TabInfo)>, ui_automata::AutomataError> {
29        Err(ui_automata::AutomataError::Platform("Windows only".into()))
30    }
31}
32
33#[derive(Clone)]
34pub struct UIElement;
35
36impl ui_automata::Element for UIElement {
37    fn name(&self) -> Option<String> {
38        None
39    }
40    fn role(&self) -> String {
41        String::new()
42    }
43    fn text(&self) -> Result<String, ui_automata::AutomataError> {
44        Err(ui_automata::AutomataError::Platform("Windows only".into()))
45    }
46    fn inner_text(&self) -> Result<String, ui_automata::AutomataError> {
47        Err(ui_automata::AutomataError::Platform("Windows only".into()))
48    }
49    fn is_enabled(&self) -> Result<bool, ui_automata::AutomataError> {
50        Err(ui_automata::AutomataError::Platform("Windows only".into()))
51    }
52    fn is_visible(&self) -> Result<bool, ui_automata::AutomataError> {
53        Err(ui_automata::AutomataError::Platform("Windows only".into()))
54    }
55    fn process_id(&self) -> Result<u32, ui_automata::AutomataError> {
56        Err(ui_automata::AutomataError::Platform("Windows only".into()))
57    }
58    fn bounds(&self) -> Result<(i32, i32, i32, i32), ui_automata::AutomataError> {
59        Err(ui_automata::AutomataError::Platform("Windows only".into()))
60    }
61    fn children(&self) -> Result<Vec<Self>, ui_automata::AutomataError> {
62        Err(ui_automata::AutomataError::Platform("Windows only".into()))
63    }
64    fn parent(&self) -> Option<Self> {
65        None
66    }
67    fn click(&self) -> Result<(), ui_automata::AutomataError> {
68        Err(ui_automata::AutomataError::Platform("Windows only".into()))
69    }
70    fn double_click(&self) -> Result<(), ui_automata::AutomataError> {
71        Err(ui_automata::AutomataError::Platform("Windows only".into()))
72    }
73    fn hover(&self) -> Result<(), ui_automata::AutomataError> {
74        Err(ui_automata::AutomataError::Platform("Windows only".into()))
75    }
76    fn click_at(
77        &self,
78        _x: f64,
79        _y: f64,
80        _k: ui_automata::ClickType,
81    ) -> Result<(), ui_automata::AutomataError> {
82        Err(ui_automata::AutomataError::Platform("Windows only".into()))
83    }
84    fn type_text(&self, _text: &str) -> Result<(), ui_automata::AutomataError> {
85        Err(ui_automata::AutomataError::Platform("Windows only".into()))
86    }
87    fn press_key(&self, _key: &str) -> Result<(), ui_automata::AutomataError> {
88        Err(ui_automata::AutomataError::Platform("Windows only".into()))
89    }
90    fn set_value(&self, _value: &str) -> Result<(), ui_automata::AutomataError> {
91        Err(ui_automata::AutomataError::Platform("Windows only".into()))
92    }
93    fn focus(&self) -> Result<(), ui_automata::AutomataError> {
94        Err(ui_automata::AutomataError::Platform("Windows only".into()))
95    }
96    fn scroll_into_view(&self) -> Result<(), ui_automata::AutomataError> {
97        Err(ui_automata::AutomataError::Platform("Windows only".into()))
98    }
99    fn activate_window(&self) -> Result<(), ui_automata::AutomataError> {
100        Err(ui_automata::AutomataError::Platform("Windows only".into()))
101    }
102    fn minimize_window(&self) -> Result<(), ui_automata::AutomataError> {
103        Err(ui_automata::AutomataError::Platform("Windows only".into()))
104    }
105    fn close(&self) -> Result<(), ui_automata::AutomataError> {
106        Err(ui_automata::AutomataError::Platform("Windows only".into()))
107    }
108}
109
110use crate::{ClickType, UiError};
111
112impl Default for UIElement {
113    fn default() -> Self {
114        Self
115    }
116}
117
118impl UIElement {
119    pub fn name(&self) -> Option<String> {
120        None
121    }
122    pub fn name_or_empty(&self) -> String {
123        String::new()
124    }
125    pub fn role(&self) -> String {
126        String::new()
127    }
128    pub fn id(&self) -> Option<String> {
129        None
130    }
131    pub fn id_or_empty(&self) -> String {
132        String::new()
133    }
134    pub fn process_id(&self) -> Result<u32, UiError> {
135        Err(UiError::Platform("Windows only".into()))
136    }
137    pub fn bounds(&self) -> Result<(i32, i32, i32, i32), UiError> {
138        Err(UiError::Platform("Windows only".into()))
139    }
140    pub fn is_enabled(&self) -> Result<bool, UiError> {
141        Err(UiError::Platform("Windows only".into()))
142    }
143    pub fn is_visible(&self) -> Result<bool, UiError> {
144        Err(UiError::Platform("Windows only".into()))
145    }
146    pub fn focus(&self) -> Result<(), UiError> {
147        Err(UiError::Platform("Windows only".into()))
148    }
149    pub fn control_type(&self) -> Result<String, UiError> {
150        Err(UiError::Platform("Windows only".into()))
151    }
152    pub fn children(&self) -> Result<Vec<UIElement>, UiError> {
153        Err(UiError::Platform("Windows only".into()))
154    }
155    pub fn parent(&self) -> Result<Option<UIElement>, UiError> {
156        Err(UiError::Platform("Windows only".into()))
157    }
158    pub fn text(&self) -> Result<String, UiError> {
159        Err(UiError::Platform("Windows only".into()))
160    }
161    pub fn inner_text(&self) -> Result<String, UiError> {
162        Err(UiError::Platform("Windows only".into()))
163    }
164    pub fn click(&self) -> Result<(), UiError> {
165        Err(UiError::Platform("Windows only".into()))
166    }
167    pub fn double_click(&self) -> Result<(), UiError> {
168        Err(UiError::Platform("Windows only".into()))
169    }
170    pub fn click_at_position(
171        &self,
172        _x_pct: u8,
173        _y_pct: u8,
174        _kind: ClickType,
175    ) -> Result<(), UiError> {
176        Err(UiError::Platform("Windows only".into()))
177    }
178    pub fn type_text(&self, _text: &str, _use_clipboard: bool) -> Result<(), UiError> {
179        Err(UiError::Platform("Windows only".into()))
180    }
181    pub fn press_key(&self, _key: &str) -> Result<(), UiError> {
182        Err(UiError::Platform("Windows only".into()))
183    }
184    pub fn activate_window(&self) -> Result<(), UiError> {
185        Err(UiError::Platform("Windows only".into()))
186    }
187    pub fn minimize_window(&self) -> Result<(), UiError> {
188        Err(UiError::Platform("Windows only".into()))
189    }
190    pub fn close(&self) -> Result<(), UiError> {
191        Err(UiError::Platform("Windows only".into()))
192    }
193}