ADVERTISEMENT

How to Set Up Android Automation Testing on Mac

How to Set Up Android Automation Testing on Mac

Android automation also introduces the side of technological innovation to everyone’s life: a functional aspect for app development. Testers can skip the tedious task of manually checking each screen and leverage automated checks to review app performance, identify problems, and enhance app reliability. This tutorial will take you from configuring the emulator to running the first passing test on the Mac. It is created to be as accessible as possible to newcomers, and as clearly and concisely written as a reference for experienced testers. By the end, you will run a real automated test against an Android emulator for iOS.

What Android Automation Testing Is and Why It Matters

In Android automation testing, driving means you control your app with code, instead of handling it manually. A script is used to start the app, manipulate elements, and return a result. It is able to detect regressions at an early and standardized stage for a variety of devices and OS versions. Weekly shippers should take the easiest route to maintain an acceptable level of quality. There are some fundamental ways of covering mobile with automation testing platforms. Everyone has a compromise while providing speed, realism, and upkeep. Understanding them enables you to select the appropriate hybrid for your app.

  • Emulators and simulators: virtual devices that run on your machine, cheap and fast for early functional checks.
  • Real device testing: physical phones that expose sensor, gesture, and hardware behavior that emulators miss.
  • Native framework drivers: tools like Espresso and UI Automator that run inside the Android process for speed.
  • Cross-platform frameworks: tools like Appium that reuse one test script across Android and iOS.
  • Cloud device grids: hosted device fleets that run many tests in parallel for broad coverage.

This guide will focus on the Appium/UiAutomator2 driver. It is open source, multilingual, and the most popular framework for automation of Android apps currently. One of the frequently asked questions is when to go about it automatically. Use automation for repetitive and stable processes like login, checkout, and navigation. Do not use manual exploratory checks and one-off checks. This division provides maximum use for the time you put in, and provides a maintainable suite.

The table below compares the main approaches so that you can match each one to a goal:

ApproachBest forMain tradeoff
EmulatorsFast, low-cost functional checksNo real sensors or hardware behavior.
Real devicesProduction-accurate validationHigher cost to own and maintain.
Native driversFast in-process Android testsAndroid only, less reuse across platforms.
Cross-platformOne script for Android and iOSSlightly slower than native drivers.
Cloud gridsBroad parallel coverage at scaleRequires a hosted platform.

Prerequisites and Setup

Before writing tests, your Mac needs a working Android and Appium toolchain, along with the right automated testing tools to support your setup. If you’re working with cross-platform frameworks, this environment is also crucial for ensuring test consistency across devices, ensuring that the testing process occurs seamlessly and uniformly from one device to another. There are slight differences between Mac computers with Apple Silicon and Mac computers with Intel processors. Press the Apple button and then pick About This Mac. Cache it now, as it is what the emulator image you’re going to install!

You will need the following installed first:

  • Java JDK 17 or newer: Android SDK tools and Appium drivers need a current JDK. JDK 17 LTS is a safe default.
  • Node.js 18 or newer: Appium installs through npm, so Node must be present.
  • Android Studio: the simplest way to get the SDK, platform tools, and emulator in one install.
  • Appium 2.x or later: the automation server that drives the device.

If you prefer the command line, install Android Studio with Homebrew, then open it once to finish the SDK and emulator setup:

brew install –cask android-studio

open -a “Android Studio”

Verify each tool before moving on. These commands should each print a version, not an error:

java -version

node -v

adb –version

Install Appium globally with npm, then add the Android driver:

npm install -g appium

appium driver install uiautomator2

appium -v

Appium 3.2.2 was the latest stable release as of early 2026. Appium 2.x remains widely used and is fully supported. In Appium 2 and later, the UiAutomator2 driver is a separate install, which the command above handles.

Next, point your shell at the Android SDK. Add these lines to your ~/.zshrc file:

export ANDROID_HOME=$HOME/Library/Android/sdk

export PATH=$PATH:$ANDROID_HOME/platform-tools

export PATH=$PATH:$ANDROID_HOME/emulator

export PATH=$PATH:$ANDROID_HOME/cmdline-tools/latest/bin

Then run source ~/.zshrc to apply them. The default SDK path on a Mac is ~/Library/Android/sdk after an Android Studio install.

How to Set Up an Android Emulator on Mac

Mac Android Emulator provides a virtual device for you to experiment with. The important thing to understand is that it is necessary to have a matching system image with your processor. Images of arm64-v8a type are required for Apple Silicon Macs (M1 to M4). The x86_64 images are used for Intel Macs. The no. 1 most frequent setup error is a mismatch.

Follow these steps to create and launch an emulator from the command line:

  1. List available images. Run sdkmanager –list | grep system-images to see options.
  2. Install an Android 15 image. Pick the build that matches your chip:

# Apple Silicon (M-series):

sdkmanager “system-images;android-35;google_apis;arm64-v8a”

# Intel Macs:

sdkmanager “system-images;android-35;google_apis;x86_64”

  1. Create the virtual device. Name it and bind it to the image and a device profile:

avdmanager create avd -n pixel8_api35 \

  -k “system-images;android-35;google_apis;arm64-v8a” \

  –device “pixel_8”

  1. Launch the emulator. Boot the device you just created:

emulator -avd pixel8_api35

Android 15 is targeting API level 35, which is the latest version of the Play Store target by early 2026. Anytime you are running the emulator, just execute emulator -list-avds to list the available devices again.  Cold start of the system image causes the first boot to be slow. It is also quicker for later launches, which are reusing the stored snapshot. Make sure that the device has completed the boot process before performing any tests:

adb wait-for-device shell getprop sys.boot_completed

If the system is ready, it will return 1. If there are no results, the device is still booting: wait and try again. The performance of an emulator and how fast it can run depends on the availability of hardware acceleration. The emulator automatically emulates native virtualization for Apple Silicon; no extra setup is required. Ensure that the emulator and Hypervisor framework are kept up to date on Intel Macs to run smoothly.

How to Write Your First Android Automation Test

With the emulator running, you can write a test that drives it and see automation in action. This example demonstrates Appium on macOS using Python with the Appium client, though the same capabilities are available in Java and JavaScript. The script uses Appium to engage with the app, open the Settings app, and check a screen element. Compact and essentially purpose-built, it provides a real-life example of the technology now powering the modern software development process and shows how a few lines of code do so much more than interact with the user. 

Install the Appium Python client first:

pip install Appium-Python-Client

Then create a file named first_test.py with these capabilities:

from appium import webdriver

from appium.options.android import UiAutomator2Options

from appium.webdriver.common.appiumby import AppiumBy

options = UiAutomator2Options()

options.platform_name = “Android”

options.device_name = “pixel8_api35”

options.app_package = “com.android.settings”

options.app_activity = “.Settings”

driver = webdriver.Remote(“http://127.0.0.1:4723”, options=options)

el = driver.find_element(

    AppiumBy.XPATH,

    “//android.widget.TextView[@text=’Network & internet’]”)

assert el.is_displayed()

driver.quit()

The options class is used by the Automation driver, which is automatically set to UiAutomator2 for you. Appium 2: Requires driver to be explicitly named; it is the answers object that takes care of that. By default, the server address doesn’t contain the /wd/hub because that is not the naming convention that was used in Appium 2.0. Your tests are determined by the locators you choose. Avoid using brittle xpaths, instead using a resource-id or accessibility ID. We’re using XPath only to prevent requiring a stable ID in the Settings element. When creating an app, include testID style identifiers for crucial elements at the outset. To be able to see the package and activity for your own app, on the emulator open your app and click the button for “run.”

adb shell dumpsys window | grep -i mCurrentFocus

The output shows the foreground package and activity. Copy those values into app_package and app_activity in your test.

How to Run and Verify the Test

Taking this test lets you know that the whole of your toolchain is running correctly from end to end. You can use this approach, starting the Appium server and running the script in different terminals. A script passed, and element present indicates a passing test. This is the piece of evidence that you passed: that emulator, server and any driver were aligned with each other. For teams following a complete QA guide, this successful test also provides a practical checkpoint before expanding automation to more devices and test scenarios.

Start the Appium server:

appium

Confirm the emulator is connected:

adb devices

Then run the test:

python first_test.py

A successful run shows no assertion errors and a clean exit. Check these signals to confirm it worked:

  • adb devices lists your emulator: the device shows as “device”, not “offline”.
  • Appium logs show a session: the server prints a new session ID when the script connects.
  • The script exits cleanly: the assertion passed and driver.quit() closed the session.

Common Issues and How to Fix Them

Most Android automation failures trace back to a few recurring causes. The table below maps each symptom to its likely cause and a fix. Work through them top to bottom when a run breaks.

ProblemLikely causeFix
emulator: command not foundSDK paths missing from PATHAdd emulator and platform-tools to PATH, then reload the shell.
No connected device foundEmulator not started or adb offlineLaunch the AVD, then run adb kill-server and adb start-server.
Image architecture errorarm64 image on Intel, or x86_64 on Apple SiliconReinstall the system image that matches your chip.
Session fails to startUiAutomator2 driver not installedRun appium driver install uiautomator2.

Why Do Tests Pass on Emulators but Fail on Devices?

Since emulators are hardcoded in and cannot replicate real equipment, sensor changes or quirks. Therefore, a test might be successful on your Mac, but of course not in production. As a lot of applications grow, locator changes also make emulator-based suites flaky. It’s here that a real device cloud comes in handy. TestMu AI (formerly LambdaTest) provides a Real Device Cloud with 10,000+ real Android and iOS devices. The tests you ran on an Android emulator on your Mac can run unchanged on real hardware, after you point them at the cloud grid endpoint. Self-healing tests are added using its KaneAI agent when your UI changes. It reduces the infuriating maintenance which created Android automation flaky in the long term.

Next Steps

You’ve now got a working Android automation on Mac. From this, take a few steps next to the zones and increase coverage while decreasing flakiness. Improve test suite with more test cases, parameterize device capabilities, and integrate into CI. Every step is a progression from a single check to working regression protection. With the growth in complexity of mobile apps, efficient testing is also another form of cutting-edge technology that is propelling development. Local emulators can eventually become a bottleneck as test suites expand. 

To solve this, HyperExecute, TestMu’s orchestration engine, can execute big suites concurrently and shorten the execution period. In 2026, LambdaTest (now TestMu AI) was also named a strategic partner of Appium. It is also useful for those existing Appium scripts that will need to be ported across without rewriting, and can be of aid to dev teams and help extend their mobile test coverage without starting from scratch. It also supports a more efficient Android development process, allowing teams to scale testing alongside application growth while keeping existing workflows intact.

Share or leave a comment

Conversations (0)

Replying to comment

No comments yet.