Metadata-Version: 2.4
Name: cesium-ios
Version: 0.1.5
Summary: Driverless, WDA-Free iOS Test Automation & Telemetry SDK for Linux and Windows
Author: Cesium Team
Author-email: Cesium Team <info@cesium-ios.org>
License: MIT
Project-URL: Homepage, https://github.com/cesium-ios/cesium-ios
Project-URL: Repository, https://github.com/cesium-ios/cesium-ios
Keywords: ios,automation,coredevice,driverless,testing,wda-free,telemetry
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Topic :: Software Development :: Testing
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Python: >=3.9
Description-Content-Type: text/markdown
Requires-Dist: pymobiledevice3>=4.0.0
Requires-Dist: Pillow>=9.0.0
Dynamic: author
Dynamic: requires-python

# Cesium iOS Python SDK (`cesium-ios`)

> **Driverless, 100% WDA-Free iOS Automation & Telemetry Engine for Linux and Windows.**  
> Completely eliminates WebDriverAgent (WDA), macOS Mac Minis, and Apple Developer certificate signing. Connects directly to physical iPhones and iPads (iOS 17+) over native Apple CoreDevice, `universalhidservice`, and `axAuditDaemon`.

---

## 🌟 Key Architecture & Capabilities

- **Zero-Boilerplate Test Flow Engine (`CesiumRunner`)**: Write only your test logic (`@runner.flow`). The SDK automatically handles device discovery, dynamic port mapping, multi-threaded execution, and reporting.
- **Dynamic Multi-Device Scaling**: Automate 1, 4, 10, or 50 physical iOS devices simultaneously with zero hardcoded UDIDs or ports.
- **Custom CLI Arguments**: Extend test scripts with custom command-line flags (`runner.add_argument(...)`) integrated with standard `argparse`.
- **Sub-10ms Hardware Gestures**: Injects true hardware digitizer touch events (taps, drags, swipes, scrolls) directly through Apple's native HID daemon.
- **Sub-25ms App Lifecycle**: Cold-launches and terminates any iOS application bundle directly over CoreDevice. Deep link payload URLs open in under 25ms.
- **Direct Virtual Keyboard & Clipboard**: Types text into input fields using native virtual keyboard modifier states (with 100% symbol & capital fidelity) and inspects/sets the iOS system pasteboard.
- **Integrated Wi-Fi Control**: Toggles radio interfaces, connects to SSIDs, and forgets networks.
- **Sub-80ms Accessibility Tree**: Queries visible UI elements, taps buttons by text, and checks toggle switch states (`[ON]` / `[OFF]`) without OCR lag.

---

## 📦 Installation & Setup

### In-Tree / Local Development
Add the `cesium_sdk` directory to your Python `sys.path`:
```python
import sys, os
sys.path.insert(0, os.path.abspath("cesium_sdk"))
from cesium_ios import CesiumRunner, IOSDevice
```

### Install as Python Package (Editable Mode)
```bash
cd cesium_sdk
pip install -e .
```

---

## 🚀 Quickstart: Writing a Universal Test Flow

With `CesiumRunner`, you do not write socket code, thread pools, or port mappings. You define your test interaction sequence:

```python
#!/usr/bin/env python3
from cesium_ios import CesiumRunner, IOSDevice

runner = CesiumRunner(title="Settings App Automation")

# Register custom CLI flags for your test script
runner.add_argument("--bundle-id", default="com.apple.Preferences", help="Target App Bundle ID")
runner.add_argument("--scrolls", type=int, default=3, help="Number of feed scrolls")
runner.add_argument("--toggle-wifi", action="store_true", help="Cycle Wi-Fi state during test")

@runner.flow
def test_flow(dev: IOSDevice, args):
    """
    Executes concurrently across all target devices (smartphones and tablets).
    """
    dev.log("Step 1: Return to SpringBoard Home")
    dev.home()
    dev.sleep(1.0)

    if args.toggle_wifi:
        dev.log("Step 2: Toggling Wi-Fi interface...")
        dev.toggle_wifi()
        dev.sleep(2.0)
        dev.toggle_wifi()
        dev.sleep(2.0)

    dev.log(f"Step 3: Launching '{args.bundle_id}'")
    dev.launch_app(args.bundle_id)
    dev.sleep(3.0)

    for i in range(args.scrolls):
        dev.log(f"Step 4: Scrolling content ({i + 1}/{args.scrolls})")
        dev.scroll_down()
        dev.sleep(1.5)

    dev.log("Step 5: Clean up & return Home")
    dev.terminate_app(args.bundle_id)
    dev.home()

if __name__ == "__main__":
    runner.run()
```

---

## 💻 Running Tests from the Command Line

### 1. Auto-discover all connected devices (Zero configuration)
```bash
python test_script.py --host 127.0.0.1
```
> Automatically queries the Cesium platform, detects all connected iPhones and iPads, and runs the test flow across all of them in parallel.

### 2. Run on specific target devices
```bash
python test_script.py --udids 00008101-0016056E3A22601E 00008110-001155242680A01E
```

### 3. Use your custom arguments
```bash
python test_script.py --scrolls 5 --toggle-wifi
```

### 4. Automatic Multi-Device Summary Report
```text
========================================================================
🚀 [Cesium Test Runner] Settings App Automation
📡 Host: 127.0.0.1 | 📱 Devices: 3 | 🧵 Workers: 3
========================================================================

[12:19:05] [..2680A01E] ▶️ Starting flow 'test_flow'
[12:19:05] [..0188801E] ▶️ Starting flow 'test_flow'
[12:19:05] [..3A68401E] ▶️ Starting flow 'test_flow'
[12:19:06] [..2680A01E] Step 3: Launching 'com.apple.Preferences'
[12:19:06] [..0188801E] Step 3: Launching 'com.apple.Preferences'
[12:19:06] [..3A68401E] Step 3: Launching 'com.apple.Preferences'
[12:19:12] [..2680A01E] ✅ Completed successfully in 7.05s
[12:19:12] [..0188801E] ✅ Completed successfully in 7.09s
[12:19:12] [..3A68401E] ✅ Completed successfully in 7.01s

========================================================================
📊 EXECUTION SUMMARY: Settings App Automation
========================================================================
Status   #   UDID                         Duration   Details
------------------------------------------------------------------------
✅ PASS   1   00008110-001155242680A01E      7.05s    Completed successfully
✅ PASS   2   00008101-001D30500188801E      7.09s    Completed successfully
✅ PASS   3   00008110-001A38503A68401E      7.01s    Completed successfully
========================================================================
Total: 3 | Passed: 3 | Failed: 0 | Total Time: 7.09s
```

---

## 🛠️ Complete `IOSDevice` API Reference

### 1. Navigation & System Gestures
| Method / Property | Description |
| :--- | :--- |
| `dev.home()` | Hardware gesture to return to SpringBoard Home screen. |
| `dev.app_switcher()` | Hardware gesture to open native iOS multitasking App Switcher. |
| `dev.back()` | Taps standard iOS top-left navigation back button (`0.08, 0.065`). |
| `dev.sleep(seconds)` | Pauses execution for the specified duration (seconds). |
| `dev.wait(seconds)` | Alias for `dev.sleep()`. |
| `dev.log(message)` | Prints a thread-safe message prefixed with timestamp and device UDID tag. |
| `dev.is_tablet` | Boolean property: returns `True` if connected device is an iPad, `False` for iPhones. |

### 2. Device Discovery & Port Resolution (Class Methods)
| Method | Description |
| :--- | :--- |
| `IOSDevice.get_connected_devices(host="127.0.0.1")` | Dynamically queries Cesium and returns `{udid: engine_port}` map for all connected devices. |
| `IOSDevice.list_devices(host="127.0.0.1")` | Returns a list of connected device UDIDs. |
| `IOSDevice.resolve_port_for_udid(udid, host="127.0.0.1")` | Dynamically resolves the active engine communication port for a given UDID. |

### 3. Touch Gestures & Hardware Digitizer
All coordinates are normalized fractions (`0.0` to `1.0`), making touch gestures device-agnostic across varying screen resolutions.
| Method | Description |
| :--- | :--- |
| `dev.tap(fx, fy, dwell_ms=80)` | Hardware digitizer tap at normalized coordinates `(fx, fy)`. |
| `dev.swipe(x0, y0, x1, y1, duration_ms=300)` | Hardware digitizer swipe from `(x0, y0)` to `(x1, y1)`. |
| `dev.scroll_down(duration_ms=300)` | Vertical swipe downwards (`0.50, 0.70` to `0.50, 0.30`). |
| `dev.scroll_up(duration_ms=300)` | Vertical swipe upwards (`0.50, 0.30` to `0.50, 0.70`). |

### 4. Application Lifecycle
| Method | Description |
| :--- | :--- |
| `dev.launch_app(bundle_id, url=None)` | Launches app cold via CoreDevice. Optional deep link URL opens in < 25ms. Includes automatic DVT fallback. |
| `dev.terminate_app(name_or_bundle_id)` | Instantly terminates running process matching bundle ID or executable name. |
| `dev.terminate_process(pid, signal=9)` | Terminates a process directly by its PID. |
| `dev.list_processes()` | Lists all active processes with PIDs and bundle identifiers. |

### 5. Text Input & Clipboard
| Method | Description |
| :--- | :--- |
| `dev.type(text)` | Types text into the focused field via CoreDevice Virtual Keyboard HID. |
| `dev.type_text(text, char_delay=0.04)` | Types text with calibrated modifier key support for symbols & capitals. |
| `dev.paste()` | Sends Command + V to paste the current system clipboard into the focused field. |
| `dev.set_clipboard(text)` | Sets iOS system clipboard directly via CoreDevice pasteboard service. |
| `dev.get_clipboard()` | Reads iOS system clipboard contents. |

### 6. Wi-Fi Management
| Method | Description |
| :--- | :--- |
| `dev.toggle_wifi()` | Toggles Wi-Fi interface state (On ↔ Off). |
| `dev.connect_wifi(ssid, password)` | Associates device with target Wi-Fi network. |
| `dev.forget_wifi(ssid)` | Forgets target Wi-Fi network profile. |

### 7. Accessibility & UI Element Finding
Inspects and interacts with on-screen elements (labels, buttons, switches) in sub-80ms:
| Method | Description |
| :--- | :--- |
| `dev.get_elements()` | Dumps all visible on-screen elements (`UIElement` objects). |
| `dev.find_element(text_or_predicate)` | Searches for visible element matching caption substring or predicate function. |
| `dev.tap_element(text_or_element)` | Finds element by caption and taps its exact center. |
| `dev.tap_toggle(row_name)` | Directly clicks the toggle switch for a row (e.g. "Wi-Fi", "Bluetooth", "Airplane Mode"). |
| `dev.get_toggle_state(row_name)` | Returns `"ON"` or `"OFF"` for a given switch row. |
| `dev.screenshot(save_path=None)` | Captures uncompressed PNG screenshot in ~78ms. |
| `dev.inspect()` | Prints an ASCII table of all visible UI elements, types, states, and coordinates. |

---

## 📋 `UIElement` Properties
When calling `dev.get_elements()` or `dev.find_element()`, each element provides:
- `el.text`: Element text, label, or accessibility caption.
- `el.element_type`: `"Button"`, `"Switch"`, `"Header"`, `"Label"`, or `"Paragraph"`.
- `el.state`: State string (e.g. `"ON"`, `"OFF"` for toggle switches, or `None`).
- `el.fx`, `el.fy`: Normalized center coordinates `(0.0 - 1.0)` ready for hardware touch injection.
- `el.left`, `el.top`, `el.width`, `el.height`: Pixel bounding box dimensions.

---

## 📖 Practical Script Examples

### Example 1: Interacting with Settings & Toggle Switches
```python
from cesium_ios import IOSDevice

dev = IOSDevice()

# Launch Settings
dev.launch_app("com.apple.Preferences")
dev.sleep(2.0)

# Check Wi-Fi switch state and toggle it
state = dev.get_toggle_state("Wi-Fi")
dev.log(f"Current Wi-Fi Switch state: {state}")

dev.tap_toggle("Wi-Fi")
dev.sleep(2.0)

# Return Home
dev.home()
```

### Example 2: Typing Text into Input Fields
```python
from cesium_ios import IOSDevice

dev = IOSDevice()

# Tap input field at normalized coordinates (or by element name)
dev.tap(0.50, 0.25)
dev.sleep(0.5)

# Type text with special characters and uppercase letters
dev.type("LanforgePassword123!")

# Alternatively, set clipboard and paste instantly:
dev.set_clipboard("SecretTokenXYZ")
dev.paste()
```

### Example 3: Inspecting UI Elements with ASCII Inspector Table
```python
from cesium_ios import IOSDevice

dev = IOSDevice()
dev.launch_app("com.apple.Preferences")
dev.sleep(2.0)

# Prints full on-screen hierarchy table to terminal:
dev.inspect()
```
Output:
```text
🔍 [Cesium Inspector] Detected 12 visible UI elements on 00008110-001155242680A01E (1170x2532):
================================================================================================
#   Type               Name / Element                         State    Center (fx, fy)   
------------------------------------------------------------------------------------------------
1   Header             Settings                               -        (0.500, 0.065)    
2   Switch             Airplane Mode Switch [OFF]             [OFF]    (0.875, 0.175)    
3   Label              Airplane Mode                          -        (0.245, 0.175)    
4   Switch             Wi-Fi Switch [ON]                      [ON]     (0.875, 0.235)    
5   Label              Wi-Fi                                  -        (0.180, 0.235)    
6   Button             Bluetooth                              -        (0.500, 0.295)    
================================================================================================
```

---

## 🚢 Building & Packaging the SDK
```bash
cd cesium_sdk
python -m build
```
