Skip to main content

uiautomator2/
lib.rs

1//! Async Rust client for [uiautomator2](https://github.com/openatx/uiautomator2)
2//! Android UI automation. Built on the `adbutils` crate.
3//!
4//! The high-level `Device` API (`d(text="OK").click()`) lands in M2; M1 provides
5//! the transport ([`jsonrpc`]) and on-device server lifecycle ([`server::Server`]).
6
7pub mod device;
8pub mod errors;
9#[cfg(feature = "ext")]
10pub mod ext;
11#[cfg(feature = "image")]
12pub mod image;
13#[cfg(feature = "input")]
14pub mod input;
15pub mod jsonrpc;
16pub mod proto;
17#[cfg(feature = "screenrecord")]
18pub mod screenrecord;
19pub mod selector;
20pub mod server;
21pub mod session;
22pub mod settings;
23pub mod swipe;
24pub mod uiobject;
25#[cfg(feature = "xpath")]
26pub mod watcher;
27#[cfg(feature = "xpath")]
28pub mod xpath;
29
30pub use device::{connect_usb, Device};
31pub use errors::{Error, Result};
32#[cfg(feature = "input")]
33pub use input::EditorAction;
34pub use proto::{Direction, DEFAULT_SERVER_PORT};
35pub use selector::Selector;
36pub use server::Server;
37pub use session::Session;
38pub use settings::Settings;
39pub use uiobject::UiObject;
40#[cfg(feature = "xpath")]
41pub use watcher::Watcher;
42
43use adbutils::AdbDevice;
44
45/// Connect to a device (sole one, or by serial) and start the server.
46/// Mirrors `u2.connect()`.
47pub async fn connect(serial: Option<&str>) -> Result<Device> {
48    connect_usb(serial).await
49}
50
51/// Provision and start the raw server manager on `dev` (lower-level than
52/// [`connect`]; most users want [`connect`]/[`Device`]).
53pub async fn connect_server(dev: AdbDevice, port: u16) -> Result<Server> {
54    Server::connect(dev, port).await
55}