Skip to main content

การทดสอบ iOS App อัตโนมัติ

ใช้ Synapse + Computer Control API เพื่อทำให้การทดสอบ iOS app เป็นอัตโนมัติผ่าน Simulator


การทดสอบ iOS App อัตโนมัติ

รวมระบบ memory ของ Synapse กับ Computer Control API เพื่อสร้างการทดสอบ iOS app ที่ขับเคลื่อนด้วย LLM LLM จดจำสถานการณ์ทดสอบ, เรียนรู้จากความล้มเหลวในอดีต และปรับตัวตามการเปลี่ยนแปลง UI

Architecture

┌──────────────┐    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
  • Synapse MCP server กำหนดค่าใน Claude Desktop
  • iOS Simulator พร้อม screen-remote-agent ติดตั้ง
  • Computer ลงทะเบียนใน Synapse (ดู Computer Control API)

ขั้นตอนที่ 1: ลงทะเบียน Simulator Computer

บน Mac ที่รัน iOS Simulator:

# 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: เก็บสถานการณ์ทดสอบใน Memory

เก็บสถานการณ์ทดสอบที่ใช้ซ้ำเป็น memory:

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 เพื่อหา memory test_scenario_login_flow
  2. เรียก computer_screenshot เพื่อดูสถานะปัจจุบัน
  3. ปฏิบัติแต่ละขั้นตอนผ่าน computer_command_queue (click, type)
  4. ตรวจสอบผลลัพธ์ผ่าน screenshot
  5. เก็บความล้มเหลวเป็น memory mistake

ขั้นตอนที่ 4: การทดสอบที่ซ่อมแซมตัวเอง

เมื่อการทดสอบล้มเหลว ให้เก็บความล้มเหลวและวิธีกู้คืน:

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 รันการทดสอบ มันจะ recall ความล้มเหลวและปรับใช้การกู้คืนโดยอัตโนมัติ

ขั้นตอนที่ 5: ติดตามผลการทดสอบ

ติดตามการรันทดสอบเป็น task:

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"
        })

คำสั่งทั่วไป

Action Command
Launch Simulator xcrun simctl launch booted com.example.app
Screenshot computer_screenshot (via Synapse MCP)
Tap at (x,y) computer_command_queue {type:"click", payload:{x,y}}
Type text computer_command_queue {type:"type", payload:{text:"..."}}
Press Home computer_command_queue {type:"key", payload:{keys:["Cmd","Shift","H"]}}

แนวทางปฏิบัติที่ดีที่สุด

ขั้นตอนถัดไป