Appium: iOS UI Software Test Automation

Automation–A Critical Advantage

  • Resource reduction
  • Faster, more accurate results
  • Repeatable
  • Programable
  • Decrease in a part cycle time
  • Improves quality and reliability
  • Better maintenance of Test Suit

With so many benefits, why not consider it? Engineers who develop mobile apps can make automation scripts to maintain their sanity when doing UI automation testing. Let’s take a look at automation testing with Appium and python code.

Appium is an open source test automation tool, developed and supported by Sauce Labs to automate native and hybrid mobile apps. It uses JSON wire protocol internally to interact with iOS and Android apps through the Selenium WebDriver.

Python is a high level programming language, widely used for general purposes, such as for automation because many automation frameworks are available in this language.

Necessary tools/framework required to execute scripts with Appium:

  • Prepare with latest OS X and xCode 5.1.1 (Appium now supports the latest version)
  • Install Node here
  • Install python from here
  • Install pip sudo easy_install pip
  • Install nosetests pip install nose
  • Download the sublime text editor here
  • Download Appium UI client on your mac here

After completing these steps, open Appium from finder. It will look like this:

appiom ios_1

Get the build(.app) of the iPhone-Simulator from finder and make a .zip of your application. Choose path from Appium IOS settings. Settings on Appium should like this:


To apply automation we need recorded scripts. Appium can record your existing features into scripts very well. Appium supports recorded features and converts them into multiple scripting languages like:

  • Python (personal favorite)
  • C#
  • Ruby
  • Objective-c
  • Java
  • Node.js

Start Recording

  • Click on the Launch button from the Appium UI tool.
  • After seeing (twice): info: <— Get wd/hub/status/  200 xxx ms
  • Click on the Search button(Appium Doctor)
  • Click on the Record button

It will open the record functionality of Appium like this:


After pressing the Send Keys button, it will directly effect the running application on the IOS Simulator and the script will generate something like this:


Based on your requirements, you can then record more scripts and keep them for automation.

[See Also: Virtualization in Custom Software Development]

Focusing on Scripting

As you can see here, the web driver is an instance of the Appium web driver. Actually, it deals with IOS via JSON wire protocol. Selenium is well known and widely used in automation testing. Selenium uses Appium, and it was made for IOS-Android UI automation testing. Here’s how Appium scripts work:




Examples of clean scripts in Python and executed in Appium:

Here are examples of clean scripts in Python that are executed in Appium. For this example we will use Login, Favorite and Logout. Start by taking Appium’s web driver instance into singletone.

1. Create a file like this:

  • Import OS
  • From datetime import datetime

#--Generic Variables for use through Appium connection
K_APPIUM_VER = '1.0'
K_DEVICE_NAME = 'iPhone Retina (4-inch 64-bit)'

#--Webdriver property

#--Result Files
K_RST_FILE = '/Result/test.txt'
K_RST_FILE_PATH = os.path.dirname(os.path.realpath(__file__)) + K_RST_FILE
K_RST_HTML_FILE = '/result.html'
K_RST_HTML_FILE_PATH = os.path.dirname(os.path.realpath(__file__)) + K_RST_HTML_FILE
K_RST_PDF_FILE = 'Report'

K_FILE_NOT_FOUND = 'File not found for given path %s'

class utility_functions():

#--Common utils for Apending string in test.txt file.
def write_comment_in_file(self,text):
f = open(K_RST_FILE_PATH, "a")
f.write('Time: %s ' %
return True

2. Create a file labeled like the script:

  • Import os
  • Import constant as const
  • Import unittest, time
  • from appium import webdriver
  • from time import sleep

#--SingleTone Class
class Singleton(object):
_instance = None
_desired_caps = None

#-- Initialized new instance of Appium Webdriver if not found instance while calling.
def __new__(cls, *args, **kwargs):
if not cls._instance:
cls._instance = super(Singleton, cls).__new__(cls, *args, **kwargs)
cls._desired_caps = {}
cls._desired_caps['appium-version'] = const.K_APPIUM_VER
cls._desired_caps['platformName'] = const.K_APP_PLATFORM_NAME
cls._desired_caps['platformVersion'] = const.K_APP_PLATFORM_VER
cls._desired_caps['deviceName'] = const.K_DEVICE_NAME
cls._desired_caps['app'] = os.path.dirname(os.path.realpath(__file__)) + const.K_APP_FILE_NAME

cls._instance = webdriver.Remote(const.K_WD_REMOTE_URL, cls._desired_caps)

return cls._instance

3. Create for login scripts like this:

  • import os
  • import unittest, time
  • from time import sleep
  • import constant as const
  • from sz_appium_driver import Singleton

class ios_sz(unittest.TestCase):
def test_login(self):
#--Variable of initialized appium webdriver
wd = Singleton()
success_login = False

wd.find_element_by_name("icon back").click()


def is_alert_present(wd):
return True
return False

if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(ios_sz)

4. Record your features to save scripts.

You can create several scripts by recording your features and keeping them in separate python files. After that, you should create a config file that will execute the new scripts. Create a file named config.ini [nosetests]

verbosity = 2
#Used to display print statements on console
nocapture = 1
#test only some modules with comma seperated values
tests =,,, etc…

5. Launch appium.

6. Open terminal and execute nosetests -c config.ini.

7. See the magic begin: the simulator will open and automatically execute.


You can enhance these scripts with test case reports with HTMLTestRunner here.After these implementations, you can see your test case results like this:


Here we are starting Appium from UI Tools. We can also start Appium from the terminal. For that we need to install:

  • brew install node # get node.js
  • npm install -g appium # get appium
  • npm install wd # get appium client
  • appium & # start appium

Installing Appium via npm takes a few mins. If you directly call Appium (start appium server, same function as launch) it says -bash: appium command not found. So the four steps for the installation of nap and Appium are necessary.

You can also call these scripts and make the Appium server create a shell script.

Create a shell script:
#! /bin/sh
appium &
sleep 10
cd ~
cd Documents/SZ_Automation/SZ_Small_Big
python > result.html

You can call it something like: sh

Now you can use Appium to generate reports with automated testing! Happy automation to all you iOS developers!

Everything you need to know about outsourcing technology development
Access a special Introduction Package with everything you want to know about outsourcing your technology development. How should you evaluate a partner? What components of your solution that are suitable to be handed off to a partner? These answers and more below.


About The Author

Speak to our Experts
Lets Talk

Our Latest Blogs

With Zymr you can