API 参考
DeviceDriver / Locator / Element / 错误
DeviceDriver trait
aixautosdk::core::device::DeviceDriver —— 所有平台驱动实现的统一接口(节选):
#[async_trait]
pub trait DeviceDriver: Send + Sync {
async fn info(&self) -> Result<DeviceInfo>;
async fn screen_size(&self) -> Result<ScreenSize>;
fn platform(&self) -> Platform;
async fn find_element(&self, locator: &Locator) -> Result<Element>;
async fn find_elements(&self, locator: &Locator) -> Result<Vec<Element>>;
async fn capture_ui_tree(&self) -> Result<UITreeNode>;
async fn screenshot(&self) -> Result<Vec<u8>>;
async fn tap(&self, x: f64, y: f64) -> Result<()>;
async fn double_tap(&self, x: f64, y: f64) -> Result<()>;
async fn long_press(&self, x: f64, y: f64, duration_secs: f64) -> Result<()>;
async fn swipe(&self, x1: f64, y1: f64, x2: f64, y2: f64, duration: f64) -> Result<()>;
async fn input_text(&self, text: &str) -> Result<()>;
async fn press_key(&self, key: KeyCode) -> Result<()>;
// launch_app / terminate_app / home / back / clipboard / 便捷 tap_element(locator) …
}Locator(类型安全枚举)
#[serde(tag = "strategy", content = "value", rename_all = "snake_case")]
pub enum Locator {
Label(String), Text(String), TextContains(String), XPath(String),
ResourceId(String), Predicate(String), ClassName(String),
AutomationId(String), ContentDesc(String), ControlType(String), Role(String),
}
// 便捷构造:Locator::text("…") / ::label("…") / ::resource_id("…") / ::xpath("…")
// JSON 形态:{ "strategy": "text", "value": "登录" }Element / Rect / ScreenSize / KeyCode / Platform
pub struct Element { pub id, element_type, label, text, xpath, rect: Rect, enabled, visible, attributes }
pub struct Rect { pub x, y, width, height: f64 } // .center_x() / .center_y()
pub struct ScreenSize { pub width, height: u32 } // .center_x() / .center_y()
pub enum KeyCode { Enter, Backspace, Tab, Escape, ArrowUp, Home, F1, /* …F12 */ Custom(u32) }
pub enum Platform { IOS, Android, Windows, MacOS }常用 prelude 导出
use aixautosdk::core::prelude::*; 引入:DeviceDriver、DeviceManager、DeviceConfig、DeviceInfo、Element、Rect、ScreenSize、KeyCode、Platform、Locator、LocatorEntry、UITreeNode、WaitEngine、BackendClient、Screenshot、Scriptlet / execute_scriptlet、AumxError、Result。
错误类型
pub enum AumxError {
DeviceNotFound(String),
ElementNotFound { locator: Locator, platform: Platform, device_id: String },
Timeout(Duration, String), AssertionFailed(String),
WdaSession(String), NoSession, Adb(String),
SidecarError(String), SidecarDead,
BackendApi { status: u16, message: String }, BackendAuth(String),
UnsupportedPlatform(String), UnsupportedOperation(String),
Io(std::io::Error), Other(String), /* … */
}完整、最新的 API 以源码与
cargo doc -p aixautosdk --open为准;本指南覆盖集成所需的稳定面。