
github.com/openatx/uiautomator2
概览
UIAutomator 是做 Android UI 测试的好工具,但要做到这一点,你得写 Java 代码、编译、安装 jar 并运行。这对所有测试人员来说都是复杂的步骤...... 这个项目是在Android设备上构建一个轻量级的jsonrpc服务器,这样我们只需写PC端脚本来编写UIAutomator测试。 在Android Studio -> 构建 -> 构建应用包/APK -> 构建APK 现在apk文件可以在app/build/outputs/apk/debug/app-debug.apk中找到 如果没有提供端口,默认为9008。使用-h查看所有选项。 脚本自动执行 adb forward tcp:9008 tcp:9008,无需手动转发。 方法定义文件 tools/methods.json 由 AutomatorService.java 接口同步生成,含所有方法的名称、参数类型、描述和示例值。 当 AutomatorService.java 接口有新增、删除或修改方法时,使用 sync-methods skill 同步更新 tools/methods.json。
概述(AI 翻译)
UIAutomator 是 很适合做安卓UI测试的工具,但要做到这一点,你得写Java。 编写代码,编译,安装jar,然后运行。这对所有人来说都是复杂的步骤 测试员…
这个项目是在安卓设备上构建一个轻量级的jsonrpc服务器,所以 我们只需写PC侧脚本来编写UIAutomator测试。
如何建造
构建APK
方法一:
在Android Studio -> Build -> Build App Bundle/APK -> Build APK
方法二:
现在apk文件可以在[[T4]中找到。
启动罐服务器
如果没有端口,默认为9008。使用-h查看所有选项。
测试服务器
JSON-RPC 测试工具
交互式 JSON-RPC 方法测试脚本,用于快速调试和验证各个 RPC 方法。
脚本自动执行 adb forward tcp:9008 tcp:9008,无需手动转发。
方法定义文件 tools/methods.json 由 AutomatorService.java 接口同步生成,含所有方法的名称、参数类型、描述和示例值。
同步Methods.json
当 AutomatorService.java 接口有新增、删除或修改方法时,使用 sync-methods skill 同步更新 tools/methods.json。
在 opencode 中对 AI 说:
AI 将自动:解析 Java 源码 → 提取所有方法 → 生成 methods.json →校验 JSON 合法性。
该 skill 位于
.opencode/skills/sync-methods/SKILL.md,纯 AI 驱动,无需额外脚本。
资源
- Google UiAutomator 教程
- 谷歌 UiAutomator API
- Maven 的 uiautomator 仓库
本页由 AI 翻译,技术细节请以原文为准。
README
以下为原文 README 节选,完整内容请查看原文。
Purpose
UIAutomator is a great tool to perform Android UI testing, but to do it, you have to write java code, compile it, install the jar, and run. It’s a complex steps for all testers…
This project is to build a light weight jsonrpc server in Android device, so that we can just write PC side script to write UIAutomator tests.
How to build
Build APK
Method 1:
In Android Studio -> Build -> Build App Bundle/APK -> Build APK
Method 2:
./gradlew assembleDebug
Now apk file can be found in app/build/outputs/apk/debug/app-debug.apk
Install APK
adb install -r app/build/outputs/apk/debug/app-debug.apk
The application ID is com.github.uiautomator2. Installing the APK is required to use the bundled AdbKeyboard input method.
Launch Jar server
adb push app/build/outputs/apk/debug/app-debug.apk /data/local/tmp
adb shell CLASSPATH=/data/local/tmp/app-debug.apk app_process / com.github.uiautomator2.Console [-p port]
If no port is provided, it defaults to 9008. Use -h to see all options.
Test server
adb forward tcp:9008 tcp:9008
curl -X POST -d '{"jsonrpc": "2.0", "id": "1f0f2655716023254ed2b57ba4198815", "method": "deviceInfo", "params": {}}' 'http://127.0.0.1:9008/jsonrpc/0'
# Expect output like
{'currentPackageName': 'com.smartisanos.launcher',
'displayHeight': 1920,
'displayRotation': 0,
'displaySizeDpX': 360,
'displaySizeDpY': 640,
'displayWidth': 1080,
'productName': 'surabaya',
'screenOn': True,
'sdkInt': 23,
'naturalOrientation': True}
JSON-RPC Test Tool
Interactive JSON-RPC script for quickly debugging and verifying RPC methods.
# Interactive mode (pick a method from categorized menus, enter params, see results)
python3 tools/test_jsonrpc.py
# Direct invocation
python3 tools/test_jsonrpc.py ping
python3 tools/test_jsonrpc.py click 100 200
python3 tools/test_jsonrpc.py dumpWindowHierarchy false
The script runs adb forward tcp:9008 tcp:9008 automatically, no manual forwarding needed.
Method definitions in tools/methods.json are generated from the AutomatorService.java interface, including the name, parameter types, description and example values of every method.
Sync methods.json
Whenever a method in AutomatorService.java is added, removed or changed, use the sync-methods skill to update tools/methods.json.
Ask the AI in opencode:
sync methods
The AI will parse the Java sources → extract every method → generate methods.json → validate the JSON.
The skill lives at
.opencode/skills/sync-methods/SKILL.md. It is entirely AI driven and needs no extra scripts.
AdbKeyboard (ATX Keyboard)
推荐工具
换一个关键词,或者移除筛选条件。
安装
npx skillfish add openatx/android-uiautomator-server-jar