Skip to content

Mobile devices (Appium)

Video: iOS simulators and Android emulators (1:06).

Appium clients use the same /wd/hub as Selenium. When the capabilities say platformName: Android or iOS, the gateway picks a device instead of a browser, gets it ready, and opens an Appium session on it for you.

Where devices come from

A device pool is a set of identical devices, for example "Pixel 8, Android 15" or "iPad Air, iOS 27.2". Devices join a pool in one of two ways:

  • Hosts. A machine outside the cluster runs hearth-agent next to its devices: a Mac with iOS simulators, or a Linux or macOS machine with Android emulators. You add one with hearth hosts add (or Hosts in the web UI) and one pasted line on the machine, then choose its devices; the farm makes the device pools for you. See Add a Mac in two minutes.
  • Emulator pods (Android only). With cluster: set on a DevicePool, the operator runs Android emulators as pods, each with its own Appium and agent. The nodes need /dev/kvm.

Unlike browser pods, devices are reused: after a session the agent resets the device (Android: reload a clean snapshot; iOS: replace the simulator with a fresh clone) and reports it ready again.

Declare a pool

Pools for hosts added from the farm are made from their plans (Choose its simulators); you do not declare them. Declare pools in the chart values for in-cluster emulators, and for hosts listed under agents: (the older way). Such a host may only report devices of a declared DevicePool (403 unknown_pool otherwise). In the chart values:

devicePools:
  - name: pixel8
    platform: android
    deviceName: Pixel 8
    osVersion: "15"
    cluster: { warm: 1 }          # omit for hosts listed under agents:
  - name: ipad-air
    platform: ios
    deviceName: iPad Air 11-inch (M4)
    osVersion: "27.2"

Each entry becomes a DevicePool resource:

Field Default Meaning
platform (required) android or ios
deviceName "" Shown to users; matched against appium:deviceName
osVersion "" Matched against appium:platformVersion
maxSessions 10 Most sessions at once; for emulator pods, also the most pods
queueTimeoutSeconds 300 How long a request may wait for a free device
idleTimeoutSeconds 300 A session with no command for this long is ended
cluster unset Android only: run emulators as pods (below)

A pool name may not also be a browser pool's name.

Emulators in the cluster

cluster:
  warm: 1                       # idle emulators kept booted
  image: ""                     # defaults to the chart's android.image
  resources: { cpu: "4", memory: 6Gi, shm: 512Mi }
  nodeSelector: { hearth.testzeus.com/kvm: "true" }
  scaleDownDelaySeconds: 300    # idle emulators above warm go after this long

What you need to know:

  • The emulator needs hardware virtualisation. Nodes must expose /dev/kvm; on most clouds that means bare-metal or nested-virtualisation instance types. Use nodeSelector to land the pods on them. A pod without /dev/kvm exits at once with no /dev/kvm: emulator pods need nodes with hardware virtualisation.
  • The image (hearth-android:35, built from the android target of the Dockerfile and published for linux/amd64 only) holds Android API 35 (google_apis, x86_64), Appium with the UiAutomator2 driver, and hearth-agent.
  • Emulator pods run privileged to use /dev/kvm. Put them on dedicated nodes.
  • Each pod's agent reports as host cluster-<pod name> with the chart's cluster agent token, and serves one device, cluster-<pod name>-<pool>-1.
  • The operator sizes emulator pools like browser pools: warm idle emulators plus one per queued request, up to maxSessions. See Pools and scaling.

Upload your app

Devices never download apps from a URL you pass. You upload the app once, and refer to it by its SHA-256:

hearth app upload app-debug.apk          # prints hearth:app:<sha256>

or with the API:

curl -sS -X POST "$HEARTH_URL/api/apps" \
  -H "Authorization: Bearer $HEARTH_KEY" \
  -H "x-filename: app-debug.apk" \
  --data-binary @app-debug.apk
{"sha256": "9f2c...", "name": "app-debug.apk", "size": 5242880, "uploadedMs": 1796000000000, "ref": "hearth:app:9f2c..."}
  • Android: an .apk. iOS simulators: one simulator .app packed as a .zip (or .app.zip), at the top of the zip or under Payload/. .ipa files are refused; simulators cannot run device builds.
  • File names are letters, digits, spaces, ., - and _. Up to 2 GiB. The same bytes always get the same reference, so uploading again is harmless.
  • Apps belong to your team. GET /api/apps lists them; the web UI has an Apps page that does the same upload and copies the reference.

The agent installs an APK with adb install -r -g and reads its package and launch activity; it unpacks an iOS zip with path checks, installs it with simctl install and reads the bundle id.

Connect

Put the reference in appium:app:

from appium import webdriver
from appium.options.common import AppiumOptions
from appium.webdriver.client_config import AppiumClientConfig

hub = "https://hearth.example.com/wd/hub"
options = AppiumOptions()
options.set_capability("platformName", "Android")
options.set_capability("appium:automationName", "UiAutomator2")
options.set_capability("appium:app", "hearth:app:9f2c...")
options.set_capability("hearth:options", {"pool": "pixel8"})

config = AppiumClientConfig(remote_server_addr=hub, username="hearth", password=key)
driver = webdriver.Remote(hub, options=options, client_config=config)
import { remote } from "webdriverio";

const driver = await remote({
  protocol: "https",
  hostname: "hearth.example.com",
  port: 443,
  path: "/wd/hub",
  headers: { Authorization: `Bearer ${process.env.HEARTH_KEY}` },
  capabilities: {
    platformName: "iOS",
    "appium:automationName": "XCUITest",
    "appium:app": "hearth:app:4b1e...",
    "appium:deviceName": "iPad",
  },
});

Runnable: examples/appium-python and examples/appium-node.

A session without appium:app starts on the device's home screen.

How the device is picked

  1. hearth:options.pool, if set, picks a pool by name (it must be of the right platform). (hearth:options.name names the session, as for Selenium.)
  2. Otherwise, pools of that platformName are filtered by appium:deviceName (a case-insensitive substring of the pool's deviceName, so "iPad" matches "iPad Air 11-inch (M4)") and by appium:platformVersion (equal to the pool's osVersion, or a prefix of it: "27" matches "27.2").
  3. Of the matches, the pool with the highest osVersion wins.

If nothing matches, the session is refused with this farm has no ios "iPhone" 26 devices (or similar).

Capabilities the farm owns

The gateway builds the capabilities Appium gets:

  1. It takes yours and removes hearth:options and se:*.
  2. It flattens appium:options into top-level appium: keys, so nested keys get the same checks (a top-level key wins over a nested one).
  3. It drops every capability that points at host resources, makes the device fetch something, or runs host programs. Matched case-insensitively, with or without the appium: prefix:

    app, otherApps, udid, webDriverAgentUrl, wdaLocalPort, mjpegServerPort, systemPort, derivedDataPath, chromedriverPort, chromedriverExecutable, chromedriverExecutableDir, chromedriverChromeMappingFile, avd, avdArgs, avdLaunchTimeout, remoteAdbHost, adbHost, adbPort, adbExecTimeout, keystorePath, keystorePassword, keyAlias, keyPassword, prebuiltWdaPath, usePreinstalledWda, usePrebuiltWda, agentPath, bootstrapPath, xcodeConfigFile

  4. It adds the device's own capabilities from its agent (platform, automation name, udid, device name and version, its ports, and for iOS appium:isHeadless and MJPEG settings), then the app capabilities from preparing the device (appium:appPackage and appium:appActivity, or appium:bundleId). These always win.

Every other capability you send reaches Appium as is.

Commands the farm blocks

Commands that install apps, move files or run programs on the host answer 403 unsupported operation:

  • POST .../appium/device/install_app, push_file, pull_file, pull_folder, and .../appium/app/install: installing apps or moving files is not allowed; upload apps with POST /api/apps.
  • execute/sync and execute/async with the scripts mobile: installApp, mobile: installMultipleApks, mobile: shell, mobile: pushFile, mobile: pullFile, mobile: pullFolder, mobile: execEmuConsoleCommand, mobile: startLogsBroadcast, mobile: installCertificate, mobile: injectEmulatorCameraImage: this mobile: command is not allowed on the farm.
  • Command paths with .., ., ?, #, \ or % are refused with 400 invalid argument.

Other mobile: commands (for example mobile: pressKey) work.

During and after a session

  • Commands go through the gateway to the device's agent, which forwards them to the device's Appium on its host. The session id you see is the farm's.
  • driver.quit() (W3C DELETE /session/{id}) ends the session. The gateway tells the agent to release the device; the agent stops recording, uploads video.mp4 and device.log, and resets the device. The artifacts appear on the session a little after it ends.
  • A session with no command for idleTimeoutSeconds (5 minutes by default) is ended and marked failed: ended after no command for too long.
  • If the agent restarts mid-session and reports the device free, the session is marked failed: the device restarted during the session. If an emulator pod disappears, its session is marked failed: the browser or device went away during the session.
  • The web UI shows the device screen live, and take control sends taps, swipes, text, hardware buttons, keys and rotation through the running Appium session. See The web UI.

Not built yet

  • Reserving devices for a team (Team.spec.reserved) and keeping a team's apps installed between sessions.
  • Real iOS hardware. Hearth targets simulators on Mac hosts.