Orchard.Simulator (orchard v0.1.7)

View Source

Module for managing iOS simulators using AXe CLI.

This module provides functions to list, boot, and manage simulators. When a simulator is booted, a SimulatorServer GenServer is started to manage its lifecycle.

Summary

Functions

Boots a simulator.

Starts video capture from the simulator using screenshot-based streaming.

Gets UI hierarchy description from AXe

Erases a simulator's contents and settings.

Finds a simulator by its name or UDID.

Gets the server process for a simulator.

Installs an app on the simulator.

Launches an app on the simulator.

Lists all available simulators.

Lists only booted simulators.

Records video using native simctl recording (file-based only).

Takes a screenshot of the simulator.

Shuts down a simulator.

Records video from the simulator. Returns the PID of the recording process.

Stops video recording.

Stops a video capture or recording process.

UI automation functions using AXe

Uninstalls an app from the simulator.

Types

t()

@type t() :: %Orchard.Simulator{
  device_type: String.t(),
  name: String.t(),
  runtime: String.t(),
  state: String.t(),
  udid: String.t()
}

Functions

boot(simulator)

@spec boot(String.t() | t()) :: {:ok, t()} | {:error, String.t()}

Boots a simulator.

capture_video(simulator, opts \\ [])

Starts video capture from the simulator using screenshot-based streaming.

Note: iOS simulators don't provide real-time video streams. This method captures screenshots at regular intervals and encodes them into a video stream.

Options:

  • :output - Output path or streaming URL (default: "/tmp/simulator_<udid>.mp4")
  • :fps - Frames per second (default: 30)
  • :duration - Maximum duration in seconds (optional)

For true real-time streaming, consider using Facebook's idb tool alongside Orchard.

Examples

iex> {:ok, simulator} = Orchard.Simulator.find_by_name("iPhone 15")
iex> {:ok, stream} = Orchard.Simulator.capture_video(simulator, output: "output.mp4", fps: 30)
iex> Orchard.Simulator.stop_video_capture(stream)
:ok

describe_ui(simulator)

Gets UI hierarchy description from AXe

erase(identifier)

@spec erase(String.t() | t()) :: :ok | {:error, String.t()}

Erases a simulator's contents and settings.

find(identifier)

@spec find(String.t()) :: {:ok, t()} | {:error, String.t()}

Finds a simulator by its name or UDID.

get_server(udid)

@spec get_server(String.t()) :: {:ok, pid()} | {:error, :not_found}

Gets the server process for a simulator.

install_app(simulator, app_path)

@spec install_app(t(), String.t()) :: :ok | {:error, String.t()}

Installs an app on the simulator.

launch_app(simulator, bundle_id, args \\ [])

@spec launch_app(t(), String.t(), [String.t()]) :: :ok | {:error, String.t()}

Launches an app on the simulator.

list()

@spec list() :: {:ok, [t()]} | {:error, String.t()}

Lists all available simulators.

Returns a list of simulator structs.

list_booted()

@spec list_booted() :: {:ok, [t()]} | {:error, String.t()}

Lists only booted simulators.

record_video(simulator, output_path, opts \\ [])

Records video using native simctl recording (file-based only).

This uses Apple's built-in recording functionality which provides excellent quality but only supports recording to files, not real-time streaming.

Options:

  • :codec - Video codec: "h264" (default) or "hevc"
  • :display - Display to record: "internal" (default) or "external"
  • :mask - Black mask setting: "ignored" (default) or "black"
  • :force - Force overwrite existing file (default: false)

Examples

iex> {:ok, recording} = Orchard.Simulator.record_video(simulator, "recording.mp4")
iex> Process.sleep(5000)  # Record for 5 seconds
iex> Orchard.Simulator.stop_recording(recording)
:ok

screenshot(simulator, output_path)

@spec screenshot(t(), String.t()) :: :ok | {:error, String.t()}

Takes a screenshot of the simulator.

shutdown(identifier)

@spec shutdown(String.t() | t()) :: :ok | {:error, String.t()}

Shuts down a simulator.

start_recording(simulator, output_path)

@spec start_recording(t(), String.t()) :: {:ok, pid()} | {:error, String.t()}

Records video from the simulator. Returns the PID of the recording process.

stop_recording(pid)

@spec stop_recording(pid()) :: :ok

Stops video recording.

stop_video_capture(capture_info)

Stops a video capture or recording process.

tap(simulator, x, y)

UI automation functions using AXe

type_text(simulator, text)

uninstall_app(simulator, bundle_id)

@spec uninstall_app(t(), String.t()) :: :ok | {:error, String.t()}

Uninstalls an app from the simulator.