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.




Recommended reading

41 comments ↓

#1 Sravya

Nice tutorial.

Could you please post appium tutorial on How to Perform Automation Testing of iOS Apps on an iOS System or Windows

#2 shankar

finally someone shared the appium related posts here..

please share the detailed tutorial for android apps mobile test automation

#3 Kirti s

good to see appium tutorial. please share more such tutorials.

do you have mobile app testing training?

#4 Josh

Great to see . It would be great if some thing on iOS app

#5 Shreya

Great to see this tutorials.This is really helpful with MAC OS.This tutorial I was finding long back.

#6 Mukesh T

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.

#7 Roushan Kumar

very useful and clearly written

#8 Sayeed Ahmed

Outstanding Article.very useful for software testing folks.

#9 Krishna

thanks to Author.it is quite helpful to me

#10 Goutham M

fabulous Article.very helpful to beginner level.
Thanks Author

#11 P Thomas

It’s quite different.very helpful to testing android.Good luck.I am very happy by this

#12 Indhrajeet Podduluma

Finaly someone shared Appium Testing Article.Thanks to Author Mr.Bikram

#13 Jenish Duraimurugan

Learning Article for Entry Level Test Engineers.Good thought.

#14 Amrita Rao

Valuable article.Completely I read.keep it up the Author Mr.Bikram

#15 jagadeesh

Thanks, this tutorial is very usefull to me

#16 mukul Banerjee

its too nice article

#17 Ajay Nayak

Thanks,very helpful

#18 M Athar siddique

after long time i am seeing an in-detailed article on Appium.thanks to author

#19 Sandeep kumar

nice article but try to execute it out deeply

#20 nagajyothi

Nice article Bikram.very useful.You did a great job.keep it up my friend

#21 Darshini

Very Useful Article,Each step has been Explained in detail…Thank you for sharing it Mr.Bikram

#22 Luisha

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

#23 Bikram(Author)

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

#24 Bikram(Author)

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.

#25 Bikram(Author)

@Sravya,First of all Thanks.Definitly I will try to post related to IOS apps.

#26 Bikram(Author)

@Josh,Definitely I will try for ios apps.Thanks for your appreciation.

#27 sebak pradhan

very good achievement ..new innovation should be der ,hope u ill keep it up ..

#28 Ritu rani

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..

#29 Abhijit

Nic one well, achievement really I don’t understand BT well done too.

#30 Sourajya

Very nice tutorial.Really well explained.

#31 Bikram(Author)

@Sourajya, Thanks.it will encourage me to do better next time.

#32 Bikram(Author)

Thanks Luisha For your comments.

#33 Prakash

Really well explained.I went through it.Thanks to Author Mr.Bikram for this topic.

#34 Shrinivas

I am new to mobile automation , i have a query how you find out the xpath in mobile.

#35 Supriya

Hello Bikram, This is tutorial is very helpful. I have an Interview tomorrow. Can you please help me with some brief training.

#36 Bikram(Author)

@Shrinivas.you can use UIautomatorViewer which I already mentioned in this article

#37 Bikram(Author)

@supriya,Thanks.sorry within tomorrow it’s not possible to further training on it. I will try later on.

#38 Gignesh Pati

It’s very beautiful article. It helped me a lot. Thanks Author

#39 Arjoo Srivastav

Nice tutorial.well explained

#40 gowri

Very nice and useful article Bikram…keep up the good work..

#41 Pratik P

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.

Leave a Comment