AirtestIDE 可对用例进行录制, 但底层使用 uiautomation1, 缺陷是无法在播放状态使用, 而新版本的 uiautomation2 没有这个问题, 因此将底层升级以支持视频播放器 app 的用例录制.
poco_u2 是一个仅使用 UIAutomator2 的 Poco 驱动,面向 AirtestIDE 的嵌入式 Python 环境做了专门适配:
- 全面切换到 UIAutomator2,保持 Poco 的 API、返回数据结构和操作行为兼容。
- 坚持保留完整的 XML 属性(含
package),修复旧版本“包名丢失”问题。 - 启用非压缩层级(uncompressed hierarchy),在全屏播放场景下也能检测浮层/播放控件。
- 坐标归一化依据
window_size(与截图/IDE 高亮一致),解决中下区域“定位下偏”的问题。 - 内置第三方依赖自举逻辑(thirdparty 目录),无需改动 IDE 内置 Python。
- 兼容 Python 3.6 / 老 PIL:提供必要的兼容垫片(如
UnidentifiedImageError)。
使用时只需“替换 AirtestIDE 目录下的
poco为本版本”。尽管工程名标注为poco_u2,但在 IDE 中目录名仍须为poco(IDE 固定加载)。
- 关闭 AirtestIDE。
- 将本仓库的
tmp\\poco整个复制并替换到:C:\\Download\\AirtestIDE-win-1.2.17\\AirtestIDE\\poco
- 一键安装依赖(联网):
- 运行:
C:\\Download\\git\\uni\\tmp\\poco\\setup_airtest_uia2_deps.bat - 脚本会下载并安装所需依赖到
poco\\thirdparty\\site-packages,即使该目录为空也能一次拉齐。
- 运行:
- 设备初始化(建议一次性在任意 Python 环境执行):
python -m uiautomator2 init
- 打开 AirtestIDE,脚本中保持原有用法:
from poco.drivers.android.uiautomation import AndroidUiautomationPoco poco = AndroidUiautomationPoco(device_id="192.168.100.112:5555") h = poco.agent.hierarchy.dump()
- ImportError 依赖缺失:运行一键脚本,或确认
poco\\thirdparty\\site-packages下存在uiautomator2/adbutils/apkutils2/whichcraft/xmltodict/cigam/progress/...。 progress is not a package:IDE 自带progress.py会遮蔽包名,驱动已内置规避与兜底垫片;仍异常时运行一键脚本确保progress包到位。…uiautomator2-*.whl/.../assets/app-uiautomator.apk not found:驱动已强制以“解压后的 uiautomator2 包”导入并屏蔽.whl;若你手动加入.whl,请删除之。- 坐标漂移:本驱动使用
window_size归一化,与 IDE 高亮一致;若仍偏移,请反馈window_size、device.info与目标节点bounds。 - 全屏播放控件缺失:已使用
dump_hierarchy(compressed=False);如仍缺失,请提供目标控件resource-id/text以便核对。 - 调试开关:设置环境变量
POCO_THIRDPARTY_DEBUG=1可在日志输出被加入的依赖路径。
poco_u2 is a UIAutomator2‑only Poco driver tailored for AirtestIDE’s embedded Python:
- Switches fully to UIAutomator2 while preserving Poco’s API, action behavior and data shape.
- Preserves full XML attributes (incl.
package) to fix legacy data loss. - Dumps uncompressed hierarchy to keep overlay/controls visible during fullscreen playback.
- Normalizes coordinates using
window_sizeto match screenshots/IDE overlays; fixes lower‑screen drift. - Bundles a self‑bootstrap for third‑party deps (under
thirdparty) — no need to modify IDE’s Python. - Provides compatibility shims for Python 3.6 and old PIL.
Usage is simple: replace AirtestIDE’s
pocofolder with this version. The project name ispoco_u2, but the folder must be namedpocounder IDE.
- Close AirtestIDE.
- Copy this repo’s
tmp\\pocoand replace at:C:\\Download\\AirtestIDE-win-1.2.17\\AirtestIDE\\poco
- One‑click dependency install (online):
- Run:
C:\\Download\\git\\uni\\tmp\\poco\\setup_airtest_uia2_deps.bat - This populates
poco\\thirdparty\\site-packageswith all required packages even from empty.
- Run:
- Device init (recommended once from any Python):
python -m uiautomator2 init
- Use in scripts (unchanged):
from poco.drivers.android.uiautomation import AndroidUiautomationPoco poco = AndroidUiautomationPoco(device_id="192.168.100.112:5555") h = poco.agent.hierarchy.dump()
- ImportError deps: run the one‑click script, or check
poco\\thirdparty\\site-packagesforuiautomator2/adbutils/apkutils2/whichcraft/xmltodict/cigam/progress/.... progress is not a package: the IDE’s flatprogress.pycan shadow the real package; the driver mitigates this and shimsprogress.bar.Bar. Ensure the package is present by running the script.…uiautomator2-*.whl/.../assets/app-uiautomator.apk not found: driver forces file‑based import ofuiautomator2and strips.whl. Remove stray wheels if manually added.- Coordinate drift: driver uses
window_size; if a mismatch persists, sharewindow_size,device.info, and XMLbounds. - Playback controls missing: driver uses
dump_hierarchy(compressed=False); if still missing, share theresource-id/textso we can inspect. - Debugging: set
POCO_THIRDPARTY_DEBUG=1to log vendor paths added.
- Do NOT vendor Pillow; the driver works with IDE’s built‑in PIL (shims provided for missing symbols).
- This driver does not change Poco’s external API — only the backend and robustness.
- For detailed adoption notes and fixes, see
docs/POCO_UIA2_ADOPTION_NOTES.md.