1use async_trait::async_trait;
7use std::time::Duration;
8
9use smix_error::ExpectationFailure;
10use smix_input::{KeyName, SwipeDirection};
11use smix_runner_client::{IncludeScope, OcrFrame, SystemPopup, TapMode};
12use smix_screen::A11yNode;
13use smix_selector::Selector;
14
15use crate::traits::{Driver, Platform};
16use crate::{IosDriver, Orientation};
17
18#[async_trait]
19impl Driver for IosDriver {
20 fn platform(&self) -> Platform {
21 Platform::Ios
22 }
23
24 fn as_ios_driver(&self) -> Option<&IosDriver> {
25 Some(self)
26 }
27
28 fn set_target_bundle_id(&mut self, bundle: &str) {
32 self.runner_mut().set_target_bundle_id(bundle);
33 }
34
35 fn set_auto_activate(&mut self, activate: bool) {
38 self.runner_mut().set_auto_activate(activate);
39 }
40
41 fn set_force_key_events(&mut self, force: bool) {
46 use smix_runner_client::InputDispatchMode;
47 if force {
48 self.runner_mut()
49 .set_input_dispatch_mode(InputDispatchMode::KeyEvents);
50 }
51 }
52
53 fn set_session_id(&mut self, id: Option<String>) {
58 match id {
59 Some(sid) => self.runner_mut().set_session_id(sid),
60 None => self.runner_mut().clear_session_id(),
61 }
62 }
63
64 async fn tree(&self, include: Option<IncludeScope>) -> Result<A11yNode, ExpectationFailure> {
67 IosDriver::tree(self, include).await
68 }
69
70 async fn find(
71 &self,
72 selector: &Selector,
73 include: Option<IncludeScope>,
74 ) -> Result<bool, ExpectationFailure> {
75 IosDriver::find(self, selector, include).await
76 }
77
78 async fn find_one(
79 &self,
80 selector: &Selector,
81 include: Option<IncludeScope>,
82 ) -> Result<Option<A11yNode>, ExpectationFailure> {
83 IosDriver::find_one(self, selector, include).await
84 }
85
86 async fn find_all(
87 &self,
88 selector: &Selector,
89 include: Option<IncludeScope>,
90 ) -> Result<Vec<A11yNode>, ExpectationFailure> {
91 IosDriver::find_all(self, selector, include).await
92 }
93
94 async fn find_norm_coord(
95 &self,
96 selector: &Selector,
97 ) -> Result<Option<(f64, f64)>, ExpectationFailure> {
98 IosDriver::find_norm_coord(self, selector).await
99 }
100
101 async fn find_text_by_ocr(
102 &self,
103 text: &str,
104 locales: &[String],
105 recognition_level: &str,
106 ) -> Result<Option<OcrFrame>, ExpectationFailure> {
107 IosDriver::find_text_by_ocr(self, text, locales, recognition_level).await
108 }
109
110 async fn system_popups(
111 &self,
112 include: Option<IncludeScope>,
113 ) -> Result<Vec<SystemPopup>, ExpectationFailure> {
114 IosDriver::system_popups(self, include).await
115 }
116
117 async fn system_popup_action(
118 &self,
119 popup_id: &str,
120 button_id: &str,
121 ) -> Result<bool, ExpectationFailure> {
122 IosDriver::system_popup_action(self, popup_id, button_id).await
123 }
124
125 async fn wait_for(
126 &self,
127 selector: &Selector,
128 timeout: Duration,
129 include: Option<IncludeScope>,
130 ) -> Result<A11yNode, ExpectationFailure> {
131 IosDriver::wait_for(self, selector, timeout, include).await
132 }
133
134 async fn tap(
137 &self,
138 selector: &Selector,
139 include: Option<IncludeScope>,
140 ) -> Result<(), ExpectationFailure> {
141 IosDriver::tap(self, selector, include).await
142 }
143
144 async fn tap_with_mode(
145 &self,
146 selector: &Selector,
147 mode: TapMode,
148 include: Option<IncludeScope>,
149 ) -> Result<(), ExpectationFailure> {
150 IosDriver::tap_with_mode(self, selector, mode, include).await
151 }
152
153 async fn tap_at_norm_coord(&self, nx: f64, ny: f64) -> Result<(), ExpectationFailure> {
154 IosDriver::tap_at_norm_coord(self, nx, ny).await
155 }
156
157 async fn tap_by_id(&self, id: &str) -> Result<(), ExpectationFailure> {
158 IosDriver::tap_by_id(self, id).await
159 }
160
161 async fn double_tap(
162 &self,
163 selector: &Selector,
164 include: Option<IncludeScope>,
165 ) -> Result<(), ExpectationFailure> {
166 IosDriver::double_tap(self, selector, include).await
167 }
168
169 async fn long_press(
170 &self,
171 selector: &Selector,
172 duration: Duration,
173 include: Option<IncludeScope>,
174 ) -> Result<(), ExpectationFailure> {
175 IosDriver::long_press(self, selector, duration, include).await
176 }
177
178 async fn fill(
179 &self,
180 selector: &Selector,
181 text: &str,
182 include: Option<IncludeScope>,
183 ) -> Result<(), ExpectationFailure> {
184 IosDriver::fill(self, selector, text, include).await
185 }
186
187 async fn clear(
188 &self,
189 selector: &Selector,
190 include: Option<IncludeScope>,
191 ) -> Result<(), ExpectationFailure> {
192 IosDriver::clear(self, selector, include).await
193 }
194
195 async fn press_key(&self, key: KeyName) -> Result<(), ExpectationFailure> {
196 IosDriver::press_key(self, key).await
197 }
198
199 async fn scroll(
200 &self,
201 selector: &Selector,
202 direction: SwipeDirection,
203 ) -> Result<(), ExpectationFailure> {
204 IosDriver::scroll(self, selector, direction).await
205 }
206
207 async fn swipe_once(&self, direction: SwipeDirection) -> Result<(), ExpectationFailure> {
208 IosDriver::swipe_once(self, direction).await
209 }
210
211 async fn swipe_at_norm_coord(
212 &self,
213 from: (f64, f64),
214 to: (f64, f64),
215 ) -> Result<(), ExpectationFailure> {
216 IosDriver::swipe_at_norm_coord(self, from, to).await
217 }
218
219 async fn hide_keyboard(&self) -> Result<(), ExpectationFailure> {
220 IosDriver::hide_keyboard(self).await
221 }
222
223 async fn back(&self) -> Result<(), ExpectationFailure> {
224 IosDriver::back(self).await
225 }
226
227 async fn set_orientation(&self, orientation: Orientation) -> Result<(), ExpectationFailure> {
228 IosDriver::set_orientation(self, orientation).await
229 }
230
231 async fn foreground(&self, bundle_id: &str) -> Result<(), ExpectationFailure> {
232 IosDriver::foreground(self, bundle_id).await
233 }
234
235 async fn webview_eval(&self, js: &str) -> Result<serde_json::Value, ExpectationFailure> {
236 IosDriver::webview_eval(self, js).await
237 }
238}