First Appium test script on Android device


Written by:

1/ Turn on USB debugging on your android device

Go to Setting –> Developer Options –> Enable USB debugging



2/ Find appPackage and appActivity name of your app.

In this tutorial I will use calculator app on my phone.

There’re 2 ways to check:

2-1/ Use ‘mCurrentFocus’ or ‘mFocusedApp’ in CMD

  • Unclock your mobile device and connect it to your computer by using USB cable.
  • Open Calculator app
  • Open command prompt. And type 

dumpsys window windows | grep -E ‘mCurrentFocus’

or dumpsys window windows | grep -E ‘mFocusApp’



2-2/ Use Apk Info app

  • Open Play Store and download.

  • Open Apk Info. It will show all app into your mobile.
  • Select Calculator app.

  • You can see appPackage name at top.
  • Expand “Activities”.

3/ Get your device name.

4/ Get device ID of your phone.

Open CMD and type adb devices


5/ Get your phone’s android version

Go to Settings –> About phone –> Software information

6/ Start Appium server


7/ Open Eclipse

We will make a simple test with steps:

  • Open Calculator.
  • Do calculation: 7+8.
  • Verify result and show report on by console.

Add code and run.


import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.MobileElement;

public class App 
    public static void main( String[] args ) throws InterruptedException, MalformedURLException
    	DesiredCapabilities caps;
    	AppiumDriver<MobileElement> driver;
    	caps = new DesiredCapabilities();
		caps.setCapability("deviceName", "TestingPhone");
		caps.setCapability("udid", "4200620ea8f6941b"); //Give Device ID of your mobile phone
		caps.setCapability("platformName", "Android");
		caps.setCapability("platformVersion", "7.0");
		caps.setCapability("appPackage", "");
		caps.setCapability("appActivity", "");
		caps.setCapability("noReset", "true");
		driver = new AndroidDriver<MobileElement>(new URL(""), caps);
    	driver.findElement("")).click();//press number 7
    	driver.findElement("")).click();//press +
    	driver.findElement("")).click();//press number 8
    	driver.findElement("")).click();//press =
    	//Verify result
    	String resultText = driver.findElement("")).getText(); 
    	if(resultText.equals("15")) { 
    		System.out.println("Test Passed"); 
    	}else {
    		System.out.println("Test Failed"); 


Congratulations! finally you have completed to launch a mobile app with Appium code. Hope that this tutorial is helpful for you. If there’re any issues, please leave a comment.

Leave a Reply

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