# اختبار تطبيقات iOS المؤتمت اجمع نظام ذاكرة Synapse مع Computer Control API لبناء اختبارات تطبيقات iOS مدفوعة بـ LLM. يتذكر الـ LLM سيناريوهات الاختبار، يتعلّم من الإخفاقات السابقة، ويتكيّف مع تغييرات الواجهة. ## البنية ``` ┌──────────────┐ 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 مُعدّ في Claude Desktop - iOS Simulator مع `screen-remote-agent` مثبت - جهاز مسجّل في Synapse (راجع [Computer Control API](/docs/api/computers)) ## الخطوة 1: سجّل جهاز Simulator على الـ Mac الذي يشغّل iOS Simulator: ```bash # احصل على رمز التثبيت من 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_..." } # شغّل screen-remote-agent على الـ Mac # (يستخدم رمز التثبيت للتسجيل) ``` ## الخطوة 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" }) # مثال 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] > - **خزّن إحداثيات الواجهة كذكريات** — تتغير الواجهة، لكن الـ LLM يستطيع إعادة التعلم > - **استخدم تسميات الوصول (accessibility labels)** — أكثر ثباتًا من الإحداثيات > - **خزّن بيانات الاختبار منفصلة** — استخدم متغيرات لأسماء المستخدمين، كلمات المرور > - **شغّل الاختبارات في حالة نظيفة** — أعد تعيين Simulator بين التشغيلات > - **سجّل لقطات شاشة للإخفاقات** — مفيد للتصحيح ## الخطوات التالية - [اختبارات ذاتية الإصلاح](/docs/guides/self-healing-tests) - [Computer Control API](/docs/api/computers) - [أفضل ممارسات الذاكرة](/docs/guides/memory-best-practices)