AgentSkillsCN

Android Automation Skill

当用户希望实现以下功能时,可使用此技能: - 控制 Android 设备、模拟器或仿真器 - 在 Android 平台上开展移动测试、自动化质量保证,或执行 UI 测试 - 在 Android 屏幕上查找、点击、滑动或与各类元素交互 - 启动、安装、卸载或管理 Android 应用 - 截取屏幕截图、捕获日志,或对 Android 问题进行调试 - 编写或运行类似 Appium 的自动化脚本,而无需依赖 Appium - 获取元素定位器、无障碍树,或 UI 层级结构 - 模拟按下返回键、主屏幕键或音量调节键等硬件按钮 - 在 Android 设备上输入文本或录入凭据 此技能提供 20 多个基于 ADB 的 Python 自动化脚本。

SKILL.md
--- frontmatter
name: Android Automation Skill
description: |
  Use this skill when the user wants to:
  - Control Android devices, emulators, or simulators
  - Perform mobile testing, QA automation, or UI testing on Android
  - Find, tap, scroll, or interact with elements on Android screens
  - Launch, install, uninstall, or manage Android apps
  - Take screenshots, capture logs, or debug Android issues
  - Write or run Appium-like automation without Appium
  - Get element locators, accessibility tree, or UI hierarchy
  - Press hardware buttons like back, home, or volume
  - Type text or enter credentials on Android
  
  This skill provides 20+ ADB-based Python automation scripts.
triggers:
  - android
  - mobile testing
  - adb
  - emulator
  - appium alternative
  - ui automation
  - tap element
  - scroll screen
  - find locator
  - app testing
  - android device
  - mobile app
  - screen mapper
  - accessibility audit
invocation:
  - /android
  - /mobile
  - /adb

Android Automation Skill

Production-ready automation for Android app testing. 20+ scripts optimized for AI agents and human developers.

Prerequisites

  • Android SDK Platform Tools (ADB) in PATH
    bash
    # macOS
    brew install android-platform-tools
    
    # Verify
    adb version
    
  • Python 3.8+
  • Connected Android device or running emulator

Quick Start

bash
# Check device connection
./scripts/device/list_devices.sh

# Take screenshot
python scripts/interaction/screenshot.py --output screen.png

# Map current screen
python scripts/interaction/screen_mapper.py

# Tap element by text
python scripts/interaction/navigator.py --find-text "Settings" --tap

Scripts Reference

Device Management

ScriptDescriptionUsage
list_devices.shList connected devices/emulators./scripts/device/list_devices.sh
emulator_boot.pyBoot emulator by AVD namepython scripts/device/emulator_boot.py --avd Pixel_7_API_34
emulator_shutdown.pyShutdown emulatorpython scripts/device/emulator_shutdown.py [--udid <id>]
device_info.pyGet device propertiespython scripts/device/device_info.py

App Management

ScriptDescriptionUsage
app_install.pyInstall APKpython scripts/app/app_install.py --apk app.apk
app_uninstall.pyUninstall apppython scripts/app/app_uninstall.py --package com.example.app
app_launch.pyLaunch apppython scripts/app/app_launch.py --package com.example.app
app_stop.pyForce stop apppython scripts/app/app_stop.py --package com.example.app
app_list.pyList installed appspython scripts/app/app_list.py [--filter user]

Screen Interaction

ScriptDescriptionUsage
screenshot.pyCapture screenshotpython scripts/interaction/screenshot.py --output shot.png
annotated_screenshot.pyScreenshot with labeled elementspython scripts/interaction/annotated_screenshot.py --output annotated.png
screen_mapper.pyAnalyze UI hierarchypython scripts/interaction/screen_mapper.py [--format tree]
navigator.pyFind/interact with elementspython scripts/interaction/navigator.py --find-text "Login" --tap
gesture.pySwipe, scroll, pinchpython scripts/interaction/gesture.py --swipe up
gesture_record.pyRecord/replay gesturespython scripts/interaction/gesture_record.py --record gestures.json

Advanced Navigator Features

The navigator.py script supports advanced element finding:

bash
# Wait for element (useful after navigation/loading)
python scripts/interaction/navigator.py --find-text "Welcome" --wait-timeout 10 --tap

# XPath queries
python scripts/interaction/navigator.py --xpath "//android.widget.Button[@text='Submit']" --tap

# Self-healing with fallbacks (tries primary, then fallbacks)
python scripts/interaction/navigator.py --find-text "Login" --fallback-id "submit_btn" --tap

# Retry on failure
python scripts/interaction/navigator.py --find-id "dynamic_element" --retry-count 3 --tap

Input & Navigation

ScriptDescriptionUsage
keyboard.pyType textpython scripts/input/keyboard.py --text "Hello World"
button.pyHardware buttonspython scripts/input/button.py --key HOME
open_url.pyOpen URL in browserpython scripts/input/open_url.py --url "https://example.com"

Testing & Analysis

ScriptDescriptionUsage
accessibility_audit.pyCheck accessibilitypython scripts/testing/accessibility_audit.py
logcat_monitor.pyMonitor logspython scripts/testing/logcat_monitor.py --package com.example.app
app_state.pyDebug snapshotpython scripts/testing/app_state.py --output state/
visual_diff.pyCompare screenshotspython scripts/testing/visual_diff.py baseline.png current.png

How It Works

The AI agent automatically detects when to use this skill based on your request:

code
You: "Launch the Settings app"
AI: [Uses app_launch.py with com.android.settings]

You: "Tap on Wi-Fi"
AI: [Uses navigator.py to find and tap Wi-Fi element]

You: "Scroll down and take a screenshot"
AI: [Uses gesture.py to scroll, then screenshot.py]

Usage Examples

Example 1: Login Flow Testing

bash
# Launch app
python scripts/app/app_launch.py --package com.example.app

# Map screen to find login fields
python scripts/interaction/screen_mapper.py

# Enter credentials
python scripts/interaction/navigator.py --find-type EditText --index 0 --enter-text "user@test.com"
python scripts/interaction/navigator.py --find-type EditText --index 1 --enter-text "password"

# Tap login button
python scripts/interaction/navigator.py --find-text "Login" --tap

# Check accessibility
python scripts/testing/accessibility_audit.py

Example 2: Visual Regression Testing

bash
# Capture baseline
python scripts/interaction/screenshot.py --output baseline.png

# Make changes and capture current
python scripts/interaction/screenshot.py --output current.png

# Compare
python scripts/testing/visual_diff.py baseline.png current.png

Example 3: CI/CD Pipeline

bash
# Boot emulator
python scripts/device/emulator_boot.py --avd CI_Emulator --headless

# Install APK
python scripts/app/app_install.py --apk app-debug.apk

# Run automated tests
python scripts/app/app_launch.py --package com.example.app
python scripts/interaction/navigator.py --find-text "Start" --tap

# Capture logs
python scripts/testing/logcat_monitor.py --package com.example.app --duration 30

# Cleanup
python scripts/device/emulator_shutdown.py

Troubleshooting

Device Not Found

bash
# Check USB debugging is enabled
adb devices

# Restart ADB server
adb kill-server && adb start-server

Element Not Found

bash
# Dump full UI hierarchy
python scripts/interaction/screen_mapper.py --verbose

# Use different search strategies
python scripts/interaction/navigator.py --find-id "login_button" --tap
python scripts/interaction/navigator.py --find-class "android.widget.Button" --index 0 --tap

Emulator Won't Boot

bash
# List available AVDs
emulator -list-avds

# Check for locks
rm -rf ~/.android/avd/*.avd/*.lock

Output Format

All scripts output JSON by default for easy parsing:

json
{
  "success": true,
  "data": { ... },
  "error": null
}

Use --format text for human-readable output.