Files
go-mobile-uiautomator/libs/doc.go

51 lines
2.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Package libs 提供了完整的 Android UIAutomator2 自动化框架。
//
// 本包是 Python uiautomator2 的 Go 语言实现,通过 ADB 隧道协议与运行在 Android 设备上的
// UIAutomator2 HTTP 服务直连提供设备控制、UI 操作、文本输入等功能。
// 零外部依赖,仅使用 Go 标准库。
//
// 核心组件:
// - Device设备客户端管理 UIAutomator2 服务生命周期,提供所有设备操作
// - UiObjectUI 控件对象,支持点击、输入、滑动、等待、滚动等操作
// - SelectorUI 元素选择器,支持文本、类名、资源 ID、描述等多种查询条件
// - JsonRpcWrapperJSON-RPC 2.0 调用封装,自动错误映射和重试
// - InputMethod通过 AdbKeyboard 输入法实现快速文本输入(支持中文)
// - SwipeExt扩展滑动操作按方向、比例滑动
// - WatchContext弹窗/对话框自动监控和处理
// - Session应用会话管理自动检测应用存活状态
// - Settings线程安全的设备配置管理等待超时、操作延迟等
//
// 通信层:
// - AdbTunnelDevice通过 ADB 隧道直连设备,与 Python uiautomator2 方案完全一致
// - http.Transport自定义 DialContext 将 HTTP 连接替换为 ADB 隧道
// - HttpRequest高层 HTTP 请求封装
// - JsonRpcCallJSON-RPC 2.0 请求/响应处理
//
// 使用示例:
//
// // 创建设备连接(自动推送 u2.jar、启动服务
// d, err := libs.NewDevice("emulator-5554")
// // 自定义 ADB 地址: libs.NewDevice("emulator-5554", "192.168.1.100:5037")
// if err != nil {
// log.Fatal(err)
// }
// defer d.Close()
//
// // 便捷选择器,链式调用
// d.ByText("登录").Click()
// d.ByResourceId("com.example:id/input").SetText("admin")
//
// // 多条件组合查找
// d.By(libs.P{"className": "android.widget.Button", "text": "确定"}).Click()
//
// // 使用 AdbKeyboard 输入中文
// im := libs.NewInputMethod(d)
// im.SendKeys("你好世界")
//
// // 使用 Watcher 自动处理弹窗
// w := libs.NewWatchContext(d, true)
// w.WhenText("允许").Click()
// w.Start()
// defer w.Stop()
package libs