Quick tips to perform mobile automation using Appium

Dream. Dare. Do – that is Suyati’s work principle in a nutshell.

Feb
27
2017
  • Author:
  • Sarath Viswanath

mobile automation using Appium

Appium is an open source, cross-platform mobile test automation tool for native and hybrid applications. Tests can be done on simulators, emulators and on real devices too. It is an extension of Selenium webdriver. Appium has its own unique features. It supports IOS, Android and FirefoxOS.

Why is Appium in demand?

If we are using Appium for our mobile app automation, we can write the code in any language supported by Selenium webdriver. Also, we can use any testing framework which matches our goals. If we want to automate IOS apps, we need to use Apple’s UI Automation library. Similarly, to automate Android apps we need to use Google’s UI Automator library, which supports only Java.

Appium Architecture

1

Appium follows Client- Server Architecture. The language in which we write the script is called client libraries. Once we write the code and run it, the command reaches the Appium server which is written in Node js.  Appium server should be started before executing the program, if not, an error will be thrown. The commands will be reaching the server as session objects. The server will understand the commands, and triggers the invocation into the mobile device.

Appium act as a bridge between the client library (where actually we write the code) and the mobile device. It has the ability to identify whether it is IOS or Android framework. This is achieved through a mechanism called Desired Capabilities. It takes our input and passes it to the Appium server to create a session. Input includes Platform name (IOS/Android), Device name (Emulator/Real device) and Path of the application under test.

 

Prerequisites for Android Automation

  • Install Java and set the path

http://www.oracle.com/technetwork/java/javase/downloads/index-jsp-138363.html

  • Install Android Studio and set the path

https://developer.android.com/studio/index.html

  • Install Eclipse IDE

http://www.eclipse.org/downloads/packages/eclipse-ide-java-and-dsl-developers/neon2

  • Download and install Appium server

https://appium.io/downloads.html

  • Download Selenium and Appium Jar files

http://selenium-release.storage.googleapis.com/index.html?path=2.51/

https://mvnrepository.com/artifact/io.appium/java-client/2.1.0

  • Create a Project in Eclipse

Open Eclipse-> Click on file-> new-> Java Project-> Enter project name-> Finish

2

3

  • Import Selenium and Appium Jar files to the project

Right click on the Project-> Build path-> Configure build path-> Add external Jars-> Apply

4

5

Getting started with an Appium Program

Once we are done with the prerequisites, we can move to developing scripts. Every Appium code should begin with desired capabilities. To provide inputs to the server first we need to create an object of class “DesiredCapabilities”. And with that object we can pass other commands also. These commands will be common for all Android apps except the path of the application under test. Given below is a sample code which will be common to all apps written in Java.

@Test (Default annotation in TestNG Framework)

Step 1: DesiredCapabilities cap=new DesiredCapabilities();

 //Creating Object “cap” for class “DesiredCapabilities”

Step 2: cap.setCapability(MobileCapabilityType.PLATFORM_NAME,MobilePlatform.ANDROID);

//Passing command with the cap object to server that the platform we are using is Android

Step3: cap.setCapability(MobileCapabilityType.DEVICE_NAME, “Android Emulator”);

//Command telling the server that the device we are going to use is emulator

Step4: File appDir = new File (“folder name”);

        File app = new File (appDir, “sample.apk”);

// These 2 steps define the path of the app      

Step 5:  cap.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());

// Passing the app path to the server

Step6: AndroidDriver driver=new AndroidDriver (newURL (“http://127.0.0.1:4723/wd/hub”),cap );

//Invoking Android driver and we are passing the command to Appium server which is configured in port number 4723

 

Related Posts:

About the Author:

Sarath Viswanath

Sarath-photo

Sarath is currently working as QA Engineer at Suyati Technologies. A great tech enthusiast, Sarath is keenly interested in Automation testing for both mobile and web applications. He is a novice in the blogging arena and also loves playing cricket.

Get Our Newsletter

CMSCRMOpensourceEcommerce