mirror of
https://github.com/callstack/agent-device.git
synced 2026-09-14 20:06:34 +08:00
2.9 KiB
2.9 KiB
iOS UI Automation Strategy (v1)
Goal
Provide robust element-level interactions for AI agents on iOS by combining a fast macOS Accessibility (AX) snapshot tool for simulators with an XCTest runner for interactions and fallbacks.
Why this approach
- Apple’s official UI automation layer is XCUITest/XCUI, which runs as an XCTest bundle on device/simulator.
- macOS Accessibility (AX) can read the simulator UI tree quickly without launching XCTest.
- Tools like Appium and Maestro use an on-device XCTest runner and talk to it over HTTP.
- For real devices, code signing is required, so a local build/sign step is unavoidable.
Experience targets
- First run: build and cache the runner via
xcodebuild. - Subsequent runs: reuse cached artifacts per Xcode version + runtime.
- Simulators: allow prebuilt runner when compatible.
- Devices: always require local signing.
Implementation plan (condensed)
- AX snapshot tool
ios-runner/AXSnapshotSwiftPM CLI that reads the simulator accessibility tree via AX.- Used for fast
snapshotoutput and interactive element discovery.
- Runner project
ios-runner/Xcode project with one XCTest target.- Minimal HTTP server inside tests to accept JSON commands (Maestro uses a long-running XCTest that serves HTTP and exposes view hierarchy and actions).
- Protocol is documented in
docs/ios-runner-protocol.md.
- Build + cache
- Build via
xcodebuild build-for-testingand run viatest-without-building. - Cache artifacts under
~/.agent-device/ios-runner/<xcode-version>/<runtime>.
- Build via
- Node adapter
- Add an iOS automation adapter that:
- Runs the AX snapshot tool on simulators for fast tree dumps.
- Ensures runner is built/available.
- Starts runner for the specific device/simulator.
- Sends commands (tap, type, swipe, find, list elements) over HTTP.
- Add an iOS automation adapter that:
- Snapshot backends
- Default snapshot backend is
xctestfor completeness, which works out of the box. - The
--backend axflag is available for macOS Accessibility Tree snapshots when you can tolerate missing details. - If XCTest returns 0 nodes (foreground app changed), call
openfor the target app. Otherwise, agent-device will fall back to AX when available (requires permissions). - Use
trace start [path]/trace stop [path]to capture AX/XCTest logs for debugging snapshot issues. - If runner not available, fall back to
simctl/devicectlcapabilities.
- Default snapshot backend is
Notes
- Prebuilt runners can be distributed for simulators, but are sensitive to Xcode/runtime versions.
- Real devices always need user signing.
- Real device support (including snapshots) is on the roadmap.
References
- Appium’s XCUITest driver uses
build-for-testing+test-without-buildingand supports prebuilt runners for faster startup. - Maestro’s iOS driver runs an XCTest with an HTTP server to serve view hierarchy and actions; it separates UI automation (XCTest) from device management (simctl/devicectl).