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 async fn tree(&self, include: Option<IncludeScope>) -> Result<A11yNode, ExpectationFailure> {
44 IosDriver::tree(self, include).await
45 }
46
47 async fn find(
48 &self,
49 selector: &Selector,
50 include: Option<IncludeScope>,
51 ) -> Result<bool, ExpectationFailure> {
52 IosDriver::find(self, selector, include).await
53 }
54
55 async fn find_one(
56 &self,
57 selector: &Selector,
58 include: Option<IncludeScope>,
59 ) -> Result<Option<A11yNode>, ExpectationFailure> {
60 IosDriver::find_one(self, selector, include).await
61 }
62
63 async fn find_all(
64 &self,
65 selector: &Selector,
66 include: Option<IncludeScope>,
67 ) -> Result<Vec<A11yNode>, ExpectationFailure> {
68 IosDriver::find_all(self, selector, include).await
69 }
70
71 async fn find_norm_coord(
72 &self,
73 selector: &Selector,
74 ) -> Result<Option<(f64, f64)>, ExpectationFailure> {
75 IosDriver::find_norm_coord(self, selector).await
76 }
77
78 async fn find_text_by_ocr(
79 &self,
80 text: &str,
81 locales: &[String],
82 recognition_level: &str,
83 ) -> Result<Option<OcrFrame>, ExpectationFailure> {
84 IosDriver::find_text_by_ocr(self, text, locales, recognition_level).await
85 }
86
87 async fn system_popups(
88 &self,
89 include: Option<IncludeScope>,
90 ) -> Result<Vec<SystemPopup>, ExpectationFailure> {
91 IosDriver::system_popups(self, include).await
92 }
93
94 async fn system_popup_action(
95 &self,
96 popup_id: &str,
97 button_id: &str,
98 ) -> Result<bool, ExpectationFailure> {
99 IosDriver::system_popup_action(self, popup_id, button_id).await
100 }
101
102 async fn wait_for(
103 &self,
104 selector: &Selector,
105 timeout: Duration,
106 include: Option<IncludeScope>,
107 ) -> Result<A11yNode, ExpectationFailure> {
108 IosDriver::wait_for(self, selector, timeout, include).await
109 }
110
111 async fn tap(
114 &self,
115 selector: &Selector,
116 include: Option<IncludeScope>,
117 ) -> Result<(), ExpectationFailure> {
118 IosDriver::tap(self, selector, include).await
119 }
120
121 async fn tap_with_mode(
122 &self,
123 selector: &Selector,
124 mode: TapMode,
125 include: Option<IncludeScope>,
126 ) -> Result<(), ExpectationFailure> {
127 IosDriver::tap_with_mode(self, selector, mode, include).await
128 }
129
130 async fn tap_at_norm_coord(&self, nx: f64, ny: f64) -> Result<(), ExpectationFailure> {
131 IosDriver::tap_at_norm_coord(self, nx, ny).await
132 }
133
134 async fn tap_by_id(&self, id: &str) -> Result<(), ExpectationFailure> {
135 IosDriver::tap_by_id(self, id).await
136 }
137
138 async fn double_tap(
139 &self,
140 selector: &Selector,
141 include: Option<IncludeScope>,
142 ) -> Result<(), ExpectationFailure> {
143 IosDriver::double_tap(self, selector, include).await
144 }
145
146 async fn long_press(
147 &self,
148 selector: &Selector,
149 duration: Duration,
150 include: Option<IncludeScope>,
151 ) -> Result<(), ExpectationFailure> {
152 IosDriver::long_press(self, selector, duration, include).await
153 }
154
155 async fn fill(
156 &self,
157 selector: &Selector,
158 text: &str,
159 include: Option<IncludeScope>,
160 ) -> Result<(), ExpectationFailure> {
161 IosDriver::fill(self, selector, text, include).await
162 }
163
164 async fn clear(
165 &self,
166 selector: &Selector,
167 include: Option<IncludeScope>,
168 ) -> Result<(), ExpectationFailure> {
169 IosDriver::clear(self, selector, include).await
170 }
171
172 async fn press_key(&self, key: KeyName) -> Result<(), ExpectationFailure> {
173 IosDriver::press_key(self, key).await
174 }
175
176 async fn scroll(
177 &self,
178 selector: &Selector,
179 direction: SwipeDirection,
180 ) -> Result<(), ExpectationFailure> {
181 IosDriver::scroll(self, selector, direction).await
182 }
183
184 async fn swipe_once(&self, direction: SwipeDirection) -> Result<(), ExpectationFailure> {
185 IosDriver::swipe_once(self, direction).await
186 }
187
188 async fn swipe_at_norm_coord(
189 &self,
190 from: (f64, f64),
191 to: (f64, f64),
192 ) -> Result<(), ExpectationFailure> {
193 IosDriver::swipe_at_norm_coord(self, from, to).await
194 }
195
196 async fn hide_keyboard(&self) -> Result<(), ExpectationFailure> {
197 IosDriver::hide_keyboard(self).await
198 }
199
200 async fn back(&self) -> Result<(), ExpectationFailure> {
201 IosDriver::back(self).await
202 }
203
204 async fn set_orientation(&self, orientation: Orientation) -> Result<(), ExpectationFailure> {
205 IosDriver::set_orientation(self, orientation).await
206 }
207
208 async fn foreground(&self, bundle_id: &str) -> Result<(), ExpectationFailure> {
209 IosDriver::foreground(self, bundle_id).await
210 }
211
212 async fn webview_eval(&self, js: &str) -> Result<serde_json::Value, ExpectationFailure> {
213 IosDriver::webview_eval(self, js).await
214 }
215}