Quick tips to perform 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 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
- Install Android Studio and set the path
- Install Eclipse IDE
- Download and install Appium server
- Download Selenium and Appium Jar files
- Create a Project in Eclipse
Open Eclipse-> Click on file-> new-> Java Project-> Enter project name-> Finish
- Import Selenium and Appium Jar files to the project
Right click on the Project-> Build path-> Configure build path-> Add external Jars-> Apply
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
- Benefits of using Selenium for Test Automation in enterprises
- Tips to select the right mobile testing tool
- Software Testing Trends That Dominated 2016
About the Author:
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.