Create Appium script for Android Mobile App

In this Post, we are going to create our first Appium script for mobile app and we will be running it on Android real device. In our previous posts, we have already covered the installation and configuration part that you have to do before creating Appium script. If you haven’t done it yet then please follow the links provided under Pre-requisite section.



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 App that we will be going to automate :

  • Main Activity class Name
  • Package name

We have to mention the Activity 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. We can simply get this information from “apk Info” App. You can download this app from Google play store on your android device. When you open this app, it will display all the installed apps of your device. Just look for calculator app and then tap on it to get the Activity and Package Name. Refer screen shot below :




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, "Appium");
		capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
		capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "4100b79b459381f7");
		capabilities.setCapability("appPackage", "");
		capabilities.setCapability("appActivity", "Calculator");
		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 the above program, desired capabilities are mentioned which helps Appium to understand that which browser it has to invoke 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 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 : Appium

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

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 launch Application on device, We have to mention App Package and Activity name in Desired Capabilities to allow the script to open the application under test.

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

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 *