Appium Tool for Automation Testing of Android Apps on an iOS System

Appium is an open source test automation tool used for testing mobile applications. It allows users to test various types of mobile applications (such as Native, Hybrid and Mobile Web) using standard WebDriver library.

Using Appium, you also run automated tests on actual devices like tablets, mobile phones etc. Appium makes mobile app regression testing easy; especially, for large mobile apps that  are updated frequently with new features and functionalities. 

Most testing professionals prefer Windows platform for Appium testing and there is enough help on the web on this topic. However, this Appium tutorial will help you automate android apps on an iOS system for which little documentation is available.

appium-tutorial

The article is divided into three sections:

  1. The first section explains the software required for the task
  2. The second is the setup on the device and
  3. Finally, the procedure to run the automation tasks on the device

Setup Appium with Eclipse IDE:

Software Required for Appium:

  • JDK, Appium Server, Eclipse, Android SDK
  • Jars: java-client jars and Selenium Jars.
  • Apk: Application to be automated
  • Real Device: In this case SAMSUNG Note3
  • USB driver for Real Device: In this case SAMSUNG Kies

Step 1: Install the Java Development Kit (JDK)

Step 2: Setup Java Environment Variable Path

Go to the Terminal and type:
Open .bash_profile

bash_profile

Set the ANDROID_HOME Path as well as JAVA_HOME Path

Step 3: Install Android SDK / ADB on MAC

We need to install Tools, Extras and corresponding API Level packages (in this  case Android 4.4.2 API 19).

(Note: Click on any image for enlarged view)

install-android-4-4-2-api-19

Step 4: Download and install Appium Server

appium-server

Note 1:  No need to set anything in general setting icon. When Appium Server is installed, the Server address as well as Port address will be set by default. Port address will be 4723. The user can change server address if required.

Note 2: In Android Setting, the user needs to set APK path where the APK is located, Check app path, package and launch Activity.

android-setting

How to Find .Apk File Package Name and Launcher Activity Name:

There are so many ways to find out Package name and Launcher Activity Name of an application. Here terminal is used to get Package and Launcher Activity name.

Go to terminal and type:

aapt dump badging <apk_File_Path><apk_File_Name.apk>

Hit “Enter” for the below screen:

find-apk-file-package-name-and-launcher-activity-name

If a user specifies package name in Appium Server, then Launcher Activity Name, wait for Activity names to be displayed automatically.

In this case Launcher Activity Name is:

com.amazon.mShop.android.home.HomeActivity.”

Steps to Enable Developer Mode / Options on Android Phone or Tablet

Step 1: Enable Developer Options

1) Tap on the Main Menu icon.

2) Go to Settings.

3) Scroll down to ‘About phone‘ and tap on it.

4) Scroll down to the bottom, tap on ‘Build number’ Seven (7) times. (Your build number may vary). After the third tap, the user can see a playful dialog “You are a developer”. Keep on tapping until the dialog is displayed.

5) You can notice the Developer Options on your screen now.

developer-options

Step 2: Switch On USB Debugging

1) Go to Developer Options.

2) Select USB Debugging.

usb-debugging

3) It may display the Pop Up message and if it does, simply click OK.

Step 3: Download and install USB Driver for Corresponding Real Device. In this case SAMSUNG Kies.

How to Locate Element using UIAutomatorViewer?

1) The first step before locating any element on the device is to connect the device to the computer.

Follow the below steps to check the device connectivity:

  • Go to Terminal.
  • Type ‘adb devices

adb-devices

This will display the list of devices connected to the system.

2) On the real device, open the app that has to be automated (Here amazon app is automated)

3) Go to the following directory to open UIAutomatorViewer:

Users -> Library -> android -> sdk -> tools -> uiautomatorviewer.bat

EX: users/bikram.badatya/Library/Android/sdk/tool/

4) In UIAutomatorViewer, click on Device screenshot.

device-screenshot

5) On clicking Device screenshot, device image along with the detailed information will be displayed on the left side of the UIAutomator window.

6) On clicking any element in the page, relevant information about that element will be displayed on the right side.

device-screenshot-element-info

7) Click on Main Menu button to display all properties.

Appium Test to Launch Amazon App

1) Launch Appium Server.

launch-appium-server

2) Android Settings.

android-settings

3) General Settings for Server Address and Port address:

general-settings-for-server-address-and-port-address

4) Click on the launch button.

Code snippet to launch Amazon Application:

package com.AppiumDemo;

//Library to create the path to APK
import java.io.File;
//Library used to verify if URL is malformed
import java.net.MalformedURLException;

//Library used to create URL for the Appium server
import java.net.URL;

import java.util.concurrent.TimeUnit;

//Libraries for import selenium WebDriver
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;

//Libraries for configuring Desired Capabilities
import org.openqa.selenium.remote.DesiredCapabilities;

//Library for import TestNG
import org.testng.annotations.Test;

//Libraries for import Appium Drivers
import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;

public class LauchAmazon {
	private static AndroidDriver&lt;MobileElement&gt; driver;
	 //static WebDriver driver;
		
		@Test
		public void setup() throws MalformedURLException, InterruptedException{
			
			// Path to &lt;project folder&gt;&lt;Amazon&gt;
			File appDir = new File("//Users//bikram.badatya//Library//Android//sdk//platform-tools//");
			
			//Path to &lt;project Folder&gt; to  Amazon apk File&gt;
			File app = new File(appDir, "Amazon.apk");
			
			//To create an object of Desired Capabilities
			DesiredCapabilities capabilities = new DesiredCapabilities();
			
			//To set Command Timeout in appium server.Its optional you can set in appium Server itself.
			capabilities.setCapability("no",true);
	        capabilities.setCapability("newCommandTimeout", 100000);
	        
	        // Name of the OS: Android, iOS or FirefoxOS
		    capabilities.setCapability("platformName", "Android");
		    
		    //set the name of the connected device.you have to give same name in both server and the code
		    capabilities.setCapability("deviceName","41001fd89730a000");
		    
		    //Mobile OS version. My device is running Android 4.4.2
		    capabilities.setCapability("AndroidVersion","4.4.2");
		    
		    //set the package name of the app 
		    capabilities.setCapability("appPackage", "com.amazon.mShop.android");
		    
		    //set the Launcher activity name of the app
		    capabilities.setCapability ("appActivity","com.amazon.mShop.android.home.HomeActivity");
		    
		    // Name of mobile web browser to automate. It should be an empty string, as we are automation an app.
		    capabilities.setCapability("browserName", "");
		    
		    //driver object with new Url and Capabilities
			driver = new AndroidDriver&lt;MobileElement;(new URL(http://0.0.0.0:4723/wd/hub), capabilities);
		    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);		   
		    driver.findElement(By.xpath ("//android.view.View[@content-desc='Hello.Sign inSign inHello. Link']")).click();
		    driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);		    
		    driver.findElement(By.xpath ("//android.widget.EditText[@index='0']")).sendKeys("xxxx@gmail.com");
		    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
		    driver.findElement(By.xpath ("//android.widget.EditText[@bounds='[101,188][499,231]']")).sendKeys("yyyzzz");
		    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);	    
		    driver.findElement(By.xpath ("//android.widget.Button[@content-disc='Submit']")).click();		   
		    driver.quit();
		}
  
}

When the above Script is executed, Amazon application will be launched on the real device and a list of messages will be displayed in the Appium console.

Important commands:

1) To kill adb server:

adb kill-server

2) To start adb server:

adb start-server

3) To set JAVA_Home Path as well ANDROID_Home Path

open .bash_profile

4) To get package name and android Launcher name in apk (another way)

aapt dump badging <path to the apk>.apk name

Ex- aapt dump badging
/users/bikram.badatya/Library/Android/sdk/platform-tools/Amazon.apk

5) To install apk in real device

adb install <apk path>.apk name

6) To uninstall apk in real device

adb uninstall <app_package_name>
Ex– adb uninstall com.amazon.mShop.android

Limitations of Appium:

  • It does not support Android API level less than 17
  • Toast messages are not supported
  • Script execution on IOS platform is very slow
  • Gestures support is limited

Challenges faced while working with Appium:

#1) To get the launcher activity name, which is required to launch the application, many methods can be followed like an extra apk named “apkInfo” needs to be installed, certain lines of code have to be written etc .But, in this document, the following command is used to get the launcher activity name.

i.e.  aapt dump badging <path to the apk>.apk name

#2) During setup in android SDK manager we need to focus on the following packages that have to be uninstalled. Otherwise, application will not launch

during-setup

#3) Especially on MAC we need to setup Java_HomePath and Android HomePath in .bash_profile so that it is not required to setup again and again.

#4) Launching the application using Emulator consumes more time compared to a real device. Hence, use of a real device is recommended.

Conclusion:

Everybody knows how mobile devices and their applications are increasing. These mobile applications work on multiple platforms. Appium is a very good tool for mobile automation. Lots of organizations prefer it for its simplicity, ease of use and robustness.

Personally, I have worked with it and I am satisfied.

About the author: This is a guest post written for STH by Bikram Badatya and reviewed by Vivek Babu Gondi (QA Manager).

If you have any questions about this Appium tutorial, feel free to post in comments below.


Further Reading

44 thoughts on “Appium Tool for Automation Testing of Android Apps on an iOS System”

  1. Very clearly written and understaning.I had failed long back by trying Android Testing with MAC os.But really this tutorials will helpful to me.many many thanks to the Author.

  2. Wonderful article !!! I liked the complete article…. great written,Thanks for all the information you have provided… Keep updating more articles …. :-)

  3. Thanks All of you for your support and encourage.I will be updating some more articles.Once again thanks for your coopration.

  4. Thanks all of your positive feedback. It will encourage me to do same in future. I am very happy by getting feedbacks at high.Definitely I will try to improve myself in next article.I will keep on posting some more important articles.Once again thanks to all readers and Team STH.

  5. Brilliant job bikarm this is exactly what i was looking,this article will be very helpful for evry1 to learn easily as it is explained in very detailed manner..

  6. Great insights related to the Appium. I would also suggest to experience one more user-friendly tool named TestingWhiz, which is already integrated with Appium for automating maobile apps, mostly related to the android apps.

  7. DesiredCapabilities dc=new DesiredCapabilities();
    dc.setCapability(CapabilityType.BROWSER_NAME,””);
    //dc.setCapability(“automationName”, “uiautomator2”);
    dc.setCapability(“deviceName”, “0123456789ABCDEF”);
    dc.setCapability(“PlatformName”, “android”);
    dc.setCapability(“PlatformVersion”, “4.4.2”);
    //provide app details
    //dc.setCapability(“app”,app.getAbsolutepath());
    dc.setCapability(“appPackage”, “in.amazon.mShop.android”);
    dc.setCapability(“appActivity”, “com.amazon.mshop.android.home.HomeActivity”);
    but iam getting error like An unknown server-side error occurred while processing the command. Original error: Error occured while starting App. Original error: Activity used to start app doesn’t exist or cannot be launched! Make sure it exists and is a launchable activity (WARNING: The server did not provide any stacktrace information)

Leave a Comment