Appium : Simplifying Mobile App Automation
Halo Developers !
There are numerous cycles any product progresses through, and the most crucial and imperative one is Quality Testing.
Quality Testing is bittersweet for most app developers. It exposes vulnerabilities and failed logics that test a developers competencies. But you have to taste the bitterness in order to gain a quality product. There are a plethora of test cases that must be run through and testing them is usually tedious and tiresome for most software products.. Every new feature added will cause a certain amount of regressions and it remains true for app development as well.
Hence this requires testing all the flows all over again to find breaks and cracks. This process usually is redundant and its not a pretty job to retest your app for all its test cases.
Enter Appium .
Appium is an open source test automation tool developed and supported by Sauce Labs to automate native and hybrid mobile apps. Best thing about Appium is it supports languages like- Java, Objective-C, PHP, Ruby, Python, C# etc. Also, it can run both on emulators and on mobile devices.
How it works ?
Appium is an HTTP server written in node.js that creates and handles web driver sessions.
So, Appium webserver receives http requests from selenium client libraries through JSON and then it handles those requests in different ways depending upon the platforms (Native or Hybrid mobile apps). Appium has its own mechanism for iOS and Android.
Appium server performs the following actions:
1) Receives connection from the client
2) Listen for a command
3) Execute a command
4) Respond back the command execution status.
Below picture, depicts the architecture of Appium :
First thing first
To make Appium work, we'll have to install the following :
1. JDK
2. Android SDK
3. Eclipse IDE (Note: Verison Luna or later versions of Eclipse should be installed)
4. UI Automator viewer (optional)
5. Install Appium
Assuming that you have JDK (Java development kit) and Eclipse IDE (Integrated development environment) already installed in your system,
let's have a quick view of steps to follow for Android installation :
1. Download Android SDK.
( Note: SDK API level should be greater than or equal to 17, because Appium will not work on lower levels. ) 2. Download and Install Eclipse IDE. 3. Add Android ADT plugin to Eclipse, by following the steps given below: - Start Eclipse – Select Help --> Install New Software --> Click 'Add' from the dialog box which appears --> -->Add the link https://dl-ssl.google.com/android/eclipse/ in 'Location' field --->Add name as 'ADT' in 'Name' field and Click on 'OK' button.
- In the Available Software dialog, check the check-box next to ADT and click 'Next’
- Continue with the Instructions to finish off the process.
4. Link the SDK folder in Eclipse, Select Window --> Preferences --> Select Android from the left panel
- In SDK Location field, browse the SDK location of the folder in your local machine and click ‘Ok’
5. Launch Android SDK manager.
- Click on Android SDK Manager icon in Eclipse.
- Select the tools/packages to be Installed ---> Click 'Install Packages'
This will help users to build and compile their projects, and also to create a virtual running device with specified Android SDK specifications.
- Once Done, Close the SDK Manager.
6. Launch AVD Manager, and create a new Android Virtual Device by following the steps given below:
- Click on Android Virtual Device Manager icon in Eclipse
- Click on 'Create' button
- Add all necessary information to create an AVD
- Click on 'OK'
- Select the created AVD --> click on 'Start' ---> Click on 'Launch'
- Emulator with the specified configurations will be launched.
APPIUM INSTALLATION ON UBUNTU:
Install node.js/npm:
sudo apt-get update
sudo apt-get install -y python-software-properties python g++ make
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs
Install grunt:
npm install -g grunt
npm install -g grunt-cli
Install Appium:
1) npm install -g appium
Set up a symlink in .bashrc file for Appium
2) ln -s /path/to/appium.js /usr/bin/appium
Type appium in the console, to check whether Appium server is getting started.
3) nevedha@nevedha:~$ appium
EXPLORING UI-AUTOMTOR VIEWER (FOR ANDROID)
UiAutomator Viewer is a tool, which lets the user to inspect the UI of an application in order to find the layout hierarchy, and view the properties associated with the controls.
The uiautomatorviewer tool will be located in the /tools/ directory.
1. Open the terminal, locate the SDK path/tools. Type in the terminal,
uiautomatorviewer (or)
sudo uiautomatorviewer
2. Uiautomatorviewer will open
3. Click on device screenshot icon to capture a dumb UI XML Snapshot of the screen opened in the device.
4. The left side of the tool captures the screenshot of the device. When hovered on the objects, structure and properties of those objects are displayed on the right side, which is divided into two parts:
• Upper half shows the nodes structure of the application.
• Lower half shows the details of the node selected with all the attributes of that particular object.
APPIUM CODE:
1. Open Eclipse and Create a new Project >> Package >> Class
2. Add Selenium Jars as External library in Eclipse in the project
3. Add TestNG Library in the project
4. Sample Program
package test.sample;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.AfterTest;
@BeforeTest
public class NewTestng {
WebDriver driver;
public void setup() throws MalformedURLException{
//Local path where the application is located
File appDir = new File("/home/nevedha/Documents/apps/yourApp/");
File app = new File(appDir,"yourApp.apk");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability(CapabilityType.PLATFORM, "Android");
capabilities.setCapability(CapabilityType.VERSION, "5.0.2");
//Whether to have Appium install and launch the app automatically. Default true
capabilities.setCapability("autoLaunch",true);
capabilities.setCapability("platformVersion","21");
capabilities.setCapability("platformName","Android");
capabilities.setCapability("deviceName", "Moto G(2nd Generation)");
//udid is an unique identifier of the connected physical device, which can be identified by running adb -devices in the terminal
capabilities.setCapability("udid","ZX1D6496FL");
capabilities.setCapability("app",app.getAbsolutePath());
//Package name of the application
capabilities.setCapability("appPackage", "com.advisualinc.yourApp");
//Package activity of the application
capabilities.setCapability("appActivity","com.advisualinc.yourApp.login.LoginActivityV2");
//Create a RemoteWebDriver Instance and connect to Appium server
//It will Install and launch the Application in Android device using the configuartion specified in Desired capabilities
driver = new RemoteWebDriver(new URL("http://0.0.0.0:4723/wd/hub"),capabilities); System.out.println("App launched");
}
@Test
public void login(){
// *refer the above screen shot
WebElement login_Onboarding =
driver.findElement(By.id("com.advisualinc.yourApp:id/txt_login"));
login_Onboarding.click();
// *suceeding screen of the application
WebElement login_Phno = driver.findElement(By.id("com.advisualinc.yourApp:id/txt_phone_number"));
login_Phno.sendKeys("+912345678901");
WebElement login_Pwd = driver.findElement(By.id("com.advisualinc.yourApp:id/txt_password")); login_Pwd.sendKeys("xyz123");
WebElement login_button = driver.findElement(By.id("com.advisualinc.yourApp:id/txt_login"));
if(login_button.isEnabled())
{
//driver.findElement(By.id("android:id/navigationBarBackground")).click(); login_button.click();
}
//click on Back
driver.findElement(By.id("com.advisualinc.yourApp:id/img_app_icon")).click();
}
REFERENCES:
http://appium.io/
https://discuss.appium.io/
https://docs.saucelabs.com/tutorials/appium/
http://nishantverma.gitbooks.io/appium-for-android/content/index.html
http://www.seleniumhq.org/
- Nevedha Vasudevan, QA Engineer.












