How to Automate Android Mobile Application using Appium?

Work Flow of Appium

Appium test script written in IDE will interact with the Appium Server which is nothing but the node server with the specified IP address and port number. Node server again passes the request to mobile devices or emulator using the uiautomator as a JSON format. All the UI elements associated with the mobile application can be controlled by using the appium client which is nothing but the derived one of selenium.

The following information is going to explain about the Android application automation using Appium + Junit + Core Java. In the forthcoming posting, I will be sharing the information about the integration of Apache Maven and the continuous integration tool of Jenkins.

How to setup Appium in Windows x86 or x64 PC?

The following pre-requisites make it available at your end before start setting up Appium;

  1. Latest JDK (Should be installed not copy & paste)
  2. Android SDK with API 16 and above (Jellybean 4.1 and above)
  3. .NET Framework 4.5
  4. Appium.exe for windows
  5. Latest Eclipse IDE (I’ve tried with both Juno and Mars)
  6. APK file (Android mobile app)

Once the above pre-requisite is ready, start writing the test scripts in the newly created class file under java project by mapping the external dependencies of JAR files (Selenium & Appium client)

Now, we can see the above pre-requisite information in an elaborate way;

Pre-requisite 1:

After installing the JDK and completed the environment variable setup of both the ‘JAVA_HOME’ and ‘Path’ based on the below screenshot;



Ensure the Java installation in the command prompt based on the below screenshot;


Pre-requisite 2:

After downloading the Android SDK from and installing the Android SDK in your windows PC;

You have to setup the Android Environment variable in the ‘ANDROID_HOME’ and ‘Path’ as like JDK;

You have to add the android sdk installed location path based on the below screeshot;



You have to add both the platform-tools and tools location in the path variable;




Ensure the SDK manager is ready at your end based on the below screenshot; (click the SDK manager.exe available in the Android SDK location)


Pre-requisite 3:

Download the .NET framework from and install it in your PC and ensure the installation in your installed programs in control panel based on the below screenshot;


Pre-requisite 4:

Download the Appium Installer from and I’ve downloaded ‘’ from the above link. Unzip the installer file and click the ‘appium-installer.exe’ to install Appium in your windows PC;

Ensure Appium is successfully installed in your PC based on the below screenshot;


Pre-requisite 5:

 Download the Eclipse IDE from and run the ‘eclipse.exe’ available in your windows PC;

Pre-requisite 6:

I am going to take Yammer Android Mobile Application for this test run. You can download the Yammer apk from by giving the google play URL

Install the apk file to emulator using the below command and please note I’ve used Android API 19 (Kitkat 4.4.2) for installing the above apk. (You have to create an emulator using AVD manager.exe in the Android SDK installed location or you can connect the real device in your windows PC)


Even directly you can give the apk location path in Appium server IDE to install the apk by skipping the above section.


All the pre-requisites are ready at our end and now coming to the script preparation for automating an android mobile application;

  1. Create a java project in Eclipse IDE as AppiumDemo


2. Create a new package as Appiumdemo(your own name) and class as appiumTest(your own name) based on the below screenshot;



3. Now add the script in the file in Eclipse IDE;

Before entering in to the script preparation, I would like to highlight the importance of ui automator available under the tools folder of android sdk;

It will help us to trace the mobile elements, which is used for triggering the user actions like click, swipe, scroll, enter text etc.

Just go to the tools folder under the installed android sdk location and click the ‘uiautomatorviewer.bat’ file and open the mobile app in the emulator, click the screenshot button in the ui automator IDE based on the below screenshot;

Now you could visualize the mobile element information for your automation need;


Go to Eclipse IDE –> Project –> Properties –> Select ‘Java Build Path’ in left pane and select the ‘Libraries’ tab and select the ‘Add External Jars…’ to map all the dependencies jar as mentioned below;

Selenium supporting  jars from (Java)

Appium client libraries jars from (Java)

Add the selenium-java-2.45.0.jar and all jar files available in the libs folder.

Junit and hamcrest jars from


Add the below script and run the test script in the Eclipse IDE;

package Appiumdemo;

import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class appiumTest

private WebDriver driver = null;
public void setUp() throws Exception
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, “”);
capabilities.setCapability(“deviceName”, “Motorola”);
capabilities.setCapability(“platformVersion”, “4.4.2”);
capabilities.setCapability(“platformName”, “Android”);
capabilities.setCapability(“appPackage”, “com.yammer.v1”);
capabilities.setCapability(“appActivity”, “com.yammer.droid.ui.LauncherActivity”);
driver = new RemoteWebDriver(new URL(“ “),capabilities);
driver.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS);
catch(MalformedURLException e)

public void Login() throws Exception
driver.findElement(“Log In”)).click();
List<WebElement> textFieldsList = driver.findElements(By.className(“android.widget.EditText”));
textFieldsList.get(0).sendKeys(“”); //Give your account username
textFieldsList.get(1).sendKeys(“asdfghjkl”); //Give your account password
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); //Taking screenshot
FileUtils.copyFile(scrFile, new File(“c:\\Temp\\screenshotGK.png”));

public void tearDown()


Make the Appium Server UP with the default configuration; Ensure the server address and port number as mentioned in the test script such as with 4723.

Make the Emulator UP with the Installed APK file;

Go to Eclipse and right click the mouse button in script window by selecting the ‘Run as’ option and again select the JUnit Test’ as mentioned in the below screenshot;


That’s it!!! You script will be executed in the mobile application installed in the emulator. Next posting will be explaining about the integration of Appium with TestNG instead of JUnit.

5 thoughts on “How to Automate Android Mobile Application using Appium?

  1. Looks very good and so much useful….we all need to implement this and start from there to reach our destination….


  2. @Test
    I think, loading a test web page url statement is missing.
    For ex:

    correct me if I am wrong.


    1. testurl is applicable for browser related mobile web application automation.

      It’s for mobile application right? so we have to specify the application package name and activity(screen) name as follows;

      capabilities.setCapability(“appPackage”, “com.yammer.v1”);
      capabilities.setCapability(“appActivity”, “com.yammer.droid.ui.LauncherActivity”);


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s