Tuesday, 28 June 2016

Mobile Automation Testing using Appium

We always been a continuous process to identify new technologies and evaluate the best ones based on how they help us add value to our clients. Quality Assurance (QA) being one of the most important aspects of any development cycle, one of the initiatives we have adopted to ensure best practices is adopting Appium for mobile testing. 

Appium is an open source test automation framework that drives iOS and android apps (Native, Hybrid and Mobile web apps) using the Selenium WebDriver protocol.

Here are a few points that will highlight its relevance at Ideaapplied
  • Free and open source tool.
  • Only a handful of firms are aware of this new tool, and we are one of the earliest adopters.
  • Appium is built on the idea that testing native apps shouldn’t require including an SDK or recompiling your app.
  • Developers need not wait for the QA team to run tests, it allows developers to run it during the development time. This ensures quick bug fixes and a stable product with reduced delivery time.
  • We can write and run our tests using any language (Java, Ruby, Python etc. which Selenium supports) or test framework.
  • Appium uses Selenium WebDriver scripts to test applications.
  • Appium allows to write tests against multiple mobile platforms using the same API.
  • Using Mac we can run both Android and iOS devices.
  • Both, Browsers and native apps can be tested through Appium.

About Appium:

Just like the Selenium WebDriver – which is an open-source tool used to automate web browsers, Appium is an automation library used to drive your mobile applications, and even the web browser within the mobile simulator, emulator or real device. It drives iOS and Android apps using the WebDriver JSON wire protocol.

Prerequisite to use Appium:
  1. Android SDK (to run emulators)
  2. JDK (Java Development Kit)
  3. TestNG / Junit
  4. Eclipse
  5. Selenium Server JAR
  6. WebDriver Language Binding Library
  7. Appium For Windows
  8. APK App Info On Google Play
  9. Node.js (Not Required – Whenever Appium server is installed, it by default comes with “Node.exe” & NPM. It’s included in Current version of Appium.)

Appium Design Concepts:
  • Appium is a ‘HTTP Server’ written using Node.js platform that drives iOS and Android session using WebDriver JSON wire protocol. Hence, before initializing the Appium Server, Node.js must be pre-installed on the system.
  • When Appium is downloaded and installed, a server that exposes a REST API is setup on your machine.
  • It receives connection and command request from the client and executes that command on mobile devices (Android / iOS).
  • It responds back with HTTP responses. It uses the mobile test automation frameworks to drive the user interface of the apps. Framework like:-
  • Apple Instruments for iOS (Instruments are available only in Xcode 3.0 or later with OS X v10.5 and later)
  • Google UI Automator for Android API level 16 or higher
  • Selendroid for Android API level 15 or less

Configuring Appium in Selenium:

To configure Appium in Selenium, we have to follow the steps mentioned below,
Step 1:
Create a Remote Driver.
Driver=new RemoteWebDriver();

Step 2:
Define capabilities.
Desired capabilities are set of keys and values, sent to Appium server to tell the server on what kind of automation and platform we are interested to run the scripts.

Step 3:
Assign the desired capabilities.
DesiredCapabilities capabilities = new DesiredCapabilities();
Capabilities.setCapability(“deviceName”, deviceName);
Capabilities.setCapability(“platformName”, platformName);
Capabilities.setCapability(“appPackage”, “com.android.browser”);
Capabilities.setCapability(“appActivity”, “com.android.browser.Activity”);

Step 4:
Assign Capabilities to the remote driver.
Driver=new RemoteWebDriver(new URL(“”) capabilities);
Driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);

Appium Script:

Add a Java Class file
protected AndroidDriver driver;
protected void flipkartapp() throws MalformedURLException {
        File appDir = new File("/Users/Sibin/Development/POC/flipkartapp");
        File app = new File(appDir, "Flipkart.3.0.apk");
        DesiredCapabilities capabilities = new DesiredCapabilities();

        //mandatory capabilities

        //other caps
        capabilities.setCapability("app", app.getAbsolutePath());
        driver =  new AndroidDriver(new URL(""), capabilities);
The next logical step from here is to create Page class files for different pages in the app and then create an according test class file. However to test the code just written, you can write a small piece of code as below:

    public void test flipkartapp()
        String app_package_name = "com.flipkart.android:id/";
        By userId = By.id(app_package_name + "user_id");
        By password = By.id(app_package_name + "user_password");
        By showPassword = By.id(app_package_name + "show_password");
        By login_Button = By.id(app_package_name + "btn_login");


Post this set up method you can write your normal automation test (Selenium types). Sample code would look like:


Reports and Results:
As we mentioned earlier Appium runs on Selenium scripts. It supports both JUnit and TestNG reporting format i.e. reports are generated in HTML format.

Appium also supports XSLT reports:

Appium supports XLST reports, sample code would look like,

 Limitations of using Appium
  • Testing of Android Version lower than 4.2 is not supported
  • Limitations on hybrid app testing. E.g. it’s not possible to test the switching action of application from the web app to native and vice-versa.
  • Cannot run Appium Inspector on Microsoft Windows.
  • No provisions to run iOS devices on Windows machine.
Ideaapplied Technologies provides comprehensive QA services. Visit us at ideaapplied.com to know more about our services.