Create Appium script for Android native App

After setting up Android and Appium on your system, next step is to  create an Appium script for Android native app. I hope that you have already downloaded and installed the required tools and APIs mentioned below. If not, then you can read our previous post in which we have explained the installation part.

Required Tools and APIs

  • Android SDK
  • JDK
  • Appium
  • Eclipse
  • Junit
  • Appium Client library
  • Selenium standalone Jar


Here is the scenario that we are going to cover :
1.   Launch calculator app
2.   Add two numbers
3.  Print result and validate the result
4.  Close Application

Before creating a script, first we need to get the following information of Calculator App :

  • Main Activity class Name
  • Package name

We have to mentioned this information in our script, so that Appium could recognize that which activity it has to launch on device. We will get this information from “apk Info” App. You can download this app from Google play store on your android emulator. When you open this app, it will display all the installed apps of your emulator. Just tap on the calculator app to get the information of it. Refer screen shot below :



import io.appium.java_client.AppiumDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import junit.framework.Assert;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;

public class CalcTests {

     public AppiumDriver 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, "");
            capabilities.setCapability(MobileCapabilityType.APP_PACKAGE, "");
            capabilities.setCapability(MobileCapabilityType.APP_ACTIVITY, "");
            driver = new AndroidDriver(new URL("http://localhost:4723/wd/hub"), capabilities);

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


         public void tearDown() {

If you want to understand about the concept of desired capabilities written in the above program, Please refer our previous post.

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

Leave a Reply

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