Manages connections to iOS devices via libimobiledevice and WebDriverAgent. Requires: - libimobiledevice (idevice_id, ideviceinfo) - WebDriverAgent running on the iOS device - ios-deploy (optional, for app installation) Example: >>> conn = XCTestConnect
| 26 | |
| 27 | |
| 28 | class XCTestConnection: |
| 29 | """ |
| 30 | Manages connections to iOS devices via libimobiledevice and WebDriverAgent. |
| 31 | |
| 32 | Requires: |
| 33 | - libimobiledevice (idevice_id, ideviceinfo) |
| 34 | - WebDriverAgent running on the iOS device |
| 35 | - ios-deploy (optional, for app installation) |
| 36 | |
| 37 | Example: |
| 38 | >>> conn = XCTestConnection() |
| 39 | >>> # List connected devices |
| 40 | >>> devices = conn.list_devices() |
| 41 | >>> # Get device info |
| 42 | >>> info = conn.get_device_info() |
| 43 | >>> # Check if WDA is running |
| 44 | >>> is_ready = conn.is_wda_ready() |
| 45 | """ |
| 46 | |
| 47 | def __init__(self, wda_url: str = "http://localhost:8100"): |
| 48 | """ |
| 49 | Initialize iOS connection manager. |
| 50 | |
| 51 | Args: |
| 52 | wda_url: WebDriverAgent URL (default: http://localhost:8100). |
| 53 | For network devices, use http://<device-ip>:8100 |
| 54 | """ |
| 55 | self.wda_url = wda_url.rstrip("/") |
| 56 | |
| 57 | def list_devices(self) -> list[DeviceInfo]: |
| 58 | """ |
| 59 | List all connected iOS devices. |
| 60 | |
| 61 | Returns: |
| 62 | List of DeviceInfo objects. |
| 63 | |
| 64 | Note: |
| 65 | Requires libimobiledevice to be installed. |
| 66 | Install on macOS: brew install libimobiledevice |
| 67 | """ |
| 68 | try: |
| 69 | # Get list of device UDIDs |
| 70 | result = subprocess.run( |
| 71 | ["idevice_id", "-ln"], |
| 72 | capture_output=True, |
| 73 | text=True, |
| 74 | timeout=5, |
| 75 | ) |
| 76 | |
| 77 | devices = [] |
| 78 | for line in result.stdout.strip().split("\n"): |
| 79 | udid = line.strip() |
| 80 | if not udid: |
| 81 | continue |
| 82 | |
| 83 | # Determine connection type (network devices have specific format) |
| 84 | conn_type = ( |
| 85 | ConnectionType.NETWORK |
no outgoing calls
no test coverage detected