# Testing automatizzato di app iOS Combini il sistema di memoria di Synapse con la Computer Control API per costruire test di app iOS guidati da LLM. L'LLM ricorda gli scenari di test, impara dai fallimenti passati e si adatta ai cambiamenti della UI. ## Architettura ``` ┌──────────────┐ commands ┌──────────────┐ screenshots ┌──────────────┐ │ LLM Agent │ ─────────────▶│ Synapse │ ────────────────▶ │ iOS Sim │ │ (Claude) │ │ Computer │ ◀──────────────── │ (via agent) │ └──────────────┘ │ Control │ results └──────────────┘ │ └──────────────┘ │ store/recall ▼ ┌──────────────┐ │ Memories │ (test scenarios, past failures, UI patterns) └──────────────┘ ``` ## Prerequisiti - Account Synapse + Mind Key - Server MCP di Synapse configurato in Claude Desktop - iOS Simulator con `screen-remote-agent` installato - Computer registrato in Synapse (veda [Computer Control API](/docs/api/computers)) ## Passo 1: Registri il computer Simulator Sul Mac che esegue l'iOS Simulator: ```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) ``` ## Passo 2: Memorizzi gli scenari di test in memoria Memorizzi gli scenari di test riutilizzabili come memorie: ```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") ``` ## Passo 3: Esecuzione del test guidata da LLM In Claude Desktop (con Synapse MCP configurato): ``` 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. Chiamerà `memory_search` per trovare la memoria `test_scenario_login_flow` 2. Chiamerà `computer_screenshot` per vedere lo stato corrente 3. Eseguirà ogni passo tramite `computer_command_queue` (click, type) 4. Verificherà i risultati tramite schermate 5. Memorizzerà eventuali fallimenti come memorie `mistake` ## Passo 4: Test self-healing Quando un test fallisce, memorizzi il fallimento e il recupero: ```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.") ``` La prossima volta che l'LLM esegue il test, richiama il fallimento e applica il recupero automaticamente. ## Passo 5: Tracciamento dei risultati dei test Tracci le esecuzioni dei test come attività: ```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" }) ``` ## Comandi comuni | Azione | Comando | |--------|---------| | Avvia Simulator | `xcrun simctl launch booted com.example.app` | | Schermata | `computer_screenshot` (tramite Synapse MCP) | | Tap a (x,y) | `computer_command_queue {type:"click", payload:{x,y}}` | | Digita testo | `computer_command_queue {type:"type", payload:{text:"..."}}` | | Premi Home | `computer_command_queue {type:"key", payload:{keys:["Cmd","Shift","H"]}}` | ## Best practice > [!TIP] > - **Memorizzi le coordinate UI come memorie** — la UI cambia, ma l'LLM può reimparare > - **Usi le etichette di accessibilità** — più stabili delle coordinate > - **Memorizzi i dati di test separatamente** — usi variabili per username, password > - **Esegua i test in stato pulito** — reset del Simulator tra le esecuzioni > - **Logghi le schermate per i fallimenti** — utili per il debug ## Prossimi passi - [Test self-healing](/docs/guides/self-healing-tests) - [Computer Control API](/docs/api/computers) - [Best practice per la memoria](/docs/guides/memory-best-practices)