Skip to content

n0an/VivaDicta / .agents/skills/ios-simulator-skill

ios-simulator-skill

Verified

21 production-ready scripts for iOS app testing, building, and automation. Provides semantic UI navigation, build automation, accessibility testing, and simulator lifecycle management. Optimized for AI agents with minimal token output.

FileKindSize
SKILL.mdskill md9.9 KB
agents/openai.yamlconfig279 B
references/accessibility_checklist.mdmarkdown1.5 KB
references/idb_quick.mdmarkdown1.1 KB
references/simctl_quick.mdmarkdown1.3 KB
references/test_patterns.mdmarkdown1.6 KB
references/troubleshooting.mdmarkdown1.3 KB
scripts/accessibility_audit.pyexecutablescript10.0 KB
scripts/app_launcher.pyexecutablescript9.5 KB
scripts/app_state_capture.pyexecutablescript12.9 KB
scripts/build_and_test.pyexecutablescript11.1 KB
scripts/clipboard.pyexecutablescript2.6 KB
scripts/common/__init__.pyscript1.5 KB
scripts/common/cache_utils.pyscript8.1 KB
scripts/common/device_utils.pyscript13.5 KB
scripts/common/idb_utils.pyscript5.3 KB
scripts/common/screenshot_utils.pyscript10.0 KB
scripts/gesture.pyexecutablescript12.3 KB
scripts/keyboard.pyexecutablescript11.5 KB
scripts/log_monitor.pyexecutablescript14.6 KB
scripts/navigator.pyexecutablescript14.0 KB
scripts/privacy_manager.pyexecutablescript8.7 KB
scripts/push_notification.pyexecutablescript6.5 KB
scripts/screen_mapper.pyexecutablescript10.4 KB
scripts/sim_health_check.shexecutablescript7.7 KB
scripts/sim_list.pyexecutablescript8.9 KB
scripts/simctl_boot.pyexecutablescript8.6 KB
scripts/simctl_create.pyexecutablescript8.9 KB
scripts/simctl_delete.pyexecutablescript10.3 KB
scripts/simctl_erase.pyexecutablescript9.8 KB
scripts/simctl_shutdown.pyexecutablescript8.4 KB
scripts/simulator_selector.pyexecutablescript10.3 KB
scripts/status_bar.pyexecutablescript6.6 KB
scripts/test_recorder.pyexecutablescript10.6 KB
scripts/visual_diff.pyexecutablescript7.6 KB
scripts/xcode/__init__.pyscript378 B
scripts/xcode/builder.pyscript12.8 KB
scripts/xcode/cache.pyscript5.5 KB
scripts/xcode/config.pyscript5.4 KB
scripts/xcode/reporter.pyscript10.3 KB
scripts/xcode/xcresult.pyscript16.5 KB

scripts/simctl_boot.py

View on GitHub
#!/usr/bin/env python3
"""
Boot iOS simulators and wait for readiness.

This script boots one or more simulators and optionally waits for them to reach
a ready state. It measures boot time and provides progress feedback.

Key features:
- Boot by UDID or device name
- Wait for device readiness with configurable timeout
- Measure boot performance
- Batch boot operations (boot all, boot by type)
- Progress reporting for CI/CD pipelines
"""

import argparse
import subprocess
import sys
import time

from common.device_utils import (
    get_booted_device_udid,
    list_simulators,
    resolve_device_identifier,
)


class SimulatorBooter:
    """Boot iOS simulators with optional readiness waiting."""

    def __init__(self, udid: str | None = None):
        """Initialize booter with optional device UDID."""
        self.udid = udid

    def boot(self, wait_ready: bool = False, timeout_seconds: int = 120) -> tuple[bool, str]:
        """
        Boot simulator and optionally wait for readiness.

        Args:
            wait_ready: Wait for device to be ready before returning
            timeout_seconds: Maximum seconds to wait for readiness

        Returns:
            (success, message) tuple
        """
        if not self.udid:
            return False, "Error: Device UDID not specified"

        start_time = time.time()

        # Check if already booted
        try:
            booted = get_booted_device_udid()
            if booted == self.udid:
                elapsed = time.time() - start_time
                return True, (f"Device already booted: {self.udid} " f"[checked in {elapsed:.1f}s]")
        except RuntimeError:
            pass  # No booted device, proceed with boot

        # Execute boot command
        try:
            cmd = ["xcrun", "simctl", "boot", self.udid]
            result = subprocess.run(cmd, check=False, capture_output=True, text=True, timeout=30)

            if result.returncode != 0:
                error = result.stderr.strip()
                return False, f"Boot failed: {error}"
        except subprocess.TimeoutExpired:
            return False, "Boot command timed out"
        except Exception as e:
            return False, f"Boot error: {e}"

        # Optionally wait for readiness
        if wait_ready:
            ready, wait_message = self._wait_for_ready(timeout_seconds)
            elapsed = time.time() - start_time
            if ready:
                return True, (f"Device booted and ready: {self.udid} " f"[{elapsed:.1f}s total]")
            return False, wait_message

        elapsed = time.time() - start_time
        return True, (
            f"Device booted: {self.udid} [boot in {elapsed:.1f}s] "
            "(use --wait-ready to wait for availability)"
        )

    def _wait_for_ready(self, timeout_seconds: int = 120) -> tuple[bool, str]:
        """
        Wait for device to reach ready state.

        Args:
            timeout_seconds: Maximum seconds to wait

        Returns:
            (success, message) tuple
        """
        start_time = time.time()
        poll_interval = 0.5
        checks = 0

        while time.time() - start_time < timeout_seconds:
            try:
                checks += 1
                # Check if device responds to simctl commands
                result = subprocess.run(
                    ["xcrun", "simctl", "spawn", self.udid, "launchctl", "list"],
                    check=False,
                    capture_output=True,
                    text=True,
                    timeout=5,
                )

                if result.returncode == 0:
                    elapsed = time.time() - start_time
                    return True, (
                        f"Device ready: {self.udid} " f"[{elapsed:.1f}s, {checks} checks]"
                    )
            except (subprocess.TimeoutExpired, RuntimeError):
                pass  # Not ready yet

            time.sleep(poll_interval)

        elapsed = time.time() - start_time
        return False, (
            f"Boot timeout: Device did not reach ready state "
            f"within {elapsed:.1f}s ({checks} checks)"
        )

    @staticmethod
    def boot_all() -> tuple[int, int]:
        """
        Boot all available simulators.

        Returns:
            (succeeded, failed) tuple with counts
        """
        simulators = list_simulators(state="available")
        succeeded = 0
        failed = 0

        for sim in simulators:
            booter = SimulatorBooter(udid=sim["udid"])
            success, _message = booter.boot(wait_ready=False)
            if success:
                succeeded += 1
            else:
                failed += 1

        return succeeded, failed

    @staticmethod
    def boot_by_type(device_type: str) -> tuple[int, int]:
        """
        Boot all simulators of a specific type.

        Args:
            device_type: Device type filter (e.g., "iPhone", "iPad")

        Returns:
            (succeeded, failed) tuple with counts
        """
        simulators = list_simulators(state="available")
        succeeded = 0
        failed = 0

        for sim in simulators:
            if device_type.lower() in sim["name"].lower():
                booter = SimulatorBooter(udid=sim["udid"])
                success, _message = booter.boot(wait_ready=False)
                if success:
                    succeeded += 1
                else:
                    failed += 1

        return succeeded, failed


def main():
    """Main entry point."""
    parser = argparse.ArgumentParser(description="Boot iOS simulators and wait for readiness")
    parser.add_argument(
        "--udid",
        help="Device UDID or name (required unless using --all or --type)",
    )
    parser.add_argument(
        "--name",
        help="Device name (alternative to --udid)",
    )
    parser.add_argument(
        "--wait-ready",
        action="store_true",
        help="Wait for device to reach ready state",
    )
    parser.add_argument(
        "--timeout",
        type=int,
        default=120,
        help="Timeout for --wait-ready in seconds (default: 120)",
    )
    parser.add_argument(
        "--all",
        action="store_true",
        help="Boot all available simulators",
    )
    parser.add_argument(
        "--type",
        help="Boot all simulators of a specific type (e.g., iPhone, iPad)",
    )
    parser.add_argument(
        "--json",
        action="store_true",
        help="Output as JSON",
    )

    args = parser.parse_args()

    # Handle batch operations
    if args.all:
        succeeded, failed = SimulatorBooter.boot_all()
        if args.json:
            import json

            print(
                json.dumps(
                    {
                        "action": "boot_all",
                        "succeeded": succeeded,
                        "failed": failed,
                        "total": succeeded + failed,
                    }
                )
            )
        else:
            total = succeeded + failed
            print(f"Boot summary: {succeeded}/{total} succeeded, " f"{failed} failed")
        sys.exit(0 if failed == 0 else 1)

    if args.type:
        succeeded, failed = SimulatorBooter.boot_by_type(args.type)
        if args.json:
            import json

            print(
                json.dumps(
                    {
                        "action": "boot_by_type",
                        "type": args.type,
                        "succeeded": succeeded,
                        "failed": failed,
                        "total": succeeded + failed,
                    }
                )
            )
        else:
            total = succeeded + failed
            print(f"Boot {args.type} summary: {succeeded}/{total} succeeded, " f"{failed} failed")
        sys.exit(0 if failed == 0 else 1)

    # Resolve device identifier
    device_id = args.udid or args.name
    if not device_id:
        print("Error: Specify --udid, --name, --all, or --type", file=sys.stderr)
        sys.exit(1)

    try:
        udid = resolve_device_identifier(device_id)
    except RuntimeError as e:
        print(f"Error: {e}", file=sys.stderr)
        sys.exit(1)

    # Boot device
    booter = SimulatorBooter(udid=udid)
    success, message = booter.boot(wait_ready=args.wait_ready, timeout_seconds=args.timeout)

    if args.json:
        import json

        print(
            json.dumps(
                {
                    "action": "boot",
                    "device_id": device_id,
                    "udid": udid,
                    "success": success,
                    "message": message,
                }
            )
        )
    else:
        print(message)

    sys.exit(0 if success else 1)


if __name__ == "__main__":
    main()
finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the workStars: 322kUpdated Claude CodeCodexVerifiedInstall
systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixesStars: 322kUpdated Claude CodeCodexVerifiedInstall
test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation codeStars: 322kUpdated Claude CodeCodexVerifiedInstall
skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy.Stars: 198kUpdated Claude CodeCodexVerifiedInstall