Mobile app E2E testing CLI for AI agents with semantic locators and element references
AI-powered mobile app E2E testing CLI with semantic locators and efficient element reference system.
agent-mobile は AI エージェント向けのモバイルアプリ E2E テストツールです。iOS シミュレータ、Android エミュレータ、実機をサポートし、自然言語に近いセマンティックロケーターと効率的な要素参照システム (@e1, @e2) を提供します。
主な特徴:
@e1 形式の短縮参照--json オプションをサポート# 1. UI スナップショットを取得(要素参照を生成)
agent-mobile snapshot
# 2. セマンティックロケーターで要素を検索してアクション実行
agent-mobile find text "Login" tap
agent-mobile find label "Email" fill "test@example.com"
# 3. 要素参照を使用(トークン効率的)
agent-mobile tap @e1
agent-mobile fill @e2 "password"
# 4. スクリーンショットで検証
agent-mobile screenshot
@e1, @e2)最も重要な概念: トークン使用量を劇的に削減する短縮 ID システム。
# snapshot を取得すると @e1, @e2, ... が生成される
agent-mobile snapshot
# 出力:
# @e1 Button "Login" (enabled)
# @e2 TextField "Email" (enabled)
# @e3 SecureTextField "Password" (enabled)
# 参照を使用(繰り返しスナップショット不要)
agent-mobile tap @e1
agent-mobile fill @e2 "user@example.com"
agent-mobile fill @e3 "password123"
重要な制約:
snapshot に紐づく(画面変更後は無効)詳細: references/element-references.md
UI 要素を人間が理解しやすい方法で検索:
# タイプで検索
agent-mobile find type Button
# テキスト内容で検索(label または value)
agent-mobile find text "Login"
# ラベルで検索
agent-mobile find label "Email"
# プレースホルダーで検索
agent-mobile find placeholder "Enter your email"
# 状態で検索
agent-mobile find enabled
agent-mobile find disabled
位置指定:
--first (デフォルト): 最初の要素--last: 最後の要素--nth N: N 番目の要素(0-indexed)--all: すべての要素(アクションなし時のみ)マッチングモード:
--exact: 完全一致詳細: references/semantic-locators.md
複数デバイスで並行作業する際の状態管理:
# セッション作成
agent-mobile session create ios-dev --udid ABC-123 -p ios
agent-mobile session create android-dev --udid emulator-5554 -p android
# セッションを使用
agent-mobile --session ios-dev snapshot
agent-mobile --session android-dev snapshot
# または環境変数で設定
export AGENT_MOBILE_SESSION=ios-dev
agent-mobile snapshot
詳細: references/session-management.md
| Command | Description | Example |
|---|---|---|
tap <target> |
要素または座標をタップ | tap @e1, tap 100,200, tap home |
long-press <target> |
長押し(デフォルト1秒) | long-press @e1, long-press @e1 --duration 2.0 |
fill <target> <text> |
テキストフィールドをクリア + 入力 | fill @e2 "test@example.com" |
type <text> |
フォーカス中のフィールドに追記 | type "additional text" |
swipe <direction> |
スワイプジェスチャー | swipe up, swipe down, swipe left, swipe right |
scroll <direction> |
要素内または画面をスクロール | scroll down, scroll up --element @e1 |
Tap Targets:
@e1, @e2100,200 (x,y)home, lock, siri, volumeUp, volumeDown, applePay| Command | Description | Example |
|---|---|---|
snapshot |
UI 階層を要素参照付きで取得 | snapshot, snapshot -i (interactive only), snapshot -c (compact) |
find <locator> |
セマンティックロケーターで検索 | find type Button, find text "Login" |
find <locator> <action> |
検索 + アクション実行 | find text "Login" tap, find label "Email" fill "user@example.com" |
get <target> <property> |
要素プロパティを取得 | get @e1 text, get @e1 label, get @e1 value |
is <target> <condition> |
状態チェック(exit code) | is @e1 enabled, is @e2 disabled |
wait <target> |
要素出現を待機 | wait @e1, wait @e1 --timeout 10 |
Snapshot Options:
-i, --interactive: インタラクティブ要素のみ表示-c, --compact: 空要素を削除-d, --depth N: 階層深さを N に制限-o, --output <file>: ファイルに保存-f, --format json: JSON 形式で出力--no-scroll: スクロール無効化(デフォルトは有効)Find Locators:
type <element-type>: 要素タイプで検索 (Button, TextField, etc.)text <text>: テキスト内容で検索 (label または value)label <label>: ラベルで検索placeholder <placeholder>: プレースホルダーで検索enabled: 有効な要素disabled: 無効な要素Find Actions:
tap: タップlong-press: 長押しfill <text>: クリア + 入力clear: クリア| Command | Description | Example |
|---|---|---|
screenshot |
スクリーンショットを PNG で保存 | screenshot, screenshot -o result.png |
record start |
画面録画を開始 | record start, record start -o video.mp4 |
record stop |
画面録画を停止 | record stop |
console |
デバイスログをストリーミング | console, console --level error |
| Command | Description | Example |
|---|---|---|
app launch <bundle-id> |
アプリを起動 | app launch com.example.app |
app terminate <bundle-id> |
アプリを終了 | app terminate com.example.app |
app install <path> |
アプリをインストール | app install app.ipa, app install app.apk |
app uninstall <bundle-id> |
アプリをアンインストール | app uninstall com.example.app |
app list |
インストール済みアプリ一覧 | app list, app list -f json |
app grant <perm> -b <bundle> |
権限を付与 | app grant camera -b com.example.app |
app revoke <perm> -b <bundle> |
権限を取り消し | app revoke camera -b com.example.app |
app reset <perm> -b <bundle> |
権限をリセット | app reset camera -b com.example.app |
iOS Permissions:
camera, location, contacts, photos, microphone, calendar, reminders, siri, health, homekit, etc.
Android Permissions:
camera, location, contacts, calendar, storage, microphone, phone, sms, etc.
| Command | Description | Example |
|---|---|---|
device list |
デバイス/シミュレータ一覧 | device list, device list -p ios |
device boot <name> |
シミュレータ/エミュレータを起動 | device boot "iPhone 15", device boot Pixel_7 |
device shutdown <udid> |
デバイスをシャットダウン | device shutdown ABC-123 |
device pbcopy <text> |
クリップボードにコピー(iOS のみ) | device pbcopy "Hello" |
device pbpaste |
クリップボードから取得(iOS のみ) | device pbpaste |
| Command | Description | Example |
|---|---|---|
session create <name> |
セッションを作成 | session create test --udid ABC-123 -p ios |
session list |
セッション一覧 | session list, session list -f json |
session show |
現在のセッション情報 | session show (requires --session) |
session rm [name] |
セッションを削除 | session rm test |
すべてのコマンドで使用可能:
| Option | Description | Example |
|---|---|---|
--session <name> |
セッション名(AGENT_MOBILE_SESSION 環境変数も可) | --session ios-dev |
--udid <udid> |
デバイス UDID(指定しない場合は自動検出) | --udid ABC-123 |
--platform <platform> |
プラットフォーム(ios または android、通常は自動検出) | --platform ios |
-f, --format json |
JSON 形式で出力 | -f json |
# 1. アプリを起動
agent-mobile app launch com.example.app
# 2. UI をスナップショット
agent-mobile snapshot -i # インタラクティブ要素のみ
# 3. セマンティックロケーターでログイン
agent-mobile find label "Email" fill "user@example.com"
agent-mobile find label "Password" fill "password123"
agent-mobile find text "Login" tap
# 4. 成功を確認
agent-mobile wait @e1 --timeout 5
agent-mobile screenshot -o login_success.png
# 1. スナップショット取得
agent-mobile snapshot > snapshot.txt
# 2. 参照を使用して高速入力
agent-mobile fill @e1 "John"
agent-mobile fill @e2 "Doe"
agent-mobile fill @e3 "john@example.com"
agent-mobile tap @e4 # Submit button
# セッション作成
agent-mobile session create ios16 --udid ABC-123 -p ios
agent-mobile session create android13 --udid emulator-5554 -p android
# 並行実行
agent-mobile --session ios16 app launch com.example.app &
agent-mobile --session android13 app launch com.example.app &
# 同じテストを両方で実行
for session in ios16 android13; do
agent-mobile --session $session find text "Login" tap
agent-mobile --session $session screenshot -o ${session}_result.png
done
# ベースラインスナップショット
agent-mobile snapshot -o baseline.json -f json
# ... コード変更後 ...
# 新しいスナップショット
agent-mobile snapshot -o current.json -f json
# 差分比較(外部ツール使用)
diff baseline.json current.json
以下のコマンドは現在実装中です(todo.md を参照):
is visible <target> - 可視性判定is checked <target> - チェック状態判定get count <locator> - マッチング要素数get box <target> - バウンディングボックス取得wait --text <text> - テキスト出現待機wait --timeout <ms> - タイムアウト設定check <target> - チェックボックス/スイッチをオンuncheck <target> - チェックボックス/スイッチをオフget attr <target> <attribute> - 任意属性取得select <target> <value> - Picker/ドロップダウン選択snapshot -s <selector> - スコープ限定スナップショットこれらのコマンドの詳細な仕様は /Users/r0227n/Dev/agent-mobile/todo.md を参照してください。
Always use element references after snapshot:
❌ Bad (繰り返しスナップショット):
agent-mobile snapshot
agent-mobile find text "Email" fill "user@example.com"
agent-mobile snapshot # 不要!
agent-mobile find text "Password" fill "password"
✅ Good (参照を再利用):
agent-mobile snapshot
# @e1: Email TextField
# @e2: Password SecureTextField
agent-mobile fill @e1 "user@example.com"
agent-mobile fill @e2 "password"
スナップショットのフィルタリング:
# 大きなアプリでは -i (interactive only) を使用
agent-mobile snapshot -i
# さらに -c (compact) と -d (depth) で絞り込み
agent-mobile snapshot -i -c -d 3
明示的な待機を使用:
# アニメーション後に待機
agent-mobile tap @e1
sleep 1 # または wait コマンド
agent-mobile screenshot
エラーハンドリング:
# is コマンドの exit code を使用
if agent-mobile is @e1 enabled; then
agent-mobile tap @e1
else
echo "Button is disabled"
fi
スナップショットを保存して分析:
agent-mobile snapshot -o debug.json -f json
agent-mobile snapshot -o debug.txt
スクリーンショットで証跡を残す:
agent-mobile screenshot -o before.png
agent-mobile tap @e1
agent-mobile screenshot -o after.png
コンソールログを監視:
agent-mobile console --level error &
# テスト実行...
JSON 出力を活用:
# プログラムで解析可能な出力
devices=$(agent-mobile device list -f json)
echo "$devices" | jq -r '.[0].udid'
セッションで状態を永続化:
# セッションは最後のスナップショットを保存
export AGENT_MOBILE_SESSION=test
agent-mobile snapshot # 保存される
agent-mobile tap @e1 # セッションから参照を解決
エラーメッセージを読む:
agent-mobile find text "NonExistent" tap
# エラー: "No elements found matching text containing "NonExistent"
# Hint: Run 'agent-mobile snapshot' to see the current UI state."
詳細: references/platform-differences.md
"No Image available to encode"
agent-mobile app launch <bundle-id> でアプリを起動"No elements found matching..."
agent-mobile snapshot で UI 状態を確認"Element ref @e1 not found"
agent-mobile snapshot で再取得"Session 'xxx' not found"
agent-mobile session create xxx --udid ...詳細: references/troubleshooting.md
#!/bin/bash
set -e
# Setup
BUNDLE_ID="com.example.app"
agent-mobile app launch $BUNDLE_ID
# Wait for app to load
sleep 2
# Capture UI
agent-mobile snapshot -i -o login_screen.txt
# Login
agent-mobile find label "Email" fill "test@example.com"
agent-mobile find label "Password" fill "password123"
agent-mobile find text "Login" tap
# Wait for next screen
sleep 2
agent-mobile wait @e1 --timeout 10
# Verify
agent-mobile screenshot -o logged_in.png
echo "Login successful"
#!/bin/bash
# Take snapshot
agent-mobile snapshot > /tmp/form.txt
# Extract refs
EMAIL_REF=$(grep "Email" /tmp/form.txt | grep -o "@e[0-9]*" | head -1)
PASSWORD_REF=$(grep "Password" /tmp/form.txt | grep -o "@e[0-9]*" | head -1)
SUBMIT_REF=$(grep "Submit" /tmp/form.txt | grep -o "@e[0-9]*" | head -1)
# Fill form
agent-mobile fill $EMAIL_REF "user@example.com"
agent-mobile fill $PASSWORD_REF "securepass123"
# Check if submit button is enabled
if agent-mobile is $SUBMIT_REF enabled; then
agent-mobile tap $SUBMIT_REF
echo "Form submitted"
else
echo "Submit button is disabled"
exit 1
fi
/Users/r0227n/Dev/agent-mobile/Users/r0227n/Dev/agent-mobile/docs/ARCHITECTURE.md/Users/r0227n/Dev/agent-mobile/CLAUDE.md/Users/r0227n/Dev/agent-mobile/todo.md/Users/r0227n/Dev/agent-mobile/docs/KNOWN_ISSUES.md (if exists)Version: 1.0.0 Last Updated: 2026-01-23 Maintained by: Claude Code (Anthropic)