# iOS アプリの自動テスト Synapse のメモリシステムと Computer Control API を組み合わせて、LLM 駆動の iOS アプリテストを構築します。LLM はテストシナリオを記憶し、過去の失敗から学習し、UI 変更に適応します。 ## アーキテクチャ ``` ┌──────────────┐ commands ┌──────────────┐ screenshots ┌──────────────┐ │ LLM Agent │ ─────────────▶│ Synapse │ ────────────────▶ │ iOS Sim │ │ (Claude) │ │ Computer │ ◀──────────────── │ (via agent) │ └──────────────┘ │ Control │ results └──────────────┘ │ └──────────────┘ │ store/recall ▼ ┌──────────────┐ │ Memories │ (test scenarios, past failures, UI patterns) └──────────────┘ ``` ## 前提条件 - Synapse アカウント + Mind Key - Claude Desktop で構成された Synapse MCP サーバー - `screen-remote-agent` をインストールした iOS Simulator - Synapse に登録されたコンピュータ([Computer Control API](/docs/api/computers) を参照) ## ステップ 1:Simulator コンピュータの登録 iOS Simulator を実行する Mac 上で: ```bash # Get install code from Synapse curl -X POST https://synapse.schaefer.zone/computers/install-code \ -H "Authorization: Bearer YOUR_MIND_KEY" \ -d '{"computer_name":"ios-sim"}' # → { "install_code": "ic_..." } # Run screen-remote-agent on the Mac # (uses the install code to register) ``` ## ステップ 2:テストシナリオをメモリに保存 再利用可能なテストシナリオをメモリとして保存します。 ```python import requests def store_test_scenario(name, steps, app): requests.post(f"{URL}/memory", headers={"Authorization": f"Bearer {MIND_KEY}"}, json={ "category": "skill", "key": f"test_scenario_{name}", "content": f"App: {app}\nSteps:\n" + "\n".join(steps), "tags": ["test", "ios", app], "priority": "high" }) store_test_scenario("login_flow", [ "Launch app", "Tap email field", "Type test@example.com", "Tap password field", "Type password123", "Tap Login button", "Verify home screen appears" ], "MyApp") ``` ## ステップ 3:LLM 駆動のテスト実行 Claude Desktop で(Synapse MCP を構成済み): ``` Run the login_flow test scenario on the iOS Simulator. Take a screenshot after each step and verify the expected UI. If any step fails, store the failure as a memory so we can avoid it next time. ``` Claude は以下を行います。 1. `memory_search` を呼び出して `test_scenario_login_flow` メモリを見つける 2. `computer_screenshot` を呼び出して現在の状態を確認 3. 各ステップを `computer_command_queue`(click、type)経由で実行 4. スクリーンショットで結果を検証 5. 失敗があれば `mistake` メモリとして保存 ## ステップ 4:自己修復テスト テスト失敗時に、失敗と復旧を保存します。 ```python def store_test_failure(scenario, step, error, recovery): requests.post(f"{URL}/memory", headers={"Authorization": f"Bearer {MIND_KEY}"}, json={ "category": "mistake", "key": f"failure_{scenario}_{step}", "content": f"Scenario: {scenario}\nStep: {step}\nError: {error}\nRecovery: {recovery}", "tags": ["test", "failure", "ios", scenario], "priority": "high" }) # Example store_test_failure("login_flow", "tap_login", "Login button not found at expected coordinates", "Button moved due to new logo. Search by accessibility label instead.") ``` 次回 LLM がテストを実行する際、失敗を再取得し、復旧を自動的に適用します。 ## ステップ 5:テスト結果の追跡 テスト実行をタスクとして追跡します。 ```python def track_test_run(scenario, status, duration): requests.post(f"{URL}/mind/task", headers={"Authorization": f"Bearer {MIND_KEY}", "Content-Type": "application/json"}, json={ "title": f"Test: {scenario}", "description": f"Status: {status}, Duration: {duration}s", "priority": "normal" }) ``` ## よくあるコマンド | アクション | コマンド | |--------|---------| | Simulator 起動 | `xcrun simctl launch booted com.example.app` | | スクリーンショット | `computer_screenshot`(Synapse MCP 経由) | | (x,y) をタップ | `computer_command_queue {type:"click", payload:{x,y}}` | | テキスト入力 | `computer_command_queue {type:"type", payload:{text:"..."}}` | | Home を押す | `computer_command_queue {type:"key", payload:{keys:["Cmd","Shift","H"]}}` | ## ベストプラクティス > [!TIP] > - **UI 座標をメモリとして保存** — UI は変わるが、LLM は再学習可能 > - **アクセシビリティラベルを使用** — 座標より安定 > - **テストデータは別々に保存** — ユーザー名、パスワードには変数を使用 > - **クリーンな状態でテスト実行** — 実行間で Simulator をリセット > - **失敗時のスクリーンショットを記録** — デバッグに有用 ## 次のステップ - [Self-Healing Tests](/docs/guides/self-healing-tests) - [Computer Control API](/docs/api/computers) - [Memory Best Practices](/docs/guides/memory-best-practices)