Appium Tutorial for Testing Android and iOS Mobile Apps

By Vijay

By Vijay

I'm Vijay, and I've been working on this blog for the past 20+ years! I’ve been in the IT industry for more than 20 years now. I completed my graduation in B.E. Computer Science from a reputed Pune university and then started my career in…

Learn about our editorial policies.
Updated November 1, 2024
Edited by Swati

Edited by Swati

I’m Swati. I accidentally started testing in 2004, and since then have worked with at least 20 clients in 10 cities and 5 countries and am still counting. I am CSTE and CSQA certified. I love my job and the value it adds to software…

Learn about our editorial policies.

Here’s How to Install and Setup Appium on Windows with First Program to Get a Kick Start on Appium:

Appium is an open-source test automation tool used for testing mobile applications. It allows users to test various types of mobile applications (such as Native, Hybrid and Mobile Web) using a standard WebDriver library.

There are three types of Mobile Apps:

  • Native: Native apps built using iOS, Android, or Windows SDKs. They are platform-specific. They are built to work on a platform and/or device.
  • Hybrid: Hybrid apps are web applications developed using HTML, CSS, and wrapper of a native application on top of UIWebView for iOS and “webview” for Android Apps.
  • Mobile web apps: Mobile web apps are the apps ones accessed using mobile browsers.
Appium tutorial for beginners

List of Tutorials in The Appium Series

Tutorial #1: Appium Tutorial For Beginners (This Tutorial)
Tutorial #2: Introduction To Appium: What is Appium and Its Architecture
Tutorial #3: Download, Install And Setup Appium for Windows
Tutorial #4: Configuring Mobile Device With System In Appium
Tutorial #5: Automate Native App On Android Device Using Appium
Tutorial #6: How To Automate Web Apps On Chrome Browser In Android Device


Why Is Appium A Popular Tool For Automating Mobile Apps?

Appium is a “cross-platform tool” i.e. it allows you to write tests on multiple platforms (iOS, Android, Windows) using the same APIs. Using Appium, you can also run automated tests on actual devices like tablets, mobile phones, etc.

It is the most widely used tool for regression testing of Mobile Apps on mobile phones and tablets. Appium makes mobile app regression testing easy, especially for large mobile apps that are updated frequently with new features and functionalities.

Setting Up the Appium Tool on Windows

Prerequisites: This is a shortlist of software and hardware required for automating mobile app testing using Appium:

  • Your PC should have JDK, Appium Server, Eclipse, Android SDK installed
  • Apk: Mobile Application to be automated by our Case ContactManager.apk
  • Testing Device: In this case Moto G
  • Jars: Java-client jars and Selenium Jars.
  • USB driver for Testing Device: In this case Moto G

Step #1: Install the Java Development Kit (JDK)

Step #2: Set up Java Environment Variable Path

Step #3: Download and install Android SDK here and update the APIs

To update the API, Open Eclipse -> Click on Window in the Eclipse Menu and -> Select Android SDK manager

Update the APIs as shown in the below screenshot:

Android SDK manager

Step #4: Now we need to install Appium for Windows. Go here to download Appium for Windows.

Step #5: Install Node JS from here: Node JS download 

Step #6: Set the ANDROID_HOME path as well as JAVA_HOME path

Specify the path for tools and platform-tools present in the Android SDK path.

Android SDK path

These folders will be present in adt-bundle-windows-x86_64-20140702\sdk

Now we need to update the Environment variable (Refer below Screenshot)

(Note: Click on any image for an enlarged view)

Update the Environment variable

Update path with tools and platform-tools (folder present in Android SDK).

The entry in Path will look as below:

C:\Program Files\nodejs\;%ANDROID_HOME%\tools;%ANDROID_HOME%\platform-tools

Step #7:  Access adb

Press Win+R keys combination
Type CMD. Now in CMD type ‘adb’. adb will be accessible

Preparing Mobile Devices For Automation With Appium

Connect your Mobile Testing device via USB to your PC. Enable Developer Mode on Mobile Phone before automating the app.

Steps to Enable Developer Mode/Options on Android Phone or Tablet:

1) Open Settings, Tap on the “About” option, Tap on “Software Information”, Tap on “More”.

2) Tap on “Build number” 7 times to enable Developer options.

3) Go back to Settings and make sure that the “Developer options” setting is there.

4) Tap on Developer options and turn on the USB Debugging option from the menu on the next screen.

Enable Developer Modec

5) Download and install USB Drivers for the Mobile Testing device on PC.

6) In the adb terminal type, “adb devices”
C:\Users\NEERAJ>adb devices
List of devices attached
TA93305G0L      device

adb devices

This will display a list of devices connected to the system. We will be using App Contact Manager.apk as a sample app to automate. Download and install Contact Manager.apk on the device.

Start Automating Android Apps Using Appium

Now run the appium.exe on your PC.

Run Appium

Appium needs to run and pass the following parameters and Device Name in Android Settings.

Note: Don’t change the port number or anything in the general settings icon. When the Appium Server starts, the Server address, as well as Port address, will be set by default. The port address will be 4723 by default

In Android Settings, the user needs to set the APK path where the APK is located, check the app path, package and launch Activity.

  • Connect your Android phone to your PC and turn on USB debugging mode.
  • Open Command prompt.
  • Type command adb logcat.
  • Open the app on your Android phone. Immediately press CTRL + C in command prompt
press CTRL + C

com.example.android.contactmanager is package name and com.example.android.contactmanager.ContactManager is the activity name of the Contact Manager app.

Contact Manager app

In the above screenshot, we have populated all the needed information in the Appium i.e package, launch activity, Mobile Device Name.

How To Locate Elements Using UIAutomatorViewer?

1) To automate the app first we will need to find the elements of the app that we will need to interact
for that, we will use UIAutomatorViewer

2) Connect the device in which the app is installed to the PC

3) Go to Terminal.

Type: Adb Devices

C:\Users\NEERAJ>adb devices
List of devices attached
TA93305G0L      device

This will show the list of devices connected to your PC.

4) Open the app that you want to automate on your Mobile Device.

5) Open UIAutomatorViewer and go to the following path

adt-bundle-windows-x86_64-20140702\sdk\tools

adt-bundle-windows

6) So make sure your app is launched and the UIAutomaterViewer is launched by clicking on the Device screenshot.

7) This option will take a screenshot of the app with all the detailed information of all the elements visible on the app.

App with all the detailed information

Click on the Add Contact Button for our Test Scenario

Add contact Button

From the above screenshot, you can use locator By.name(“Add Contact”)

use locator By name

From the above screenshot you can take By.className(“android.widget.EditText”)) as our locator for Contact Name

locator for Contact Name

By.name(“Save”) can be used as our locator for the Save Button

First Program For Automating An App On Appium

Run the below Script, the Contact Manager application will be launched on the real device and all the logs will be displayed in the Appium console showing you all the actions getting invoked by the above script.

importjava.io.File;
importjava.net.MalformedURLException;
import java.net.URL;
importjava.util.List;

importorg.openqa.selenium.By;
importorg.openqa.selenium.WebDriver;
importorg.openqa.selenium.WebElement;
importorg.openqa.selenium.remote.CapabilityType;
importorg.openqa.selenium.remote.DesiredCapabilities;
importorg.openqa.selenium.remote.RemoteWebDriver;
importorg.testng.annotations.*;

public class appium {

 WebDriver driver;

 @BeforeClass
 public void setUp() throws Exception {

//location of the app
 File app = new File("C:\\Users\\NEERAJ\\Downloads", "ContactManager.apk");

 //To create an object of Desired Capabilities
 DesiredCapabilities capability = new DesiredCapabilities();
//OS Name
 capability.setCapability("device","Android");
 capability.setCapability(CapabilityType.BROWSER_NAME, "");
//Mobile OS version. In My case its running on Android 4.2
 capability.setCapability(CapabilityType.VERSION, "4.2");
 capability.setCapability("app", app.getAbsolutePath());
//To Setup the device name
 capability.setCapability("deviceName","Moto G");
 capability.setCapability("platformName","Android");
//set the package name of the app
 capability.setCapability("app-package", "com.example.android.contactmanager-1");
 //set the Launcher activity name of the app
 capability.setCapability("app-activity", ".ContactManager");
//driver object with new Url and Capabilities
 driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capability);
 }

 @Test
public void testApp() throws MalformedURLException{

System.out.println("App launched");
 // locate Add Contact button and click it
WebElementaddContactButton = driver.findElement(By.name("Add Contact"));
addContactButton.click();
 //locate input fields and type name and email for a new contact and save it
 List<WebElement>textFields = driver.findElements(By.className("android.widget.EditText"));
textFields.get(0).sendKeys("Neeraj Test");
textFields.get(1).sendKeys("9999999999");
textFields.get(2).sendKeys("testemail@domain.com");
driver.findElement(By.name("Save")).click();
 //insert assertions here
 }
 }

Setup Appium with Eclipse IDE

Software Required for Appium:

  • JDK, Appium Server, Eclipse, Android SDK
  • Jars: Java-client jars and Selenium Jars.
  • Apk: Application to be automated
  • Real Device: In this case SAMSUNG Note3
  • USB driver for Real Device: In this case SAMSUNG Kies

Step 1: Install the Java Development Kit (JDK)

Step 2: Setup Java Environment Variable Path

Go to the Terminal and type:
Open .bash_profile

bash_profile

Set the ANDROID_HOME Path as well as JAVA_HOME Path

Step 3: Install Android SDK / ADB on MAC

We need to install Tools, Extras and the corresponding API Level packages (in this case Android 4.4.2 API 19).

(Note: Click on any image for an enlarged view)

install-android-4-4-2-api-19

Step 4: Download and install Appium Server

appium-server

Note 1: No need to set anything in the general settings icon. When the Appium Server is installed, the Server address, as well as the Port address, will be set by default. The port address will be 4723. The user can change the server address if required.

Note 2: In Android Settings, the user needs to set the APK path where the APK is located, check the app path, package and launch Activity.

android-setting

How to Find .Apk File Package Name and Launcher Activity Name:

There are so many ways to find out the Package name and Launcher Activity Name of an application. This terminal is used to get the Package and Launcher Activity name.

Go to the terminal and type:

aapt dump badging <apk_File_Path><apk_File_Name.apk>

Hit “Enter” for the below screen:

find-apk-file-package-name-and-launcher-activity-name

If a user specifies the package name in Appium Server, then Launcher Activity Name, wait for Activity names to be displayed automatically.

Launcher Activity Name is:

com.amazon.mShop.android.home.HomeActivity.”

Steps to Enable Developer Mode / Options on Android Phone or Tablet

Step 1) Enable Developer Options

1) Tap on the Main Menu icon.

2) Go to Settings.

3) Scroll down to About phone and tap on it.

4) Scroll down to the bottom, tap on ‘Build number’ Seven (7) times. (Your build number may vary). After the third tap, the user can see a playful dialog “You are a developer”. Keep on tapping until the dialog is displayed.

5) You will notice the Developer Options on your screen now.

developer-options

Step 2) Switch On USB Debugging

1) Go to Developer Options.

2) Select USB Debugging.

usb-debugging

3) It may display the Pop-Up message and if it does, just click OK.

Step 3) Download and install USB Driver for Corresponding Real Device. In this case SAMSUNG Kies.

How To Locate Elements Using UIAutomatorViewer?

1) The first step before locating any element on the device is to connect the device to the computer.

Follow the steps below to check the device connectivity:

  • Go to Terminal.
  • Type: Adb Devices
adb-devices

This will display a list of devices connected to the system.

2) On a real device, open the app that has to be automated (Here amazon app is automated)

3) Go to the following directory to open UIAutomatorViewer:

Users -> Library -> android -> sdk -> tools -> uiautomatorviewer.bat

EX: users/bikram.badatya/Library/Android/sdk/tool/

4) In UIAutomatorViewer, click on Device screenshot.

device-screenshot

5) Upon clicking on the Device screenshot, the device image along with the detailed information will be displayed on the left side of the UIAutomator window.

6) Upon clicking on any element on the page, relevant information about that element will be displayed on the right side.

device-screenshot-element-info

7) Click on the Main Menu button to display all properties.

Appium Test to Launch Amazon App

1) Launch the Appium Server.

launch-appium-server

2) Android Settings.

android-settings

3) General Settings for Server Address and Port address:

general-settings-for-server-address-and-port-address

4) Click on the launch button.

Code snippet to launch Amazon Application:

package com.AppiumDemo;

//Library to create the path to APK
import java.io.File;
//Library used to verify if URL is malformed
import java.net.MalformedURLException;

//Library used to create URL for the Appium server
import java.net.URL;

import java.util.concurrent.TimeUnit;

//Libraries for import selenium WebDriver
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;

//Libraries for configuring Desired Capabilities
import org.openqa.selenium.remote.DesiredCapabilities;

//Library for import TestNG
import org.testng.annotations.Test;

//Libraries for import Appium Drivers
import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;

public class LauchAmazon {
	private static AndroidDriver&amp;amp;amp;amp;amp;amp;amp;lt;MobileElement&amp;amp;amp;amp;amp;amp;amp;gt; driver;
	 //static WebDriver driver;

		@Test
		public void setup() throws MalformedURLException, InterruptedException{

			// Path to &amp;amp;amp;amp;amp;amp;amp;lt;project folder&amp;amp;amp;amp;amp;amp;amp;gt;&amp;amp;amp;amp;amp;amp;amp;lt;Amazon&amp;amp;amp;amp;amp;amp;amp;gt;
			File appDir = new File(&amp;amp;quot;//Users//bikram.badatya//Library//Android//sdk//platform-tools//&amp;amp;quot;);

			//Path to &amp;amp;amp;amp;amp;amp;amp;lt;project Folder&amp;amp;amp;amp;amp;amp;amp;gt; to  Amazon apk File&amp;amp;amp;amp;amp;amp;amp;gt;
			File app = new File(appDir, &amp;amp;quot;Amazon.apk&amp;amp;quot;);

			//To create an object of Desired Capabilities
			DesiredCapabilities capabilities = new DesiredCapabilities();

			//To set Command Timeout in appium server.Its optional you can set in appium Server itself.
			capabilities.setCapability(&amp;amp;quot;no&amp;amp;quot;,true);
	        capabilities.setCapability(&amp;amp;quot;newCommandTimeout&amp;amp;quot;, 100000);

	        // Name of the OS: Android, iOS or FirefoxOS
		    capabilities.setCapability(&amp;amp;quot;platformName&amp;amp;quot;, &amp;amp;quot;Android&amp;amp;quot;);

		    //set the name of the connected device.you have to give same name in both server and the code
		    capabilities.setCapability(&amp;amp;quot;deviceName&amp;amp;quot;,&amp;amp;quot;41001fd89730a000&amp;amp;quot;);

		    //Mobile OS version. My device is running Android 4.4.2
		    capabilities.setCapability(&amp;amp;quot;AndroidVersion&amp;amp;quot;,&amp;amp;quot;4.4.2&amp;amp;quot;);

		    //set the package name of the app
		    capabilities.setCapability(&amp;amp;quot;appPackage&amp;amp;quot;, &amp;amp;quot;com.amazon.mShop.android&amp;amp;quot;);

		    //set the Launcher activity name of the app
		    capabilities.setCapability (&amp;amp;quot;appActivity&amp;amp;quot;,&amp;amp;quot;com.amazon.mShop.android.home.HomeActivity&amp;amp;quot;);

		    // Name of mobile web browser to automate. It should be an empty string, as we are automation an app.
		    capabilities.setCapability(&amp;amp;quot;browserName&amp;amp;quot;, &amp;amp;quot;&amp;amp;quot;);

		    //driver object with new Url and Capabilities
			driver = new AndroidDriver&amp;amp;amp;amp;amp;amp;amp;lt;MobileElement;(new URL(&amp;amp;quot;http://0.0.0.0:4723/wd/hub&amp;amp;quot;), capabilities);
		    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
		    driver.findElement(By.xpath (&amp;amp;quot;//android.view.View[@content-desc='Hello.Sign inSign inHello. Link']&amp;amp;quot;)).click();
		    driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
		    driver.findElement(By.xpath (&amp;amp;quot;//android.widget.EditText[@index='0']&amp;amp;quot;)).sendKeys(&amp;amp;quot;xxxx@gmail.com&amp;amp;quot;);
		    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
		    driver.findElement(By.xpath (&amp;amp;quot;//android.widget.EditText[@bounds='[101,188][499,231]']&amp;amp;quot;)).sendKeys(&amp;amp;quot;yyyzzz&amp;amp;quot;);
		    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
		    driver.findElement(By.xpath (&amp;amp;quot;//android.widget.Button[@content-disc='Submit']&amp;amp;quot;)).click();
		    driver.quit();
		}

}

Once the above Script is executed, the Amazon application will be launched on the real device and a list of messages will be displayed in the Appium console.

Important commands

1) To kill the adb server:

adb kill-server

2) To start the adb server:

adb start-server

3) To set JAVA_Home Path as well ANDROID_Home Path

open .bash_profile

4) To get package name and android Launcher name in apk (another way)

aapt dump badging <path to the apk>.apk name

Ex- aapt dump badging
/users/bikram.badatya/Library/Android/sdk/platform-tools/Amazon.apk

5) Install apk on real device

adb install <apk path>.apk name

6) Uninstall apk on real device

adb uninstall <app_package_name>
Ex– adb uninstall com.amazon.mShop.android

Limitations of Appium

  • It does not support the Android API level less than 17
  • Toast messages are not supported
  • Script execution on IOS platform is very slow
  • Gesture support is limited

Challenges Faced While Working With Appium

#1) To get the launcher activity name, which is required to launch the application, many methods can be followed like an extra apk named “apkInfo” needs to be installed, certain lines of code have to be written, etc. However, in this document, the following command is used to get the launcher activity name.

i.e. aapt dump badging <path to the apk>.apk name

#2) During setup in the Android SDK manager we need to focus on the following packages that have to be uninstalled. Otherwise, the application will not launch

during-setup

#3) Especially on MAC we need to setup Java_HomePath and Android HomePath in .bash_profile so that it is not required to set up again and again.

#4) Launching the application using an emulator consumes more time compared to a real device. Hence, the use of a real device is recommended.

Further reading  =>> Popular Appium Interview Questions

Conclusion

With emerging trends and more demand for Mobile Apps, all major companies are migrating to get their business on mobile apps. Thus to release quality mobile apps, automation testing of mobile apps is the latest trend in the industry.

Appium, because of its simplicity and ease of use, is one of the leaders and most widely used tools all over the globe for automation testing of mobile apps for iOS and Android.

About the author: This post was written by STH team member Neeraj. He is a passionate software tester currently working as a Senior Software Development Engineer in Test and enjoys testing web and mobile applications.

Click here to read more on Mobile Automation Using Appium Studio Tool.

NEXT Tutorial

Was this helpful?

Thanks for your feedback!

Recommended Reading

  • Introduction To Appium Open Source Automation Tool

    This Tutorial Explains What is Appium, Its Architecture, Workflow, And How to use This Open-source Tool for Mobile Automation on Android & iOS: Appium is an open-source Mobile Automation tool that provides automation on platforms like Android, iOS, etc. It also supports automation using multiple programming languages like Java, PHP,…

  • Services for Mobile Beta Testing

    Beta testing is perhaps one of the most important steps in mobile application development. Unlike standardized iOS, mobile devices running on Android significantly differ from each other, not just by the installed version of the operating system, but by the type of programming language, screen resolution, hardware etc. That is…

  • _Configure Mobile Device With System In Appium

    This Tutorial Explains how to Connect a Mobile Device with PC and Configure it for Automation Testing Using Appium. It covers the Verification of Mobile by ADB: We have to connect a real-time Android device with the PC in order to automate Android application tests in the Android device using…

  • UI Testing for mobile apps

    Mobile App UI Testing Guide: Learn how to perform iOS and Android UI Testing With the flourishing market for mobiles, testing of mobile applications has become exciting day by day. Just by running functional tests on a mobile application, you cannot sign off the app. There are few other testing…

  • Top Mobile Testing Tools (1)

    Here is a list and comparison of the Best Mobile Testing Tools for Android and iOS in 2025 for the benefit of our readers. Let's get started. Are you looking for ways to take your mobile testing strategy to the next level? There are countless methods for doing this but…

  • connecting to appium studio

    Step-by-Step Procedure on Connecting Real iOS & Android Devices from Cloud to Appium Studio: This tutorial is a part of our Appium Studio hands-on training series.  USB Recommendations: Ensure that neither Samsung Kies nor HTC Sync is installed on your system. Only use the proper, original cables for each device.…

  • Create Appium Tests for an Android App

    Steps involved in creating Appium Tests for an Android App: Step by step procedure involved in the creation of Appium tests for an Android App is explained precisely for your easy understanding. Snapshots of each step are available for your reference along with few video tutorials. And this tutorial is…

  • Installing Applications and Preparing them for Appium Testing

    How to install applications and prepare them for Testing in Appium: This tutorial is a part of our Appium Studio tutorial series and it includes the step by step procedures involved in the process of installing the applications and preparing them for Testing in Appium. Pictorial representation of each step…


19 thoughts on “Appium Tutorial for Testing Android and iOS Mobile Apps”

  1. Hi…Do u have only this post available from Appium space?

    If a person from manual testing background, want to enhance his career in automation space, Is this the right place to enhance him in an automation space?

    Reply
  2. Hi,

    Can you please tell me how to scroll application while using WebDriver instead of android driver.
    Whats the code.

    Reply
    • Hi Kuljeet,
      Here is the code for scrolling …

      public static void Scroll(int ScrollAmount)
      {
      double scrollCounter = ScrollAmount / 100;

      if (AppiumDriver.executionOS == “iOS”)
      {
      IJavaScriptExecutor js = (IJavaScriptExecutor)AppiumDriver.Instance;
      js.ExecuteScript(“window.scrollBy(0,” + ScrollAmount + “)”);
      }
      else //Android
      {
      AppiumDriver.Instance.Context = “NATIVE_APP”;
      System.Drawing.Size dimensions = AppiumDriver.Instance.Manage().Window.Size;

      Double screenHeightStart = dimensions.Height * 0.5;
      Double screenHeightEnd = dimensions.Height * 0.2;
      int scrollStart = Convert.ToInt32(screenHeightStart);
      int scrollEnd = Convert.ToInt32(screenHeightEnd);

      for (int i = 0; i < Convert.ToInt32(scrollCounter); i++) { AppiumDriver.Instance.Swipe(0, scrollStart, 0, scrollEnd, 2000); // break; } //driver.findElement(By.name("YourText")).click(); } }

      Reply
  3. We have to automate native app for ios,android and we have web application too.How we can manage automating all, is it possible to do this with using single tool or we have to automate everything separately?

    Reply
  4. Very neat and detail !! Following two would be a good addition 1. Appium Setup is most tedious thing, is there a way to dockerise / simplify the same? 2. How to run appium tests on Jenkins esp. for nightly jobs?

    Reply
  5. Please tell me how to automate an iOS App. using Appium.
    Because i’m unable to find the objects elements to create script in iOS environment.
    Is there any tool for that like “UI Automator Viewer” for Android.

    Thanks,
    Sandeep

    Reply
  6. Nice insights describing the learning about the Appium for the beginners. One more tool I would like to suggest for Mobile app testing through automation is TestingWhiz. This is a code-less test automation tool for web, database, cloud, mobile apps, etc.

    Reply
  7. How to automate mobile application if another finger scanner is attached to mobile device?
    take the scenario of mobile enrollment application where scanner is attached to mobile device.

    Reply
  8. hi,
    when we automate the mobile app,we need app source code? where we get the source code?how to use this code while automating the mobile app.plz give the info….

    thanks for sharing appium details….

    Reply
    • hi, you don’t need to use the app source code for automation purpose as you have the inspector to identify each and every element.

      Thanks !

      Reply
  9. when i am trying to use text attribute with name locator it throws exception that Locator Strategy ‘name’ is not supported for this session.

    Reply
  10. you have done gud work for sharing this appium tutorial for beginners..It is exactly what i was looking for.
    Thank You . keep going .

    Reply
  11. hello, how to install node, when it download click on .exe file command prompt is open, which command I try to install.

    Reply
  12. Not getting the Andriod SDK file on the link mentioned under #3) of “Setting up the Appium Tool on Windows”.

    Rather getting Andriod Studio link.

    Please help as I am stuck here.

    Reply

Leave a Comment