Kiểm thử ứng dụng iOS tự động
Sử dụng Synapse + Computer Control API để tự động hóa kiểm thử ứng dụng iOS qua Simulator.
Kiểm thử ứng dụng iOS tự động
Kết hợp hệ thống bộ nhớ của Synapse với Computer Control API để xây dựng kiểm thử ứng dụng iOS điều khiển bởi LLM. LLM ghi nhớ kịch bản kiểm thử, học từ lỗi quá khứ và thích ứng với thay đổi UI.
Kiến trúc
┌──────────────┐ commands ┌──────────────┐ screenshots ┌──────────────┐
│ LLM Agent │ ─────────────▶│ Synapse │ ────────────────▶ │ iOS Sim │
│ (Claude) │ │ Computer │ ◀──────────────── │ (via agent) │
└──────────────┘ │ Control │ results └──────────────┘
│ └──────────────┘
│ store/recall
▼
┌──────────────┐
│ Memories │ (test scenarios, past failures, UI patterns)
└──────────────┘Điều kiện tiên quyết
- Tài khoản Synapse + Mind Key
- Synapse MCP server được cấu hình trong Claude Desktop
- iOS Simulator với
screen-remote-agentđã cài đặt - Máy tính đã đăng ký trong Synapse (xem Computer Control API)
Bước 1: Đăng ký máy tính Simulator
Trên Mac chạy 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)Bước 2: Lưu kịch bản kiểm thử trong bộ nhớ
Lưu kịch bản kiểm thử tái sử dụng dưới dạng bộ nhớ:
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")Bước 3: Thực thi kiểm thử điều khiển bởi LLM
Trong Claude Desktop (với Synapse MCP đã cấu hình):
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 sẽ:
- Gọi
memory_searchđể tìm bộ nhớtest_scenario_login_flow - Gọi
computer_screenshotđể xem trạng thái hiện tại - Thực thi mỗi bước qua
computer_command_queue(click, type) - Xác minh kết quả qua ảnh chụp màn hình
- Lưu bất kỳ lỗi nào dưới dạng bộ nhớ
mistake
Bước 4: Kiểm thử tự sửa chữa
Khi kiểm thử thất bại, lưu lỗi và cách khôi phục:
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.")Lần tới LLM chạy kiểm thử, nó thu hồi lỗi và áp dụng khôi phục tự động.
Bước 5: Theo dõi kết quả kiểm thử
Theo dõi lần chạy kiểm thử dưới dạng tác vụ:
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"
})Lệnh phổ biến
| Hành động | Lệnh |
|---|---|
| Khởi chạy Simulator | xcrun simctl launch booted com.example.app |
| Ảnh chụp màn hình | computer_screenshot (qua Synapse MCP) |
| Nhấp tại (x,y) | computer_command_queue {type:"click", payload:{x,y}} |
| Nhập văn bản | computer_command_queue {type:"type", payload:{text:"..."}} |
| Nhấn Home | computer_command_queue {type:"key", payload:{keys:["Cmd","Shift","H"]}} |