qa-testing

How to Set Up and Run Appium for Android: A Step-by-Step Guide

Let's take a look at how to set up and run an Appium environment.

In this guide, we will focus on the Android platform.


[Prerequisites]

  • PC (Windows or MacBook; this guide is based on macOS)
  • Android device and a USB cable to connect it to your PC
  • Test App: If you have an APK file for development or testing, use that. Otherwise, we will use the APIDemos.apk file provided by Google.


[Environment Setup]

1. Install Java

Type java -version in your terminal/command prompt. If the version information is displayed, it is installed correctly. I won't go into detail here, but please ensure you've set up your Path after installation via Google search. In my case (macOS), it was installed at: /Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home. This may vary depending on your OS or version. Note that MacBooks often come with Java pre-installed.


2. Install Android SDK (via Android Studio)

Android Studio is an Integrated Development Environment (IDE) for Android. You can install the full IDE (which includes the SDK) or just the SDK separately. For this guide, I installed the full Android Studio. Please complete the installation, SDK setup, and Path configuration using online resources. My installation path was: /Users/YOURNAME/Library/Android/sdk


3. Download and Install Appium

Appium has many versions, which can be confusing at first. We will use the version that provides a GUI.

Download link: https://github.com/appium/appium-desktop/releases/latest

As of July 21, 2020, the latest version is 1.17-1. Download the version compatible with your OS. While there are versions like Appium Studio or command-line versions, we'll use the GUI version for convenience.


4. Launching Appium

Appium Start Screen

If you see the screen above, you're 50% of the way there! This guide is based on version 1.17-1 for Mac. Click the Edit Configurations button shown in the photo.


5. Configuration

Appium Configuration

You need to set the ANDROID_HOME and JAVA_HOME paths. Enter the paths you verified in steps 1 and 2. Once finished, click Save and Restart.


6. Starting the Server

Return to the main screen and click the Start Server button.

Server Running

You should see a "The server is running" message. If you see error messages, try searching for the specific error code to fix it.


7. Connect Android Device

Connect your testing device to your PC via USB. On your device, make sure to allow device access (MTP connection mode).


8. Check Connection and Get Device Name

Check the connection status by typing adb devices in your terminal. In my case, it showed:

06157df67002561b device

The alphanumeric string at the beginning is your Device Name.


9. Start Inspector Session

Go back to the Appium server window and click the Magnifying Glass icon. You might see a blank screen—many people give up here! Don't quit yet; follow the next step.


10. Configure JSON Representation

JSON Configuration

Click the pencil icon in the JSON Representation section and add the following (then make sure to save it):

{
  "platformName": "Android",
  "platformVersion": "7.0",
  "app": "/Users/YOURNAME/Downloads/APIdemos.apk",
  "automationName": "Appium",
  "deviceName": "06157df67002561b"
}

These fields are essential. Enter your phone's OS version (I used 7.0), the file path to your APK, and the device name you found via the adb devices command.


11. Start Session

Click Start Session. After a short wait, you should see a screen like this:

Successful Session

If the app screen from your phone appears on your PC, you've succeeded! In the next post, we’ll look at controls and elements for Appium automation.