Appium · Test automation · Mobile · QA

Appium Real-Device Testing: From First Session to a Device Farm

How to set up Appium tests on real Android and iOS devices, why emulators are not enough, and how to run tests reliably across a device farm.

Sander Yazıcıoğlu Published: 4 min read Türkçe oku

Emulators are a great way to start testing a mobile app, but your users don't run emulators. Battery savers, vendor-customised Android skins, real network conditions and hardware such as cameras and biometrics only show their true behaviour on real devices. This article collects what I learned building a real-device testing platform at LiveTesting, as a practical guide to a stable Appium setup.

What Appium is, and why it is still the default

Appium automates mobile apps over the WebDriver protocol. Its biggest strength is that it is language-agnostic: you can write tests in JavaScript, Java, Python or C#, and run the same test on Android and iOS.

Since Appium 2 the server is only an orchestrator; platform support ships as separate drivers:

  • UiAutomator2: the default Android driver.
  • XCUITest: the iOS driver built on Apple's XCTest.
  • Espresso: a faster Android option that is more tightly coupled to the app.
npm install -g appium
appium driver install uiautomator2
appium driver install xcuitest
appium driver list --installed

This modular design makes upgrades easier: you can update the Android driver without replacing the whole server.

Emulators or real devices?

They complement each other. A split that works well in practice:

CriterionEmulator / simulatorReal device
Speed and costCheap, easy to paralleliseHardware and maintenance cost
Hardware (camera, NFC, biometrics)Limited or mockedReal behaviour
Vendor skins (Samsung, Xiaomi)Not presentPresent
Performance and batteryDepends on the host machineWhat users actually get
Best forFast feedback on every commitPre-release and critical flows

My recommendation: run unit and fast UI tests on emulators for every commit, and run critical user journeys (sign-in, payment, notification permissions) on real devices nightly or before a release.

Your first real-device session

On Android, enable developer options and USB debugging. If adb devices lists the phone, Appium can drive it. A minimal WebdriverIO session:

import { remote } from 'webdriverio';

const driver = await remote({
  hostname: '127.0.0.1',
  port: 4723,
  capabilities: {
    platformName: 'Android',
    'appium:automationName': 'UiAutomator2',
    'appium:udid': 'R58N12ABCDE',
    'appium:app': '/builds/app-release.apk',
    'appium:newCommandTimeout': 120,
    'appium:autoGrantPermissions': true
  }
});

await driver.$('~login-button').click();
await driver.deleteSession();

A few details matter a lot:

  • Always set udid. With several devices attached, never rely on Appium picking "the first one".
  • Tune newCommandTimeout. Too low and long waits kill the session; too high and a crashed test locks a device for minutes.
  • On real iOS devices, WebDriverAgent must be signed. That step is usually the slowest part of the first setup.

Selectors that don't break

The number one enemy of real-device suites is flaky tests, and most flakiness comes from bad selectors and fixed sleeps.

  1. Use accessibility ids. contentDescription on Android, accessibilityIdentifier on iOS. They improve accessibility and let one selector work on both platforms.
  2. Avoid long XPath expressions. Something like //android.widget.LinearLayout[2]/... breaks on the smallest layout change and is slow.
  3. Wait for conditions, not for time. Wait until the element is displayed or clickable:
const button = await driver.$('~pay-now');
await button.waitForDisplayed({ timeout: 15000 });
await button.click();
  1. Keep tests independent. Each test prepares its own data. Relying on state left by a previous test causes random failures once you run in parallel.

From one phone to a device farm

A setup that starts with a few phones grows quickly. These are the problems we hit while building a device farm, and how to solve them.

Reservation and isolation

Two sessions on the same device at once will both fail. Devices need a lock or reservation layer: the device is locked when a test starts and released when the session ends or times out. Every lock needs an expiry, or a crashed test holds the device forever.

Port collisions

Each parallel Android session needs its own systemPort, and each iOS session its own wdaLocalPort. Assigning fixed ports per device removes a whole class of random failures.

Device health

Real devices overheat, run out of battery, pop up system-update dialogs and fill their storage. A short health check before each session (battery level, free space, lock screen) stops tests from failing because of the device rather than the app.

Live view and recordings

The fastest way to understand a failed test is to see the screen at that moment. Screenshots, video and device logs (logcat, iOS syslog) should be attached to every session automatically. For a live screen stream you can use WebSocket and WebRTC; I cover that in streaming a device screen to the browser with WebRTC.

Wiring it into CI/CD

Two rules made real-device tests in the pipeline much easier:

  • Split tests into tiers. A short smoke suite on every pull request, the full regression suite nightly.
  • Produce machine-readable results. JUnit XML or Allure reports let you see trends per device. If the same test always fails on the same device, the device is probably the problem.

Common mistakes

  • Uninstalling and reinstalling the app before every test: safe but very slow. Choose noReset and fullReset deliberately.
  • Dismissing permission dialogs by hand: autoGrantPermissions on Android and autoAcceptAlerts on iOS cover most cases.
  • Ignoring the network: real users are on 4G, in lifts and on the metro. Run critical flows with a slow network profile too.

Conclusion

Real-device automation with Appium takes more setup than emulators, but it pays back far more. Stable selectors, condition-based waits, device locking and health checks remove most flaky failures. If you also need to test performance under load, see the load testing guide.

All articles →