use async_trait::async_trait;
use std::time::Duration;
use smix_error::ExpectationFailure;
use smix_input::{KeyName, SwipeDirection};
use smix_runner_client::{IncludeScope, OcrFrame, SystemPopup, TapMode};
use smix_screen::A11yNode;
use smix_selector::Selector;
use crate::Orientation;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Platform {
Ios,
Android,
}
#[async_trait]
pub trait Driver: Send + Sync {
fn platform(&self) -> Platform;
fn as_ios_driver(&self) -> Option<&crate::IosDriver> {
None
}
fn set_target_bundle_id(&mut self, _bundle: &str) {}
fn set_auto_activate(&mut self, _activate: bool) {}
fn set_force_key_events(&mut self, _force: bool) {}
fn set_session_id(&mut self, _id: Option<String>) {}
async fn tree(&self, include: Option<IncludeScope>) -> Result<A11yNode, ExpectationFailure>;
async fn find(
&self,
selector: &Selector,
include: Option<IncludeScope>,
) -> Result<bool, ExpectationFailure>;
async fn find_one(
&self,
selector: &Selector,
include: Option<IncludeScope>,
) -> Result<Option<A11yNode>, ExpectationFailure>;
async fn find_all(
&self,
selector: &Selector,
include: Option<IncludeScope>,
) -> Result<Vec<A11yNode>, ExpectationFailure>;
async fn find_norm_coord(
&self,
selector: &Selector,
) -> Result<Option<(f64, f64)>, ExpectationFailure>;
async fn find_text_by_ocr(
&self,
text: &str,
locales: &[String],
recognition_level: &str,
) -> Result<Option<OcrFrame>, ExpectationFailure>;
async fn system_popups(
&self,
include: Option<IncludeScope>,
) -> Result<Vec<SystemPopup>, ExpectationFailure>;
async fn system_popup_action(
&self,
popup_id: &str,
button_id: &str,
) -> Result<bool, ExpectationFailure>;
async fn wait_for(
&self,
selector: &Selector,
timeout: Duration,
include: Option<IncludeScope>,
) -> Result<A11yNode, ExpectationFailure>;
async fn tap(
&self,
selector: &Selector,
include: Option<IncludeScope>,
) -> Result<(), ExpectationFailure>;
async fn tap_with_mode(
&self,
selector: &Selector,
mode: TapMode,
include: Option<IncludeScope>,
) -> Result<(), ExpectationFailure>;
async fn tap_at_norm_coord(&self, nx: f64, ny: f64) -> Result<(), ExpectationFailure>;
async fn tap_by_id(&self, id: &str) -> Result<(), ExpectationFailure>;
async fn double_tap(
&self,
selector: &Selector,
include: Option<IncludeScope>,
) -> Result<(), ExpectationFailure>;
async fn long_press(
&self,
selector: &Selector,
duration: Duration,
include: Option<IncludeScope>,
) -> Result<(), ExpectationFailure>;
async fn fill(
&self,
selector: &Selector,
text: &str,
include: Option<IncludeScope>,
) -> Result<(), ExpectationFailure>;
async fn clear(
&self,
selector: &Selector,
include: Option<IncludeScope>,
) -> Result<(), ExpectationFailure>;
async fn press_key(&self, key: KeyName) -> Result<(), ExpectationFailure>;
async fn scroll(
&self,
selector: &Selector,
direction: SwipeDirection,
) -> Result<(), ExpectationFailure>;
async fn swipe_once(&self, direction: SwipeDirection) -> Result<(), ExpectationFailure>;
async fn swipe_at_norm_coord(
&self,
from: (f64, f64),
to: (f64, f64),
) -> Result<(), ExpectationFailure>;
async fn hide_keyboard(&self) -> Result<(), ExpectationFailure>;
async fn back(&self) -> Result<(), ExpectationFailure>;
async fn set_orientation(&self, orientation: Orientation) -> Result<(), ExpectationFailure>;
async fn foreground(&self, bundle_id: &str) -> Result<(), ExpectationFailure>;
async fn webview_eval(&self, js: &str) -> Result<serde_json::Value, ExpectationFailure>;
}