---
title: "Run Appium tests"
description: "Run your existing Appium suite against cloud iOS simulators and Android emulators from any host, including a Linux CI runner."
sidebar:
  label: "Appium"
  order: 3
---

Your test code stays the same; only the driver setup and the capabilities change. iOS needs a Limrun fork of the XCUITest driver, while Android works with any upstream Appium driver over an ADB tunnel.

## Before you start

- The `lim` CLI and `LIM_API_KEY` set up as in the [Quickstart](/quickstart).
- Node 20.19 or newer to run the Appium server.
- An Appium test that already runs against a local device.

## How the integration works

Each platform takes a different route to the same Appium API.

**iOS** uses [`@limrun/appium-xcuitest-driver`](https://github.com/limrun-inc/appium-xcuitest-driver), a fork of the upstream XCUITest driver 12.22.8 for Appium 3. The fork keeps the public driver protocol identical to upstream but redirects the things upstream assumes are local:

- Simulator management (installing and launching apps, permissions, location, pasteboard, screenshots, screen recording), sent to the instance through the Limrun API instead of to CoreSimulator on the local host.
- File copies, uploaded through the Limrun API instead of writing to disk.
- Safari and WebView debugging, proxied through a tunnel to the simulator's Web Inspector socket.

WebDriverAgent itself is upstream. You install it on the instance as a normal app, and the driver reaches it over the instance's HTTPS endpoint for port 8100, authenticated with the instance token, or through [a localhost port](#reach-wda-through-localhost) opened by `lim ios forward`.

**Android** uses any upstream Appium driver (UiAutomator2, Espresso, Flutter) connected through an ADB tunnel opened by the Limrun SDK or CLI. Once `adb devices` shows the remote emulator on `127.0.0.1`, Appium treats it exactly like a USB-attached device.

Test code is portable: the same `webdriverio` or `appium-python-client` script that runs against a local simulator runs against a Limrun instance with only the capabilities changed.

## Run an iOS test

iOS needs more setup than Android: install a forked driver, provision an instance with WebDriverAgent on it, then pass the instance to the driver in two capabilities. If you only need Android, skip to [Run an Android test](#run-an-android-test).

### Install Appium and the driver

The driver requires Appium 3, so pin the major version when you install Appium:

```bash
npm i --location=global appium@3
appium driver install --source npm @limrun/appium-xcuitest-driver@12.22.8-lim.1
```

Start the Appium server in another terminal:

```bash
appium
```

The fork registers itself as `@limrun/xcuitest` (both `driverName` and `automationName`), so it coexists with the upstream `xcuitest` driver. Pick it via `appium:automationName` in your capabilities.

### Provision an instance with WebDriverAgent

WebDriverAgent isn't on a fresh instance by default. Hand the platform a download URL for the WDA build when you create the instance, and the platform will install it and auto-launch it before `create` returns:

```ts TypeScript
import { Limrun, Ios } from '@limrun/api';

const limrun = new Limrun({ apiKey: process.env.LIM_API_KEY });

// On success, WDA is installed and running on the simulator.
const instance = await limrun.iosInstances.create({
  wait: true,
  reuseIfExists: true,
  metadata: { labels: { name: 'appium-ios' } },
  spec: {
    initialAssets: [
      {
        kind: 'App',
        source: 'URL',
        url: 'https://github.com/appium/WebDriverAgent/releases/download/v10.4.5/WebDriverAgentRunner-Build-Sim-arm64.zip',
        launchMode: 'ForegroundIfRunning',
      },
    ],
  },
});
```

```python Python
import os
from limrun_api import Limrun

limrun = Limrun(api_key=os.environ["LIM_API_KEY"])

instance = limrun.ios_instances.create(
    wait=True,
    reuse_if_exists=True,
    metadata={"labels": {"name": "appium-ios"}},
    spec={
        "initial_assets": [
            {
                "kind": "App",
                "source": "URL",
                "url": "https://github.com/appium/WebDriverAgent/releases/download/v10.4.5/WebDriverAgentRunner-Build-Sim-arm64.zip",
                "launch_mode": "ForegroundIfRunning",
            },
        ],
    },
)
```

```go Go
import (
    "context"
    "os"
    limrun "github.com/limrun-inc/go-sdk"
    "github.com/limrun-inc/go-sdk/option"
    "github.com/limrun-inc/go-sdk/packages/param"
)

lim := limrun.NewClient(option.WithAPIKey(os.Getenv("LIM_API_KEY")))

instance, err := lim.IosInstances.New(context.TODO(), limrun.IosInstanceNewParams{
    Wait:          param.NewOpt(true),
    ReuseIfExists: param.NewOpt(true),
    Metadata: limrun.IosInstanceNewParamsMetadata{
        Labels: map[string]string{"name": "appium-ios"},
    },
    Spec: limrun.IosInstanceNewParamsSpec{
        InitialAssets: []limrun.IosInstanceNewParamsSpecInitialAsset{
            {
                Kind:       "App",
                Source:     "URL",
                URL:        param.NewOpt("https://github.com/appium/WebDriverAgent/releases/download/v10.4.5/WebDriverAgentRunner-Build-Sim-arm64.zip"),
                LaunchMode: "ForegroundIfRunning",
            },
        },
    },
})
```

The Python SDK covers instance operations (create, list, get, delete) but has no device client, so the WDA health check below is in TypeScript and Go. The Appium session itself runs in whatever language your test code is in.

`reuseIfExists` returns an existing instance only when its labels match exactly, so give each CI job or dev session its own label set. See [Concepts](/concepts) for how reuse and placement interact.

When the call resolves, two fields on the returned instance object are all the driver needs:

- `instance.status.apiUrl`, the instance API URL. The Limrun device client and the Appium driver both talk to it.
- `instance.status.token`, the instance token. Every URL on this instance authenticates with it, including WDA.

For production, push the WDA `.zip` to [Asset Storage](/platform/asset-storage) once and reference it by name, instead of pulling from GitHub on every run.

### Make sure WDA is running

WDA can crash during long runs, and the auto-launch you set up at create time only fires on first install. Before each session, ping WDA's `/status` endpoint on port 8100 with the instance token. If it doesn't answer cleanly, relaunch WDA with `simctl` through the Limrun device client:

```ts TypeScript
// The device client runs `simctl` on the simulator's host.
const ios = await Ios.createInstanceClient({
  apiUrl: instance.status.apiUrl!,
  token: instance.status.token!, // absent for read-only API keys and viewer seats
});

// Probe WDA's /status. A healthy WDA returns 200 with a JSON body.
const ok = await fetch(`${ios.targetHttpPortUrl(8100)}/status`, {
  headers: { Authorization: `Bearer ${instance.status.token}` },
  signal: AbortSignal.timeout(3000),
}).then((r) => r.ok).catch(() => false);

// If WDA is gone, relaunch it.
if (!ok) {
  await ios.simctl(['launch', 'booted', 'com.facebook.WebDriverAgentRunner.xctrunner']).wait();
}
// Keep `ios` open to install apps later; call ios.disconnect() when the suite ends.
```

```go Go
import (
    "context"
    "net/http"
    "os"

    iosws "github.com/limrun-inc/go-sdk/websocket/ios"
)

// Device client for the simulator. Used only to call `simctl`.
client, err := iosws.NewClient(instance.Status.APIURL, instance.Status.Token)
if err != nil { panic(err) }
defer client.Close()

// Probe WDA's /status with the instance token in the Authorization header.
// TargetHTTPPortURLPrefix proxies to any port inside the simulator.
req, _ := http.NewRequest("GET", instance.Status.TargetHTTPPortURLPrefix+"8100/status", nil)
req.Header.Set("Authorization", "Bearer "+instance.Status.Token)
resp, err := http.DefaultClient.Do(req)
ok := err == nil && resp.StatusCode == 200
if resp != nil { resp.Body.Close() }

// If WDA is gone, relaunch it on the booted simulator.
if !ok {
    cmd := client.Simctl(context.TODO(), "launch", "booted", "com.facebook.WebDriverAgentRunner.xctrunner")
    cmd.Stdout = os.Stdout
    cmd.Stderr = os.Stderr
    _ = cmd.Run()
}
```

### iOS capabilities

Pick your Appium client below. The capability keys are the same in every client; only the surrounding code differs.

```ts TypeScript
import { remote } from 'webdriverio';

const driver = await remote({
  hostname: '127.0.0.1',
  port: 4723,
  path: '/',
  capabilities: {
    platformName: 'iOS',
    browserName: 'safari',                              // omit for a native app session
    'appium:automationName': '@limrun/xcuitest',
    'appium:limInstanceApiUrl': instance.status.apiUrl,
    'appium:limInstanceToken': instance.status.token,
    'appium:noReset': true,                             // keep app data between sessions
  },
});
```

```python Python
from appium import webdriver
from appium.options.common import AppiumOptions

# `instance` is the create response from the Python SDK above.
opts = AppiumOptions()
opts.set_capability('platformName', 'iOS')
opts.set_capability('browserName', 'safari')            # omit for a native app session
opts.set_capability('appium:automationName', '@limrun/xcuitest')
opts.set_capability('appium:limInstanceApiUrl', instance.status.api_url)
opts.set_capability('appium:limInstanceToken', instance.status.token)  # absent for read-only API keys and viewer seats
opts.set_capability('appium:noReset', True)             # keep app data between sessions

driver = webdriver.Remote('http://127.0.0.1:4723', options=opts)
```

The Limrun-specific capabilities:

| Capability | Required | What it does |
|---|---|---|
| `appium:limInstanceApiUrl` | yes | The instance API URL (`instance.status.apiUrl`). The driver sends simulator calls, file uploads, and the Web Inspector tunnel through it. |
| `appium:limInstanceToken` | yes | The instance token (`instance.status.token`). Authenticates the URL above and every request to WDA. |
| `appium:limLogLevel` | no | One of `none`, `error`, `warn`, `info`, `debug`. Defaults to `info`. |

From those two capabilities, the driver fills in the rest of the WDA setup:

- `appium:udid` defaults to the instance's simulator. A session that sets a different UDID fails at session start.
- `appium:webDriverAgentUrl` defaults to the instance's HTTPS endpoint for port 8100. Set it only to reach WDA some other way.
- Every request to WDA carries the instance token as a `Bearer` authorization header.

Sessions written for the 10.x driver keep working: an explicit `appium:webDriverAgentUrl` is used as is, and `appium:wdaRequestHeaders` is still sent to WDA.

Everything else is standard XCUITest: `appium:bundleId` for a native app, `browserName: 'safari'` for the browser context, locator strategies, contexts, all unchanged.

### Reach WDA through localhost

To have Appium reach WDA on a port of the machine that runs the Appium server, forward port 8100 with CLI 0.65.1 or newer:

```bash
lim ios forward 8100 --id <ios-instance-id>
```

The command returns once `127.0.0.1:8100` listens, and keeps the forward running in a background process. It prints that process's ID; stop the forward with `kill <pid>` after the Appium session ends. Check that WDA responds:

```bash
curl --fail http://127.0.0.1:8100/status
```

The CLI authenticates the forward, so local requests to WDA need no Authorization header. The forward does not launch WDA. If the check fails, launch it:

```bash
lim ios simctl --id <ios-instance-id> -- launch booted com.facebook.WebDriverAgentRunner.xctrunner
```

Then add `appium:webDriverAgentUrl` to the [capabilities above](#ios-capabilities):

```ts TypeScript
// Add this entry to the capabilities object.
'appium:webDriverAgentUrl': 'http://127.0.0.1:8100',
```

```python Python
opts.set_capability('appium:webDriverAgentUrl', 'http://127.0.0.1:8100')
```

Keep `appium:limInstanceApiUrl` and `appium:limInstanceToken`. The driver still sends simulator calls, file uploads, and the Web Inspector tunnel through the instance API; the forward replaces only the WDA connection.

If local port 8100 is taken, run `lim ios forward 18100:8100 --id <ios-instance-id>` and use `http://127.0.0.1:18100`. To let the CLI pick a free port, run `lim ios forward 0:8100 --id <ios-instance-id> --json` and read `localPort` from its output.

### A minimal Safari test

Once the driver is connected, drive Safari the same way you would locally. The example below opens Hacker News, switches into the WebView context so CSS selectors work, and clicks the "More" link:

```ts
// Tell the open Safari tab to navigate. `executeScript` runs JS in the current page;
// `arguments[0]` is the first item we pass in the second argument.
await driver.executeScript(
  'window.location.assign(arguments[0])',
  ['https://news.ycombinator.com/'],
);

// Appium starts every session in the native context (NATIVE_APP). To use CSS or
// XPath against the page DOM, switch into a WEBVIEW context. There can be more
// than one, so we pick whichever WEBVIEW is currently available.
const contexts = await driver.getContexts();
const webview = contexts.find((c) => String(c).includes('WEBVIEW'));
if (!webview) throw new Error('WEBVIEW context not found');
await driver.switchContext(webview as string);

// Now selectors target the DOM. `driver.$` is webdriverio's element lookup.
await driver.$('a.morelink').click();

// End the session so WDA reclaims its state. The instance keeps running
// (and billing) until you delete it or its inactivity timeout fires.
await driver.deleteSession();
```

For a native-app session, install the app first (either at instance create through `initialAssets` or after boot through `installApp`), drop `browserName`, and add `appium:bundleId`:

```ts
await ios.installApp('https://example.com/builds/MyApp.app.zip');

const driver = await remote({
  /* ... host/port/path as above ... */
  capabilities: {
    platformName: 'iOS',
    'appium:automationName': '@limrun/xcuitest',
    'appium:bundleId': 'com.example.MyApp',
    'appium:limInstanceApiUrl': instance.status.apiUrl,
    'appium:limInstanceToken': instance.status.token,
    'appium:noReset': true,
  },
});

await driver.$('~startButton').click();   // accessibility id locator
```

The full runnable example is at [`typescript-sdk/examples/appium-ios`](https://github.com/limrun-inc/typescript-sdk/tree/main/examples/appium-ios).

### What differs from a local simulator

Most commands, including `mobile: listApps`, `mobile: setPermission`, `mobile: clearKeychains`, screen recording, file push and pull, and the `syslog` log, run on the instance and behave as they do locally. A few don't:

- `appium:fullReset` fails at session start, because it erases the simulator. Create a new instance when you need a clean simulator.
- Commands that boot, shut down, or erase the simulator fail with a `... is not supported on Limrun simulators` error. The instance owns the simulator's lifecycle.
- Setting the `notifications` permission restarts SpringBoard, which terminates every running app, WDA included. Relaunch WDA as shown in [Make sure WDA is running](#make-sure-wda-is-running) before the next command.
- `mobile: getPermission` can't read the `notifications` status.

## Run an Android test

Android is simpler: open an ADB tunnel, then use any upstream Appium driver. UiAutomator2, Espresso, and Flutter drivers all work unchanged.

### Open the ADB tunnel

Create an emulator and open an ADB tunnel to it. The CLI does both in one step; the SDKs open the tunnel after the create call returns:

```bash CLI
# `create` waits for the instance to be ready and opens an ADB tunnel by default.
# `--no-connect` skips the tunnel; `connect` opens one against an existing instance.
lim android create
# The tunnel keeps running in the background.
adb devices
# 127.0.0.1:<port>  device   ← port is chosen at runtime, e.g. 127.0.0.1:53412
```

```ts TypeScript
import { Limrun, createInstanceClient } from '@limrun/api';

const limrun = new Limrun({ apiKey: process.env.LIM_API_KEY });

const instance = await limrun.androidInstances.create({ wait: true });

const client = await createInstanceClient({
  apiUrl: instance.status.apiUrl!,
  adbUrl: instance.status.adbWebSocketUrl!,
  token: instance.status.token!, // absent for read-only API keys and viewer seats
});

// After this, `adb devices` sees the emulator and Appium can attach.
const { address, close } = await client.startAdbTunnel();
console.log(`adb connected on ${address.address}:${address.port}`);
// `close()` tears down the tunnel when your tests finish.
```

```go Go
import (
    "context"
    "log"
    "os"

    limrun "github.com/limrun-inc/go-sdk"
    "github.com/limrun-inc/go-sdk/option"
    "github.com/limrun-inc/go-sdk/packages/param"
    "github.com/limrun-inc/go-sdk/tunnel"
)

lim := limrun.NewClient(option.WithAPIKey(os.Getenv("LIM_API_KEY")))

instance, err := lim.AndroidInstances.New(context.TODO(), limrun.AndroidInstanceNewParams{
    Wait: param.NewOpt(true),
})
if err != nil { panic(err) }

// After this, `adb devices` sees the emulator and Appium can attach.
t, err := tunnel.NewADB(instance.Status.AdbWebSocketURL, instance.Status.Token)
if err != nil { panic(err) }
if err := t.Start(); err != nil { panic(err) }
defer t.Close()
log.Printf("adb connected on %s", t.Addr())
```

From Appium's side, the emulator is indistinguishable from a USB-attached device.

### Install Appium

```bash
npm i --location=global appium
appium driver install uiautomator2     # or espresso, flutter, etc.
appium
```

### Android capabilities

```ts TypeScript
import { remote } from 'webdriverio';

const driver = await remote({
  hostname: '127.0.0.1',
  port: 4723,
  path: '/',
  capabilities: {
    platformName: 'Android',
    'appium:automationName': 'UiAutomator2',
    'appium:udid': '127.0.0.1:<port>',         // copy from `adb devices`
    'appium:appPackage': 'com.example.app',
    'appium:appActivity': '.MainActivity',
  },
});
```

```python Python
from appium import webdriver
from appium.options.common import AppiumOptions

opts = AppiumOptions()
opts.set_capability('platformName', 'Android')
opts.set_capability('appium:automationName', 'UiAutomator2')
opts.set_capability('appium:udid', '127.0.0.1:<port>')  # copy from `adb devices`
opts.set_capability('appium:appPackage', 'com.example.app')
opts.set_capability('appium:appActivity', '.MainActivity')

driver = webdriver.Remote('http://127.0.0.1:4723', options=opts)
```

There are no Limrun-specific capabilities for Android. The tunnel makes the device local, so any capability documented for the upstream UiAutomator2 driver works as-is.

To install an APK before the session, push it through the tunnel like a normal local device:

```bash
adb -s 127.0.0.1:<port> install ./app-debug.apk
```

Or pre-install it at instance creation with `initialAssets`. See [Run an emulator](/android/run-emulator) for the create flow.

## Run from a Linux CI runner

Neither iOS nor Android automation needs a macOS host. The Mac lives on Limrun's side. A standard `ubuntu-latest` GitHub Actions job is enough.

```yaml title=".github/workflows/appium-ios.yml"
name: Appium iOS
on: [push, pull_request]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - uses: actions/setup-node@v4
        with:
          node-version: '22'

      - name: Install Appium and driver
        run: |
          npm i -g appium@3
          # Pin a specific `-lim.N`. See npmjs.com/package/@limrun/appium-xcuitest-driver for the latest.
          appium driver install --source npm @limrun/appium-xcuitest-driver@12.22.8-lim.1

      - name: Start Appium
        run: appium --log-level error &

      - name: Run tests
        env:
          LIM_API_KEY: ${{ secrets.LIM_API_KEY }}
        run: npm test
```

For Android, replace the `Install Appium and driver` step above with the upstream UiAutomator2 driver and make sure `adb` is on the runner's PATH (the GitHub-hosted `ubuntu-latest` image ships it under `$ANDROID_HOME/platform-tools/`):

```yaml
      - name: Install Appium and driver
        run: |
          npm i -g appium
          appium driver install uiautomator2
          echo "$ANDROID_HOME/platform-tools" >> $GITHUB_PATH
```

The CI runner doesn't need Xcode, the iOS SDK, or a local Android emulator. For iOS it needs Node, Appium, and `LIM_API_KEY`. For Android, add `adb` on the PATH (Appium's UiAutomator2 driver shells out to it, regardless of whether you open the tunnel through the CLI or `startAdbTunnel`).

:::note
  The job above creates instances from your test code, so label them there, for example `metadata: { labels: { session: process.env.GITHUB_RUN_ID! } }`, and delete them in your suite's teardown (such as `afterAll`), including on failure. Inactivity timeouts handle the rest if a job crashes. Listing and deleting by label is covered in [Run a simulator](/ios/run-simulator#reuse-and-clean-up) and [Run an emulator](/android/run-emulator#delete-the-emulator).
:::

## Troubleshooting

**`Error: socket hang up` on session create**

WDA isn't responding. Request `/status` on port 8100 (`targetHttpPortUrlPrefix` followed by `8100`) with `Authorization: Bearer ${instance.status.token}`; if it 502s, relaunch WDA via `simctl launch booted com.facebook.WebDriverAgentRunner.xctrunner`. Long-running suites should do this check before every session.

**`A new session could not be created` with `automationName: XCUITest`**

You're running upstream `xcuitest`, not the fork. Confirm with `appium driver list --installed`. The Limrun driver appears as `@limrun/xcuitest`, and `appium:automationName` must match exactly.

**WebView context isn't visible on iOS**

Safari debugging is proxied through the fork; without it, `getContexts()` only returns `NATIVE_APP`. Make sure `appium:limInstanceApiUrl` and `appium:limInstanceToken` are set so the driver can open the Safari socket tunnel.

**`adb devices` shows `offline` after a few minutes**

The tunnel was idle long enough for the WebSocket to close. The SDK auto-reconnects; if you used `lim android connect` and it exited, restart it. Raising the instance's `inactivityTimeout` also helps for long suites.

## Next steps

**[Run a simulator](/ios/run-simulator)**

Create, configure, and drive iOS simulators: the control surface Appium sits on.

**[Run an emulator](/android/run-emulator)**

ADB tunnel, instance configuration, and the Android device client.

**[Playwright](/testing/playwright)**

Drive Chrome on Android emulators over CDP.

**[Asset Storage](/platform/asset-storage)**

Store the WebDriverAgent bundle and your builds once instead of downloading them on every job.
