ScreenshotNeo

BlogGuides

Mobile Test Automation with Appium: An Introduction

Learn how Appium’s client-server model and platform drivers work, then set up Android UiAutomator2 and write a first runnable Python test.

By the ScreenshotNeo team4 October 202610 min read

Appium lets a test script automate a mobile app through a common WebDriver-based API. An Appium server receives HTTP requests from a language client; an installed platform driver translates those requests into the automation system for Android or Apple platforms. For a first Android test, install Appium, the Android SDK and Java JDK, start an emulator or connect a USB-debuggable device, install the UiAutomator2 driver, and run a client script.

Appium is an automation server and extensible ecosystem, not a test runner. The driver and its platform stack determine which commands work and what setup is required. This guide follows the Android UiAutomator2 path because it is a direct beginner route in the official quickstart. Appium’s getting-started guide and UiAutomator2 setup guide cover the current setup flow.

1. What Appium is and how it works

Appium adopts the WebDriver API and protocol as a shared way for clients to request UI actions. The server itself does not know how to operate every platform. A separately installed driver maps supported commands to platform-specific automation technology. That means the same general client-server idea can apply across platforms, but command availability and behavior can differ.

  1. Test code: a script written with an Appium client library configures a session and sends commands such as finding an element or tapping it.
  2. Appium server: an HTTP process accepts those requests and routes them to a driver.
  3. Platform driver: the driver translates the request for the selected platform and app type.
  4. Target: an emulator, simulator, or physical device runs the app and responds to automation.

The client and server communicate over a network and can run on different computers. This supports local setups as well as hosted servers and devices. A test runner such as Python’s unittest can organize and report tests; Appium does not prescribe or include a particular test framework. See the Appium architecture introduction.

2. Choose a driver for the target

Pick a driver based on the operating system, app type, and driver maintenance status. Native, hybrid, and mobile web automation may have different requirements. Consult the live Appium driver catalog before committing to a driver; it distinguishes team-maintained drivers from other ecosystem entries.

Target Driver route Key consideration
Android UiAutomator2 or Espresso UiAutomator2 is the Android route used in this first-test walkthrough. Both have their own setup and behavior.
iOS-family platforms XCUITest The driver requires macOS. Follow its current documentation for Apple tooling, signing, simulator/device, and version requirements.
Other targets Use the driver catalog Coverage and stewardship vary; verify that the driver supports the needed app mode and is maintained.

Appium’s official catalog identifies UiAutomator2 as an Android driver and XCUITest for iOS, iPadOS, tvOS, and watchOS. The catalog also lists native, hybrid, and web modes for those drivers. Do not assume every WebDriver command is available or meaningful on every platform.

3. Prepare an Android automation environment

Prerequisites

  • Node.js and npm, to install and run the Appium server.
  • A Java JDK with JAVA_HOME configured.
  • Android SDK Platform and Platform-Tools, with ANDROID_HOME configured. Android Studio’s SDK Manager is one way to install them.
  • An Android Virtual Device (AVD) created with Android Studio, or a physical Android device with developer options and USB debugging enabled.
  • An Appium client library for the language used by the test.

Install and check Appium

npm install -g appium
appium --version

Install the UiAutomator2 driver separately, then have its doctor command check the host prerequisites:

appium driver install uiautomator2
appium driver doctor uiautomator2

The doctor command helps identify missing prerequisites; resolve any reported setup issues before debugging a test script. Appium’s CLI reference documents server and driver commands.

Start an emulator or connect a device

Start the AVD from Android Studio’s Device Manager, or connect the phone over USB and accept its debugging authorization prompt. Check that Android Debug Bridge sees the target:

adb devices

Continue when the intended device appears in the output. For multiple targets, note the device identifier; the session capabilities can select the intended target. A physical phone is optional for learning because an emulator is also supported by the setup guide.

Start the Appium server

appium

The default local server listens at http://localhost:4723. Keep this process running while the client script runs. If the server is on another machine, use a reachable host address in the client and ensure network access is permitted between client and server.

4. Write and run a first Android test in Python

The example opens the Android Settings app, finds its “Apps” item, taps it, and ends the session. It follows the shape of the official Appium Python test example. The Settings app is a convenient sample target; replace its package and activity with those for the app under test when automating your own app.

Install the Python client in the same environment that will run the script:

python -m pip install Appium-Python-Client

Save this as first_test.py:

from appium import webdriver
from appium.options.android import UiAutomator2Options
from appium.webdriver.common.appiumby import AppiumBy

options = UiAutomator2Options()
options.platform_name = "Android"
options.automation_name = "UiAutomator2"
options.app_package = "com.android.settings"
options.app_activity = ".Settings"

# For multiple connected Android targets, set the device identifier:
# options.udid = "YOUR_DEVICE_ID"

driver = webdriver.Remote("http://127.0.0.1:4723", options=options)
try:
    apps = driver.find_element(AppiumBy.ACCESSIBILITY_ID, "Apps")
    apps.click()
finally:
    driver.quit()

Run it while the emulator or device and Appium server are available:

python first_test.py

The client creates a session using capabilities, sends a locator and click command, and then asks the server to end the session. The finally block closes the session even if locating or clicking the element fails. If the Settings label or activity differs on the target image, inspect that device’s UI and update the example accordingly.

What the session options mean

  • platform_name identifies the platform as Android.
  • automation_name selects the installed UiAutomator2 automation driver.
  • app_package and app_activity tell Android which app entry point to launch.
  • udid optionally selects a particular connected device when more than one is available.

For a test that installs an APK, configure the app path using the capability supported by the selected driver and client version instead of package/activity launch details. Capability names and accepted values are driver-specific; check the driver documentation rather than copying options between platforms.

5. Adapt the first test to a real app

  1. Choose the app launch route. Use the app package and activity for an already installed app, or the driver’s app-file capability to install and launch an APK.
  2. Choose stable locators. Prefer accessibility identifiers or resource identifiers maintained for automation when the app exposes them. Text labels can change with localization or product copy.
  3. Assert an outcome. A useful test checks a visible state or resulting screen after the action, not merely that a click command returned.
  4. Close every session. Put driver.quit() in cleanup logic so failures do not leave sessions and app state behind.
  5. Run through a test framework when needed. Add setup, assertions, and reporting with a framework such as unittest; Appium is the automation endpoint, not the test runner.

For hybrid apps, the driver may expose native and web contexts. Context switching and web-specific locators depend on the app and driver setup, so first confirm that the chosen driver lists the required mode. The driver catalog is the place to verify current support.

6. Android setup checklist

  • Appium server installed and its version confirmed.
  • UiAutomator2 installed and its doctor check reviewed.
  • Java JDK installed; JAVA_HOME resolves correctly.
  • Android SDK Platform and Platform-Tools installed; ANDROID_HOME resolves correctly.
  • AVD running or USB-debuggable device authorized and visible in adb devices.
  • Appium server running at the URL used by the client.
  • Python client installed in the active Python environment.
  • Capabilities match the target device and app; the test always quits its session.

7. Platform and execution choices

Choice Use it when Check
Android emulator You want to learn or run a virtual Android target without a physical phone. AVD is started and visible to Android tooling.
Physical Android device You need to automate a real device target. Developer options, USB debugging, authorization, and device selection.
Apple platform The app targets iOS-family platforms. XCUITest setup requires macOS; consult its current docs for the full toolchain.
Remote server/device Client and device infrastructure are hosted separately. Network reachability, the provider’s supported capabilities, and its terms.

Appium’s architecture allows the server, drivers, and devices to be hosted remotely. The cited documentation establishes this architecture but does not endorse or compare specific cloud providers. Confirm provider capabilities and terms before selecting one.

8. Reliability, runtime, and cost considerations

Appium’s client-server design makes the server URL, device availability, and driver session part of the test’s operating environment. A failure can originate in the test, server, driver, platform tooling, or app. Preserve server logs and the failing command when diagnosing an issue, and make cleanup unconditional. The official material cited here does not provide performance benchmarks or a universal cost estimate, so runtime and infrastructure expense depend on the chosen target and execution environment.

  • Keep tests focused: smaller flows are easier to diagnose when a device or app state differs.
  • Make target selection explicit: with multiple devices, pass the intended identifier instead of relying on an implicit choice.
  • Account for device startup: the emulator or remote target must be ready before session creation.
  • Separate infrastructure from test logic: a client can talk to a remote server, but network availability and provider configuration then matter.
  • Estimate costs from actual hosting choices: Appium itself does not specify cloud-device prices or a required paid service.

9. Troubleshooting common first-run errors

Symptom Likely cause Fix
UiAutomator2 driver not found The server is installed but the separately managed driver is missing. Run appium driver install uiautomator2, then check with appium driver doctor uiautomator2.
Doctor reports missing Android or Java setup SDK/JDK components or environment variables are absent or point to the wrong location. Install Android SDK Platform and Platform-Tools plus a JDK; set ANDROID_HOME and JAVA_HOME in the environment used to start Appium.
No device is listed by adb devices The emulator is stopped, USB debugging is off, or the device has not authorized the host. Start the AVD or enable debugging and accept the authorization prompt; reconnect and check again.
Client cannot connect to Appium The server is not running, the URL/port is wrong, or client and server cannot reach each other. Start appium; use the correct server address and verify network access. For a local server, the example uses http://127.0.0.1:4723.
Session creation fails Capabilities do not match the installed driver, platform, device, or app launch route. Check server logs, confirm driver installation and device visibility, and use capabilities documented for the selected driver version.
App does not launch Package/activity values are wrong, app is absent, or the target image uses a different app entry point. Verify app identifiers on the target; use the correct installed-app launch details or the driver’s APK capability.
Element cannot be found Locator value differs, element is not yet present, or the app’s visible state is unexpected. Inspect the target UI and available accessibility/resource identifiers; ensure the expected screen has loaded before locating.
Command exists in one test but not another platform WebDriver API compatibility does not imply every command is implemented by every driver. Check the selected driver’s command and mode documentation; use a supported platform-specific approach where needed.
Session remains active after a test error Cleanup was skipped during exception handling. Call driver.quit() from a finally block.

10. Or skip the browser setup

Appium is for automating mobile apps. If your task is to capture a website screenshot for a test report, bug ticket, or agent workflow, ScreenshotNeo provides a website screenshot API and MCP server. One GET request can return PNG, JPEG, WebP, or PDF. See the ScreenshotNeo API documentation.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

The same API call from Python:

import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)

And from Node.js:

const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
  • Cookie banners are accepted and removed before capture, along with known consent platforms, newsletter popups, and chat widgets; each step can be turned off.
  • Bot checks, blank pages, timeouts, failed loads, and cache hits cost nothing; response headers identify the page verdict and billing status.
  • An MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents and MCP clients.
  • The free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000 screenshots.

Sign up free for 1,000 screenshots a month with no card.

11. Frequently asked questions

Does Appium require a particular test framework?

No. Appium provides the automation server and protocol; choose a framework supported by your language client to organize and report tests.

Can the Appium client run on a different machine from the phone?

Yes. The client sends HTTP requests to the Appium server, and the server and device can be hosted separately if the network and configuration allow it.

Do I need a physical Android phone to learn Appium?

No. The Android setup route supports an Android Virtual Device as well as a real device.

Can I use the same test commands on Android and iOS?

The shared WebDriver-based API gives a common foundation, but each driver implements platform behavior and command support. Verify the command and app mode against the selected driver.

Can Appium take screenshots of websites?

Appium can automate mobile web experiences through drivers that support that mode. For a website screenshot API call or an MCP screenshot tool, see ScreenshotNeo.

Sources