If you’ve ever tried to manually test a new app feature across five different screen sizes and two operating systems, you know the pain. It’s tedious, error-prone, and simply doesn’t scale. That’s why I’ve spent the last few years leaning heavily into cross-platform frameworks. In this appium tutorial for mobile automation, I’m going to show you how to set up a professional-grade environment to automate your mobile apps without needing to write separate code for iOS and Android.

Appium is essentially the ‘Selenium of mobile.’ It allows you to write tests in languages you already know—like Python, Java, or JavaScript—and execute them on real devices or emulators. Before we dive into the code, remember that automation is only as good as your strategy. If you’re scaling a larger project, I highly recommend reviewing automated mobile app testing best practices to ensure you aren’t just automating bad processes.

Prerequisites: Preparing Your Machine

Setting up Appium is often the hardest part of the process. In my experience, 90% of beginners get stuck here because of environment variables. To follow this tutorial, you’ll need:

Ensure your JAVA_HOME and ANDROID_HOME environment variables are correctly mapped in your .zshrc or .bash_profile. If these aren’t set, Appium won’t be able to locate your devices.

Step-by-Step Appium Setup and First Test

Step 1: Install Appium Server

Open your terminal and run the following command to install the Appium server globally:

npm install -g appium

Once installed, start the server by simply typing appium. You should see the server listening on http://0.0.0.0:4723.

Step 2: Install the Appium Inspector

You can’t write tests if you don’t know the IDs of your UI elements. Appium Inspector is a separate desktop app that lets you ‘inspect’ your mobile app’s DOM. As shown in the image below, this is where you’ll find your XPaths and Accessibility IDs.

Appium Inspector interface showing a mobile app screen with highlighted UI elements and their corresponding properties
Appium Inspector interface showing a mobile app screen with highlighted UI elements and their corresponding properties

Step 3: Define Your Desired Capabilities

Capabilities tell the Appium server which device and OS you want to target. Here is a standard configuration for an Android device using Python:

from appium import webdriver

desired_caps = {
    'platformName': 'Android',
    'deviceName': 'Android Emulator',
    'appPackage': 'com.example.myapp',
    'appActivity': '.MainActivity',
    'automationName': 'UiAutomator2',
    'noReset': True
}

Step 4: Write Your First Test Script

Let’s write a simple script that opens the app and clicks a login button. I’ve used the Python client here for readability:

from appium import webdriver
from appium.webdriver.common.appiumby import AppiumBy

driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)

# Find element by Accessibility ID
login_button = driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value='login_btn')
login_button.click()

# Verify result
welcome_text = driver.find_element(by=AppiumBy.ID, value='com.example.myapp:id/welcome_msg')
assert 'Welcome' in welcome_text.text

driver.quit()

Pro Tips for Stable Mobile Tests

Mobile automation is notoriously flaky due to network latency and animation delays. Here is how I handle it in production:

If you are integrating these tests into a larger system, such as a cloud-native environment, you might want to explore test automation for microservices architecture to see how end-to-end mobile tests fit into the broader pipeline.

Troubleshooting Common Appium Errors

When things go wrong (and they will), check these three things first:

  1. SessionNotCreatedException: Usually means your Appium version doesn’t match the driver version. Run appium driver install uiautomator2 to update.
  2. ElementNotInteractable: The element is in the DOM but hidden by a keyboard or a loading spinner. Use a wait command or driver.hide_keyboard().
  3. Unable to find device: Run adb devices (Android) or idevice_id -l (iOS) to ensure your machine actually sees the hardware.

What’s Next?

Now that you have a basic script running, the next step is scaling. I recommend looking into BrowserStack or Sauce Labs if you don’t have access to a physical device lab. Additionally, integrating your Appium tests into a GitHub Actions pipeline will allow you to run regression tests on every pull request.

Ready to level up your QA game? Subscribe to my newsletter for more deep dives into automation tools and productivity hacks.