How to Set Up Appium with Android Studio for Mobile App Testing

Wavda Aniva
5 min readApr 15, 2023

--

As the use of mobile applications grows, so does the demand for mobile app testing. Because of its flexibility, support for multiple programming languages, and cross-platform capabilities, Appium, an open-source tool, is widely used for mobile app testing.

This article will guide you through setting up Android Studio and Appium for mobile app testing, whether you are a seasoned developer, tester, or just getting started. Now let’s get going!

Pre-requisites

  1. Node.js installed: https://nodejs.org/en/download
  2. Android Studio installed: https://developer.android.com/studio/install

Step 1: Install JDK

1. Go to the Oracle website and download the latest JDK installer for your operating system.

2. Run the installer and follow the prompts to complete the installation.

3. Set the JAVA_HOME environment variable to the JDK installation directory after installation. For example, if you installed JDK in C:\Program Files\Java\jdk-19, set JAVA_HOME to C:\Program Files\Java\jdk-19.

4. Add the JDK bin directory to your system’s PATH environment variable. For example, if you installed JDK in C:\Program Files\Java\jdk-19, add C:\Program Files\Java\jdk-19\bin to the PATH environment variable.

Step 2: Setup Emulator with Android Studio

1. Install Android SDK: Once Android Studio is installed, open it and follow the setup wizard to install the Android SDK (Software Development Kit) through More Actions > SDK Manager. This is a set of tools that enable you to run the emulator.

Install the Android version that you’d like to install on your emulator under SDK Platform.

Install SDK Tools such as Intel processor with Intel HAXM (for faster emulation performance)

SDK Tools

4. Add the Android SDK directory to your system’s ANDROID_HOME environment variable. For example, if the Android SDK Location in Android Studio is C:\Users\Administrator\AppData\Local\Android\Sdk, add C:\Users\Administrator\AppData\Local\Android\Sdk to the ANDROID_HOME environment variable.

5. An Android Virtual Device (AVD) is an emulator that allows you to test your apps without using a physical device. To set up an AVD, open Android Studio, click on the More Actions > Virtual Device Manager button, and proceed with the virtual device creation by selecting the hardware and system image. You can also refer to this document for a more detailed guideline https://developer.android.com/studio/run/managing-avds.

6. Run the emulator: Click on the “Run” button to start the AVD on the Virtual Device Manager page.

Step 3: Setup Appium

1. Install Appium: Open a terminal window (or command prompt on Windows) and run the following command to install Appium using NPM. This will install the latest version of Appium globally on your computer.

npm install -g appium

2. Install Appium Doctor: Appium Doctor is a command-line tool that helps you diagnose and fix common Appium installation issues. To install Appium Doctor, run the following command:

npm install -g appium-doctor

3. Check Appium installation: Run the following command to check that Appium is installed and running correctly. This should output the version of Appium that you just installed.

appium --version

4. Run Appium Doctor: The following command will perform a number of tests to ensure that all prerequisites and dependencies are met before running Appium. It helps in spotting potential issues that can arise when running Appium and provides instructions on how to fix them.

appium doctor

Step 4: Setup Appium Inspector

  1. Download and install Appium Desktop from the official website (https://github.com/appium/appium-desktop/releases). Choose the appropriate version for your operating system.
  2. Once the installation is complete, open Appium Inspector.
  3. Click on the “Start Inspector Session” button located in the top left corner of the window.
  4. In the “Desired Capabilities” section, enter the capabilities required to connect to the device. Note: The values for “deviceName”, “appPackage”, and “appActivity” may vary depending on the device and the application you are testing. For example, if you want to connect to an Android emulator, enter the following:
{
"platformName": "Android",
"deviceName": "emulator-5554",
"appPackage": "com.android.settings",
"appActivity": ".Settings"
}

For other desired capabilities for your emulator, you can refer to: https://appium.io/docs/en/writing-running-appium/caps/

Step 5: Getting Element Locators from Your App

1. Open a new terminal window and run the following command to start the Appium server. This will start the Appium server on the default port (4723).

appium

2. Start your device emulator in Android Studio.

3. Click on the “Start Session” button on Appium Inspector

After clicking on “Start Session", you will see a screen showing the device’s screen and a tree of elements. The Appium Inspector will display the element’s properties, including its ID, text, class, and more attributes. You can also interact with the device by tapping, swiping, or scrolling using the controls located on the highlighted menus in the screenshot below.

Step 6: Write and Run Your Test

Use your preferred programming language and testing framework to create a test script. Specify the desired capabilities for your test in your script, such as device type, platform version, and app path.

Run the test script through your preferred testing framework once it’s completed. Connect to the Appium server and run the specified test on the connected device or emulator.

We’ll discuss more detail on writing and running test scripts using Appium in the upcoming article: https://link.medium.com/0JuXh7nv0yb

--

--

Wavda Aniva
Wavda Aniva

Written by Wavda Aniva

A curious potato exploring new things on software quality

Responses (1)