Create Appium script for Android Mobile App

In this tutorial, we are going to create our first Appium script for Android App. In our previous posts, we have already covered the installation and configuration part that you need to do before creating Appium script. If you haven’t done it yet then please follow the links provided under Pre-requisite section.


a) Download and install tools required to run Appium script on Windows

b) Create new project in Eclipse and import Selenium Stand alone Jar and Appium Client Jar file into it. Following article will help you in this regard. Setup Selenium WebDriver in Eclipse

c) Start Appium Server

d) Connect Android real device to your computer and Enable USB Debugging


Here is the scenario that we are going to cover :

1.   Launch Calculator App on Android real device
2.   Multiple two numbers
3.  Print result
4.  Close Calculator App

NOTE: First, we need following 2 important information about the Android App that we need to automate :

  • Main Activity Class Name
  • Package Name

We have to mention the Main Activity Class and Package Name in the Desired Capabilities of our script, so that Appium could recognize that which Page(Activity) it has to launch on device.

NOTE: Selenium opens webpage using URL and Appium launch App using Activity.

How to to get App Activity and Package Name?

NOTE: Assuming that Android Device is connected to your computer via USB cable and USB Debugging option of Android Device is also enabled.

1. Launch the App that you want to test on Android Device

2. Open Command Prompt and execute following command to make sure that Android Device is connected:

adb devices


3. Execute following 2 commands one by one to get App Activity and Package Name:

adb shell
dumpsys window windows | grep -E 'mCurrentFocus'




import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

import io.appium.java_client.AppiumDriver;
import io.appium.java_client.MobileElement;
import io.appium.java_client.remote.MobileCapabilityType;

public class CalculatorTest {
	public AppiumDriver<MobileElement> driver = null;

	public void setupstart() throws MalformedURLException {
		DesiredCapabilities capabilities =;
		capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "UiAutomator2");
		capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
		capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "4100b79b459381f7");
		capabilities.setCapability("appPackage", "");
		capabilities.setCapability("appActivity", "");
		driver = new AndroidDriver<MobileElement>(new URL("http://localhost:4723/wd/hub"), capabilities);

	public void calcTest1() throws Exception {
		String result = driver.findElement(By.className("android.widget.EditText")).getText();
		System.out.println("Result : " + result);

	public void tearDown() {

In you noticed in the above program, Desired Capabilities are mentioned which helps Appium to understand that which Mobile app it has to launch and on which device etc.
Desired capabilities are basically a set of keys and values which goes to the Appium server to tell that what kind of automation session user is interested in starting up. There are various capabilities which can modify the behavior of the server during automation. You can refer the server capabilities from Appium Doc.

Below, We have explained the Appium server capabilities that have been used in our script.

1. Automaton name is UiAutomator2

What is UIAutomator?

UIAutomator or UIAutomator2 are automation frameworks based on Android instrumentation and allows user to run UI tests on Android Device and Appium uses Google’s UIAutomator framework to execute commands on real devices and emulators. Or you can also say that UIAutomator is Google’s test framework for native app automation at the UI level.

Note: UIAutomator2 does not support Android versions below 5.0 and if your android device OS version is below 5.0 then you have to use UIAutomator framework. In our script, we have used UIAutomator2 as we are using Android version 9.

capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "UiAutomator2");

2. Platform Name : Android
As we have created this script for android, so we have to tell Appium about the platform where we actually want to run our script. For Iphone, it would be iOS.

capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");

3. Device Name : {Unique Device ID}
We have to tell the Device name to Appium server so that it could recognize the device before launching the Mobile App. You will get this uniqueID after running the “adb devices” command in command Prompt.

capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "4100b79b459381f7");

4. In order to launch Application on device, We have to mention App Package and Activity name in Desired Capabilities to allow the script to launch the application under test.

capabilities.setCapability("appPackage", "");
capabilities.setCapability("appActivity", "");

5. Here, we have to provide the IP address and port number that we have used while starting the Appium server.

driver = new RemoteWebDriver(new URL(""), capabilities);

If you find the information provided above is useful, please don’t forget to like us on Facebook, you can also leave the comment.

Leave a Reply

Your email address will not be published. Required fields are marked *