Appium - the Best Choice for Mobile Automation

“Appium - the Best Choice for Mobile Automation”

Quality assurance is an invaluable part of any developmental process. It serves as a sanity check for developers, helping them know for sure that whatever project they’re working on, it is bug-free and works as smoothly and seamlessly as possible. It used to be that QA Engineers would perform all tests manually, meticulously going through a product time after time until they were finally sure there was nothing more for them to fix. Such approach, although dedicated and rather functional, had many times shown itself to be very inefficient and time-consuming.

Fortunately, things have changed for the better. Now, there is a wide variety of tools available for all sorts of automated quality assurance testing: Robotium, Espresso, UI Automator, Selendroid, Testdroid, Calabash and so on and so forth. All of them are, in a way, similar - of course, some being better and some being worse. However, after having tried dozens and dozens of tools, we, here at SteelKiwi Inc., came to the conclusion that Appium is the best possible choice when it comes to high-quality automation testing. In this article, we’d like to present our reasons in support of this choice, so that you are aware of why we use some particular tools when developing your projects.

So Why Appium?

First, we’d like to start with a table comparing the most popular mobile automation tools.As you can see, Appium has far more advantages than do the other tools available on the market. However, it’s definitely not perfect. Any given instrument has its strong and weak sides, and we’re more than happy to tell you about Appium’s.

Pros:

  • Appium supports Android and iOS platforms. Furthermore: you don’t need to change anything when switching between them. Code, programming languages and user experience remains the same for both. Basically, this means that any test would work just fine no matter the platform.

  • Appium doesn’t require any in-app modifications for testing. An application can be tested right after it’s been downloaded and installed on the device.

  • SauceLabs, the guys in charge of Appium, specify in creating various well-known open source automation and manual testing solutions. As a result, Appium is frequently updated and each new release includes new useful features and bug fixes. Apart from that, there is a large Appium community online, so you can always ask as many questions as you want and get answers from other professionals just like you.

  • This tool allows automating web, native and hybrid applications, while also offering support for various hardware actions.

  • Appium supports all Webdriver-compatible programming languages: Java, Objective-C, JavaScript with Node.js, PHP, Python, Ruby, C#, Clojure and Perl.

Cons:

  • Appium doesn’t support image recognition.

  • Such hardware actions as swipe and gestures work only in native applications.

  • It is impossible to execute parallel iOS tests. If you want to run tests on multiple devices at once, you’d have to do so on the corresponding number of Mac OS PCs, as Macs only allow executing one instance per device. This limitation may cause a lot of problems with Continuous Integration. However, you could easily fix it by executing tests in the SauceLabs’ mobile cloud, which allows running tests on multiple iOS simulators at once.

  • It takes a long time to install and setup Appium for both iOS and Android.

  • Appium’s got a very weak sort of documentation, which can be a pain for some engineers.

How Does It Work?

Appium is a web server that utilizes REST API and built with the help of Node.js. It has a client/server architecture that presents users with a number of useful features. For instance, you are able to create tests using any Webdriver-compatible programming language and can execute them on any computer (not just the one containing the server). A server can be either installed using npm (which is a JavaScript package manager), or built from source code.All tests run within sessions, which are being created after the ‘POST /session’ request has been sent to the server. Such request contains a JSON body that stores the ‘desired capabilities’ - a set of options for Appium server configuration. By utilizing those capabilities, we may set the platform type (Android/iOS), device, target of execution (e.g.: a real device, a simulator, an emulator etc.), path to a website or application and so on.

Appium manages devices with the help of automation instruments that are native to the particular operating system - UIAutomator for Android and XCUITest for iOS (version 10 and higher).

Appium Test Example

Now we’d like to show you an example of a simple Appium test written in Python. It demonstrates the common features and actions used when automating mobile applications.

First, let’s create a Python file. Despite the fact that Selenium/Appium Python language bindings already offer a number of features, we’re using a couple of custom-made functions for this test, meaning we’ve had to include some additional libraries.

import unittest
from appium import webdriver
import pyperclip
import json
import urllib2
from selenium.common.exceptions import NoSuchElementException

Next, we’re going to create a test class and declare both the target device and the test’s ‘desired capabilities’.

setUp and tearDown are primary unit test module methods. Within the setUp method, you can find the desired capabilities and driver initialization, while tearDown is necessary for terminating all Appium processes after having finished the testing. Desired capabilities contain different keys and values for different cases. The full list of ‘desired capabilities’ can be found here.

class Tests(unittest.TestCase):
    def setUp(self):
        desired_caps = {}
        desired_caps['platformName'] = 'iOS'
        desired_caps['platformVersion'] = '10.3'
        desired_caps['deviceName'] = 'iPhone 6'
        desired_caps['app'] = '/Users/kiwi/Desktop/Hashtag_Hound_fixed.app'
        desired_caps['automationName'] = 'XCUITest'
        desired_caps['browserName'] = ''
        self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)

    def tearDown(self):
        self.driver.quit()

After you’ve done all of that, we can create a ‘test’ method, which performs application login and navigates to its certain page. In the code snippet below, we’ve already opened an app by using setUp. The last part of our ‘test’ method contains a couple of verification actions. The script extracts inner text from the element on the page, sends a GET request to the API and then reads its content. Afterwards, it compares the text it had previously extracted from the page and the response it received from the API.

def test(self):
   self.driver.find_element_by_accessibility_id('signInButton').click()
   self.driver.find_element_by_accessibility_id('emailTextField').send_keys('test@test.com')
   self.driver.find_element_by_accessibility_id('passwordTextField').send_keys('test1234')
   self.driver.find_element_by_accessibility_id('login').click()
   self.driver.find_element_by_accessibility_id('Favorites').click()
   self.driver.find_element_by_accessibility_id('FEATURE ACCOUNTS').click()
   acc_name = self.driver.find_element_by_xpath('//XCUIElementTypeApplication[@name="Hashtag Hound"]/XCUIElementTypeWindow[1]/XCUIElementTypeOther/XCUIElementTypeTable[2]/XCUIElementTypeCell[2]/XCUIElementTypeStaticText').text()
    self.driver.find_element_by_accessibility_id('accUnsaved').click()
    link = pyperclip.paste()
    request = urllib2.urlopen(link + '?__a=1').read()
    response = json.loads(request)
    full_name = (response.get('user')).get('full_name')
    assert acc_name == full_name
    return self

In spite of its limitations and the general complexity of configuration, Appium is a perfect tool for performing mobile automation testing. It offers many common features, easily integrates with other systems and frameworks, and supports a lot more devices and programming languages than its competitors. Apart from that, a broad and active Appium community saves users from wasting time on all of the unnecessary troubleshooting, while continuous development and numerous updates help to avoid countless bugs and other system-related problems.

If you’d like to learn more about how we perform QA testings on our products, please feel free to contact one of our sales representatives for detailed information. Also, if you’re interested in seeing Appium code in the real life, there are several examples of us using it on our corporate GitHub page.