android-emulator-qa

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Android Emulator QA

Android模拟器QA

Validate Android app flows in an emulator using adb for launch, input, UI-tree inspection, screenshots, and logs.
使用adb在模拟器中验证Android应用流程,包括启动、输入、UI树检查、截图和日志采集。

When to use

适用场景

  • QA a feature flow in an Android emulator.
  • Reproduce UI bugs by driving navigation with adb input events.
  • Capture screenshots and logcat output while testing.
  • 在Android模拟器中对功能流程进行QA测试。
  • 通过adb输入事件驱动导航来复现UI漏洞。
  • 测试过程中捕获截图和logcat输出。

Quick start

快速开始

  1. List emulators and pick a serial:
    • adb devices
  2. Build and install the target variant:
    • ./gradlew :<module>:install<BuildVariant> --console=plain --quiet
    • If unsure about task names:
      ./gradlew tasks --all | rg install
  3. Launch the app:
    • Resolve activity:
      adb -s <serial> shell cmd package resolve-activity --brief <package>
    • Start app:
      adb -s <serial> shell am start -n <package>/<activity>
  4. Capture a screenshot for visual verification:
    • adb -s <serial> exec-out screencap -p > /tmp/emu.png
  1. 列出模拟器并选择序列号:
    • adb devices
  2. 构建并安装目标变体:
    • ./gradlew :<module>:install<BuildVariant> --console=plain --quiet
    • 若不确定任务名称:
      ./gradlew tasks --all | rg install
  3. 启动应用:
    • 解析Activity:
      adb -s <serial> shell cmd package resolve-activity --brief <package>
    • 启动应用:
      adb -s <serial> shell am start -n <package>/<activity>
  4. 捕获截图用于视觉验证:
    • adb -s <serial> exec-out screencap -p > /tmp/emu.png

adb control commands

adb控制命令

  • Tap (use UI tree-derived coordinates):
    • adb -s <serial> shell input tap <x> <y>
  • Swipe:
    • adb -s <serial> shell input swipe <x1> <y1> <x2> <y2>
    • Avoid edges (start ~150-200 px from left/right) to reduce accidental back gestures.
  • Text:
    • adb -s <serial> shell input text "hello"
  • Back:
    • adb -s <serial> shell input keyevent 4
  • UI tree dump:
    • adb -s <serial> exec-out uiautomator dump /dev/tty
  • 点击(使用UI树导出的坐标):
    • adb -s <serial> shell input tap <x> <y>
  • 滑动:
    • adb -s <serial> shell input swipe <x1> <y1> <x2> <y2>
    • 避免边缘(距离左右边缘约150-200像素),减少误触返回手势。
  • 输入文本:
    • adb -s <serial> shell input text "hello"
  • 返回:
    • adb -s <serial> shell input keyevent 4
  • 导出UI树:
    • adb -s <serial> exec-out uiautomator dump /dev/tty

Coordinate picking (UI tree only)

坐标选取(仅通过UI树)

Always compute tap coordinates from the UI tree, not screenshots.
  1. Dump the UI tree to a step-specific file:
    • adb -s <serial> exec-out uiautomator dump /dev/tty > /tmp/ui-settings.xml
  2. Find the target node and derive center coordinates (
    x y
    ) from bounds:
    • Bounds format:
      bounds="[x1,y1][x2,y2]"
    • Helper script:
    • python3 <path-to-skill>/scripts/ui_pick.py /tmp/ui-settings.xml "Settings"
  3. If the node is missing and there are
    scrollable
    elements:
    • swipe, re-dump, and re-search at least once before concluding the target is missing.
  4. Tap the center:
    • adb -s <serial> shell input tap <x> <y>
始终从UI树计算点击坐标,而非截图。
  1. 将UI树导出到步骤专属文件:
    • adb -s <serial> exec-out uiautomator dump /dev/tty > /tmp/ui-settings.xml
  2. 找到目标节点并从边界值推导中心坐标(
    x y
    ):
    • 边界格式:
      bounds="[x1,y1][x2,y2]"
    • 辅助脚本:
    • python3 <path-to-skill>/scripts/ui_pick.py /tmp/ui-settings.xml "Settings"
  3. 若目标节点缺失且存在
    scrollable
    元素:
    • 滑动、重新导出UI树并至少重新搜索一次,再判断目标是否缺失。
  4. 点击中心位置:
    • adb -s <serial> shell input tap <x> <y>

UI tree skeleton (helper)

UI树骨架(辅助工具)

Use this helper to create a compact, readable overview before inspecting full XML.
  1. Dump full UI tree:
    • adb -s <serial> exec-out uiautomator dump /dev/tty > /tmp/ui-full.xml
  2. Generate summary:
    • python3 <path-to-skill>/scripts/ui_tree_summarize.py /tmp/ui-full.xml /tmp/ui-summary.txt
  3. Review
    /tmp/ui-summary.txt
    to choose likely targets, then compute exact bounds from full XML.
在检查完整XML之前,使用此工具创建简洁易读的概览。
  1. 导出完整UI树:
    • adb -s <serial> exec-out uiautomator dump /dev/tty > /tmp/ui-full.xml
  2. 生成摘要:
    • python3 <path-to-skill>/scripts/ui_tree_summarize.py /tmp/ui-full.xml /tmp/ui-summary.txt
  3. 查看
    /tmp/ui-summary.txt
    选择潜在目标,再从完整XML中计算精确边界。

Logs (logcat)

日志(logcat)

  1. Clear logs:
    • adb -s <serial> logcat -c
  2. Stream app process logs:
    • Resolve pid:
      adb -s <serial> shell pidof -s <package>
    • Stream:
      adb -s <serial> logcat --pid <pid>
  3. Crash buffer only:
    • adb -s <serial> logcat -b crash
  4. Save logs:
    • adb -s <serial> logcat -d > /tmp/logcat.txt
  1. 清空日志:
    • adb -s <serial> logcat -c
  2. 流式输出应用进程日志:
    • 解析进程ID:
      adb -s <serial> shell pidof -s <package>
    • 流式输出:
      adb -s <serial> logcat --pid <pid>
  3. 仅查看崩溃缓冲区:
    • adb -s <serial> logcat -b crash
  4. 保存日志:
    • adb -s <serial> logcat -d > /tmp/logcat.txt

Package shortcuts

包快捷操作

  • List installed packages:
    • adb -s <serial> shell pm list packages
  • Filter to your namespace:
    • adb -s <serial> shell pm list packages | rg <company_or_app_id>
  • Confirm the activity resolves before launching:
    • adb -s <serial> shell cmd package resolve-activity --brief <package>
  • 列出已安装包:
    • adb -s <serial> shell pm list packages
  • 筛选指定命名空间:
    • adb -s <serial> shell pm list packages | rg <company_or_app_id>
  • 启动前确认Activity可解析:
    • adb -s <serial> shell cmd package resolve-activity --brief <package>