Skip to Content
Spawndroid

CI tests

Run automated Android UI tests on hosted devices from any CI.

Spawndroid hosts an Appium 3 server with the UiAutomator2 driver for each CI session. Your pipeline brings the test framework. Anything that speaks the W3C WebDriver protocol works: WebdriverIO, Selenium, or an Appium client in any language. There is no SDK to vendor and no test format to adopt.

There are three ways to drive a run. The CLI is the shortest path and the one the docs build around; the GitHub Action wraps it for Actions users; the raw API is there when you need explicit control.

Quick start with the CLI

The CLI is published on npm as spawndroid and needs Node 20 or newer. Run it with npx (nothing to install), install it globally with npm install --global spawndroid, or add it to the project with npm install --save-dev spawndroid.

npx spawndroid init                                  # detect the project, write the spec + workflow
export SPAWNDROID_API_KEY=spawn_live_…               # API & CI/CD → API keys, upload scope
npx spawndroid check                                 # name the walls before the first run
npx spawndroid run                                   # upload → boot → test → report → teardown

init reads the project (Gradle, Maven, WebdriverIO, pytest), prints what it inferred, and writes spawndroid.yaml plus .github/workflows/spawndroid.yml. It asks only for what it cannot infer, and stops with the flag to pass when it cannot find an APK or a test command. Every flag is overridable for non-interactive setups:

npx spawndroid init --app app/build/outputs/apk/debug/app-debug.apk \
  --command "mvn test" --report target/surefire-reports/TEST-com.example.CheckoutTest.xml

check probes the API key, validates the APK, fixtures and report path, and prints your plan's walls. run exits 0 when the suite passed, 1 when it failed, and 2 when the run could not happen — so CI retry logic never re-runs a genuine failure.

The spec

version: 1
app: app/build/outputs/apk/debug/app-debug.apk # APK path, or an uploaded app slug
command: [mvn, test] # string is split; list is exact argv
profile: android-14-phone # optional device profile
report: target/surefire-reports/TEST-com.example.CheckoutTest.xml
timeout: 600 # seconds to wait for the device
fixtures: # optional files pushed after readiness
  - local: test/fixtures/sample.jpg
    device: /sdcard/Pictures # absolute directory under /sdcard

Unknown keys are errors — a misspelled timeout must not silently fall back to the default. report is a single JUnit XML file, not a glob. Fixtures are capped at 32 MB each and are pushed only after the device reports ready.

What run does

  1. Uploads the APK (or reuses an already-uploaded build when app is a slug), creating a session with an Idempotency-Key.
  2. Retries a capacity 429 up to 3 attempts over about 90 seconds; plan limits fail immediately.
  3. Waits up to timeout for the device, then pushes fixtures.
  4. Runs command locally on the runner with the session in its environment.
  5. Posts the JUnit report, tears the device down, and prints the run URL.

The command receives SPAWNDROID_WD_URL, SPAWNDROID_UDID, SPAWNDROID_APP_PACKAGE, SPAWNDROID_APP and SPAWNDROID_SESSION_ID. The build is installed before your command runs — never set appium:app.

On GitHub Actions the CLI also records the commit, branch and repository on the run, and writes session-id, run-url and result to $GITHUB_OUTPUT.

Credentials

  • Create a key under API & CI/CD → API keys with the upload scope. Keys are workspace-scoped, not per project; the scopes form a hierarchy, read ⊂ upload ⊂ full.
  • Store it as a secret — a GitHub Actions secret, a masked and protected GitLab CI/CD variable, or the equivalent in your runner. Never echo it or put it in a build artifact.
  • The Hobby plan allows one key per workspace, so name it for the pipeline you are wiring up.

GitHub Action

- uses: spawndroid/cli@v0.1.8
  with:
    api-key: ${{ secrets.SPAWNDROID_API_KEY }}

The Action runs spawndroid run --config spawndroid.yaml on the checked-out repository and exposes session-id, run-url and result as step outputs. Inputs:

InputDefaultMeaning
api-key—Required. Key with the upload scope.
configspawndroid.yamlPath to the spec.
api-urlhttps://app.spawndroid.ioConsole origin.
version0.1.0CLI version to run.

Pull requests from forks

GitHub gives pull requests from forks no repository secrets, so SPAWNDROID_API_KEY is empty there and the step cannot reach Spawndroid. The workflow the console generates still builds a fork's pull request, runs the Spawndroid step only for branches of the repository itself, and leaves a notice on the run saying why it was skipped:

- uses: spawndroid/cli@v0.1.8
  if: github.event.pull_request.head.repo.full_name == github.repository
  with:
    api-key: ${{ secrets.SPAWNDROID_API_KEY }}

Contributors get a device run by pushing their branch to the repository instead of a fork. Do not switch the trigger to pull_request_target to work around this: it runs the fork's code with your secrets.

Run the four calls yourself

Use the per-run API when you need explicit control over the session.

1. Upload the build

A CI upload stores the build and returns its slug. It does not boot a device.

APK_ID=$(curl --silent --show-error --request POST https://app.spawndroid.io/api/apps \
  --header "Authorization: Bearer $SPAWNDROID_API_KEY" \
  --form "file=@app/build/outputs/apk/release/app-release.apk" \
  | jq --raw-output '.app.slug')

For builds near the 512 MB limit, upload directly to object storage with POST /api/apps/presign, then register the key. See the API reference.

2. Start a runner

RESPONSE=$(curl --silent --show-error --request POST https://app.spawndroid.io/api/v1/sessions \
  --header "Authorization: Bearer $SPAWNDROID_API_KEY" \
  --header "Content-Type: application/json" \
  --header "Idempotency-Key: ${CI_PIPELINE_ID:-local}-${CI_JOB_ID:-run}" \
  --data "{\"artifactId\": \"$APK_ID\"}")

SESSION_ID=$(echo "$RESPONSE" | jq --raw-output '.sessionId')
WD_URL=$(echo "$RESPONSE" | jq --raw-output '.webdriverUrl')
UDID=$(echo "$RESPONSE" | jq --raw-output '.device.serial')
PACKAGE=$(echo "$RESPONSE" | jq --raw-output '.app.package')

The Idempotency-Key makes the start step safe to retry. A second call with the same key resolves to the original runner instead of booting another device. Use the pipeline run ID, not a random value per attempt. While the first attempt is still creating, the retry returns 409 with code: "in_progress"; keep retrying with the same key.

Provisioning is asynchronous. The device boots and the APK is installed after the call returns. Follow the response's eventsUrl over SSE, or poll until the state is ready. The host allows 180 seconds to boot and 240 seconds to install, plus one boot retry, so give the loop at least 600 seconds:

for attempt in $(seq 1 120); do
  STATE=$(curl --silent --show-error https://app.spawndroid.io/api/v1/sessions/$SESSION_ID \
    --header "Authorization: Bearer $SPAWNDROID_API_KEY" \
    | jq --raw-output '.state')
  [ "$STATE" = "ready" ] && break
  [ "$STATE" = "failed" ] && exit 1
  sleep 5
done

Plan limits return 429 and are not worth retrying:

  • code: "PLAN_RUNNER_LIMIT" (legacy concurrency) — every parallel slot is in use. Free one or add one.
  • code: "PLAN_DEVICE_MINUTES_EXHAUSTED" (legacy device-minutes) — the monthly allowance is spent.

Capacity is different: when no device is free the controller answers 429 with a pool reason (free_pool_full, paid_pool_empty, paid_pool_full, …). There is no server-side queue, so a bounded retry is the right response; the CLI does three attempts over about 90 seconds.

3. Run the test

Point your framework's remote URL at $WD_URL. The build is already installed and is never launched for you, so the test owns the app lifecycle.

// webdriverio.mjs
import { remote } from "webdriverio"

const url = new URL(process.env.SPAWNDROID_WD_URL)
const driver = await remote({
  hostname: url.hostname,
  path: url.pathname, // /ci/sess_<id>/<token>/wd/hub
  protocol: "https",
  capabilities: {
    platformName: "Android",
    "appium:automationName": "UiAutomator2",
    "appium:udid": process.env.SPAWNDROID_UDID,
    "appium:appPackage": process.env.SPAWNDROID_APP_PACKAGE,
    "appium:autoGrantPermissions": true,
  },
})

// Appium 3: the driver-level startActivity endpoint is deprecated — use the
// execute command with the intent, or activateApp by package alone.
await driver.execute("mobile: startActivity", {
  intent: `${process.env.SPAWNDROID_APP_PACKAGE}/${process.env.LAUNCH_ACTIVITY}`,
})
// …your assertions…
await driver.deleteSession()

There is no appium:app capability because the build is pre-installed on the session device.

4. Report the result and tear down

The teardown request carries your test outcome. The console records it in the run history and forwards it to your webhooks.

curl --silent --show-error --request DELETE https://app.spawndroid.io/api/v1/sessions/$SESSION_ID \
  --header "Authorization: Bearer $SPAWNDROID_API_KEY" \
  --header "Content-Type: application/json" \
  --data '{"result": "passed"}'

Set result to passed or failed. Without a body, the run closes as passed, which keeps older pipelines working.

To attach the test report in the same call, add the JUnit XML as report. It is attached before the device is torn down, exactly as the separate report upload would:

jq --null-input --arg xml "$(cat build/test-results/junit.xml)" \
  '{result: "failed", report: $xml}' |
curl --silent --show-error --request DELETE https://app.spawndroid.io/api/v1/sessions/$SESSION_ID \
  --header "Authorization: Bearer $SPAWNDROID_API_KEY" \
  --header "Content-Type: application/json" \
  --data-binary @-

A report that is not JUnit XML never keeps the device running: teardown still happens, and the response says "reportAttached": false with the reason. A pipeline that dies without tearing down is closed as failed by the reconciler, so skipping teardown never yields a false pass.

Teardown destroys the device, retains the final Logcat dump and the screen recording, and returns what was stored.

{
  "ok": true,
  "result": "passed",
  "logcatStored": true,
  "videoStored": true,
  "reportAttached": true
}

reportAttached appears only when the request carried a report.

  • The retained Logcat is available at GET /api/v1/sessions/:id/logcat, either as a download or, with ?format=json, as parsed lines.
  • The screen recording is available at GET /api/v1/sessions/:id/video. Recording starts when the device is ready and covers the whole run. The recorder loops in segments and stitches them into one MP4 at teardown, so there is no length cap.
  • In the console, Runs shows each run's outcome with its Logcat viewer and video link.

Attach a test report

Upload the suite's JUnit XML and the run shows which tests failed, by name.

curl --request POST "https://app.spawndroid.io/api/v1/sessions/$SESSION_ID/report" \
  --header "Authorization: Bearer $SPAWNDROID_API_KEY" \
  --header "Content-Type: application/xml" \
  --data-binary @junit.xml

Through the stable hub, post to the WebDriver session instead:

curl --request POST "$HUB/session/$WEBDRIVER_SESSION_ID/report" \
  --header "Authorization: Bearer $SPAWNDROID_HUB_TOKEN" \
  --header "Content-Type: application/xml" \
  --data-binary @junit.xml

The report is parsed on upload. The run page shows the totals and the failing tests with their messages, and the raw XML is kept for download. Jest (jest-junit), pytest (--junitxml), Gradle/Espresso, Maestro (--format junit), and most other runners emit JUnit XML natively. The CLI posts the file named by report in the spec.

Post fixtures onto the device

Some suites need a file that is not in the build. After the session is ready, stage the bytes and ask the host to push them:

PRESIGN=$(curl --request POST "https://app.spawndroid.io/api/v1/sessions/$SESSION_ID/files/presign" \
  --header "Authorization: Bearer $SPAWNDROID_API_KEY" \
  --header "Content-Type: application/json" \
  --data '{"filename":"sample.jpg","path":"/sdcard/Pictures","size":12345}')

curl --request PUT "$(echo "$PRESIGN" | jq -r '.url')" \
  --header "Content-Type: application/octet-stream" \
  --data-binary @sample.jpg

curl --request POST "https://app.spawndroid.io/api/v1/sessions/$SESSION_ID/files" \
  --header "Authorization: Bearer $SPAWNDROID_API_KEY" \
  --header "Content-Type: application/json" \
  --data "{\"key\":\"$(echo "$PRESIGN" | jq -r '.key')\",\"path\":\"/sdcard/Pictures\",\"filename\":\"sample.jpg\"}"

The destination must be an absolute directory under /sdcard, the file is capped at 32 MB, and pushing before the device is ready returns 409 with code: "DEVICE_NOT_READY". The CLI's fixtures list does all three steps for you.

Stable hub

Point your suite at one endpoint with one token. Nothing changes between runs, so there is no URL or device serial to re-derive.

const driver = await remote({
  protocol: "https",
  hostname: "stream.spawndroid.io",
  port: 443,
  path: "/wd/hub",
  user: "spawndroid", // any non-empty value
  key: process.env.SPAWNDROID_HUB_TOKEN, // workspace hub token
  capabilities: {
    platformName: "Android",
    "appium:automationName": "UiAutomator2",
    "spawndroid:app": "my-app", // the app slug, its id, or the package id
    "spawndroid:profile": "android-14-phone", // optional
  },
})

On the first command, the hub allocates a device, installs the build, injects appium:udid, and records the run. Logcat, screen recording, run history, and webhooks work the same way as with the per-run API.

The hub accepts the token as HTTP Basic (username spawndroid, password is the token; this is what WebdriverIO's user/key, Selenium, and curl -u send) or as Authorization: Bearer <token>. The token is required only to create a session. Later commands are authorized by the session ID the hub issued, the same model as other device clouds. Generate the token under API & CI/CD → CI/CD → WebDriver hub; the Automation page shows the hub URL but does not mint tokens. It is shown once, expires, and only admins can create it.

The hub injects the device serial and returns spawndroid:appPackage and spawndroid:sessionId. It does not set appium:appPackage: Appium would then resolve the app's launchable activity, which is unreliable on ReDroid and fails for some builds. Set appium:appPackage and appium:appActivity yourself if you want Appium to launch the app, or leave both out and launch it yourself: mobile: startActivity with the intent (package/.Activity), or mobile: activateApp by package alone when you do not know the launcher activity. Both take the package id, never the slug.

Report a failing run in one of these ways, in order of preference:

# 1. Report before deleting (works with any framework that knows its session ID)
curl -X POST /wd/hub/session/<id>/result \
  -H "Authorization: Bearer $TOKEN" -d '{"result":"failed"}'

# 2. Report on teardown
DELETE /wd/hub/session/<id>?result=failed
DELETE /wd/hub/session/<id>    with header  X-Spawndroid-Result: failed

A session deleted without one of those is recorded as passed. Runs started through the hub appear in Runs as WebDriver hub. The hub also sets appium:newCommandTimeout to 300 seconds. Appium's default of 60 seconds would reap a session whose suite waits longer between commands.

Tie a run to a commit

Optional capabilities record the revision under test, so Runs can answer which commit broke:

"spawndroid:commit": process.env.GITHUB_SHA,
"spawndroid:branch": process.env.GITHUB_REF_NAME,
"spawndroid:repo":   "https://github.com/acme/app",   // for the link-out

These capabilities are never sent to Appium. The CLI and the GitHub Action send them automatically. The per-run API accepts the same values as commit, branch and repoUrl in the start body.

Instrumentation tests

CI sessions expose a WebDriver endpoint and install exactly one APK. There is no adb access and no second test-APK slot, so an am instrument flow is not supported. Your suite runs as an Appium client and drives the installed app. If you need am instrument semantics, use a physical-device farm instead.

Pipeline notes

  • Slot accounting is immediate. A start call either gets a runner or returns a capacity 429, so your job never waits in an invisible queue.
  • Runners are reaped automatically when idle, which protects the fleet if a pipeline exits without tearing down. Report the result explicitly so the outcome and artifacts are recorded.
  • If a pipeline is cancelled, times out, or crashes before teardown, the run is not lost. The host reaps the runner, stores the Logcat capture and recording, and the console closes the run as failed with both attached. Only a clean DELETE records your reported pass or fail.
  • Device profiles are chosen per session. Pass profileId when starting a runner to pin an Android version or form factor, for example android-13-phone or android-14-tablet.
  • CI runs are not capped by your plan's session length: they run to the host's ceiling (one hour by default), and their real minutes count against the monthly allowance. Manual sessions keep the plan cap (Hobby 15 minutes, Personal 60).

When a run fails

The CLI maps every failure to one of three exits — 0 green, 1 tests failed, 2 the run could not happen — and prints the registry code. What each code means:

What you seeMeaningFix
429 PLAN_RUNNER_LIMIT (legacy concurrency)Every parallel slot is busyWait for a running session, stop one, or add a slot. Retrying will not help.
429 PLAN_DEVICE_MINUTES_EXHAUSTED (legacy device-minutes)Monthly allowance spentWait for the reset or upgrade.
429 with a pool reason (paid_pool_empty, free_pool_full, …)No device capacity right nowRetry shortly; the CLI already retries three times over ~90 s.
504 UPSTREAM_TIMEOUT, 502The device host was slow or unreachableRetry. Twice in a row is worth reporting to support with the run URL.
DEVICE_BOOT_TIMEOUTThe device did not boot in timeRetry; check timeout in the spec is at least 600.
IMAGE_MISSINGThe requested image is not on the hostRetry later, or pick another profile.
BUILD_EXPIREDHobby builds expire 7 days after uploadUpload the build again.
HOBBY_BUILD_RESTRICTEDHobby restricts this package or exact build until support reviews itContact support with your workspace and app name, or use a paid workspace.
INSTALL_*, AAB_*The APK failed to installCheck minSdk, that it targets arm64, and that it is debuggable. AABs are converted at install.
DEVICE_NOT_READYA fixture was pushed before the device was readyThe CLI pushes after readiness; if you call the API yourself, poll state first.
Session never becomes readyBoot or install is stuckRun spawndroid check; if the host is slow, raise timeout. The session still bills only from ready.
Appium: Unable to resolve the launchable activityThe suite set appium:app or appium:appPackage, so Appium tried to launch the appRemove both. The build is pre-installed; your suite launches it (mobile: startActivity / activateApp).
Report not shown on the runreport is a directory, a glob, or the file was not writtenPoint report at one JUnit XML file. A missing report is a warning, not a failure.
check says the key is readThe API key lacks the upload scopeCreate a key with upload or full under API & CI/CD → API keys.

Two structural limits worth knowing before a run: CI sessions expose a WebDriver endpoint only (no adb), and exactly one APK is installed per session. An am instrument flow is not supported — see Instrumentation tests.

Set up with GitHub in one click

Connect GitHub under Settings → Integrations → GitHub, then choose Set up on a repository and Open setup pull request. Spawndroid opens a pull request with spawndroid.yaml and the workflow, and stores SPAWNDROID_API_KEY as a repository secret. Once merged, every pull request gets a Spawndroid / <build> · <device> check with the result and a link to the run.

See what changed since the last green run

Connect GitHub under Settings → Integrations → GitHub. A workspace admin picks the organization, and the repositories it shares are chosen on GitHub. After that, a failed run's Since the last green run panel lists the commits between it and the last passing run of the same app and branch, with a link to the full comparison. This needs both runs to report the same GitHub repository and full commit SHAs, which the GitHub Action does automatically.

Next steps

Was this page helpful?

On this page