Appium for Automating Native iOS Apps

Appium Test Automation tool for Native iOS Applications

Guys, there has been some implementaion changes for the Appium tool and i am sure there will few changes in setting up the project as well as my blog post here, pls wait for the new updated post. Thanks for the patience

We have seen Selenium WebDriver’s –iPhoneDriver coming up lately for automation in iOS, but that is only for the browser’s and used only for testing web applications in iOS.

Here come’s the solution, Once again Jason Huggins is up on this new tool for automating the Native iOS applications on iOS devices.
Appium is a test automation tool for use with native and hybrid iOS applications.
It uses the webdriver JSON wire protocol to drive Apple’s UIAutomation.

Appium is based on [Dan Cuellar’s]( work on iOS Auto. Just great, credit goes to him.

Dan’s Talk on Appium is here. Dont miss it, lovely to watch.

Some Good Reason’s to use Appium :

  • Appium is built on top of the Apple’s UI Automation framework and hence it is robust and no need for any code re-compilation of your app to use them.
  • Appium allows us to write tests in programming languages of our choice using Selenium WebDriver API and language specific client libraries.
  • Getting Started with Appium

    Step 1: The First step would be to clone the repository at

    Step 2: On your Terminal navigate to the cloned Appium directory and install dependencies using the command

    pip install -r requirements.txt

    . It will start installing dependencies and looks like, as in the sceenshot
    Screen Shot 2013-01-14 at 1.09.55 AM

    Step 3: To avoid a security dialog that can appear when launching your iOS app, you need to modify your /etc/authorization file.(“at own risk” is what claimed by the developer’s.) Using the command

    sudo python

    and it will look like, as in the screenshot below
    Screen Shot 2013-01-14 at 1.06.37 AM

    Step 4: To launch an interpreter for sending raw UIAutomation javascript commands run:
    For Actual Device : Use the command

    python com.yourApps.BundleID -U <DEVICE_UDID>

    For the Simulator:

    python ""

    If your app is already installed then you can find somewhere in Finder here and the link goes like – /Users/”Your Home NAme “/Library/Application Support/iPhone Simulator/Which version you use(5.1 “this is mine”)/Applications

    It will look like, as in the below screenshot (I have just tried to locate the iWebDriver app which i used for iPhoneDriver – Use your actual iOS App)

    Screen Shot 2013-01-14 at 1.43.01 AM

    We are done with the Steps to setup the Appium framework. Now Let’s see how to run the tests using WebDriver

    How to Run the Sample Scripts?

    JavaScript Approach

    Step 1: To run the test you must build the sample app (`sample-code/apps/TestApp/TestApp.xcodeproj`) in Xcode.Screen Shot 2013-01-14 at 1.51.54 AM

    Screen Shot 2013-01-14 at 1.52.49 AM
    Step 2: You can find the compiled app using spotlight from the command line.
    `mdfind -name`
    Screen Shot 2013-01-14 at 2.01.58 AM

    Step 3: Use that path to run the sample test `python “/path/to/”`
    Screen Shot 2013-01-14 at 2.01.58 AM
    This program is the same, that you will find the cloned repository

    import os
    import sys
    from random import randint
    # import appium
    appiumpath = os.path.abspath(os.path.join(os.path.split(os.path.abspath(__file__))[0],'../appium'))
    import appium
    # generate two random numbers
    num1 = randint(1,9)
    num2 = randint(1,9)
    # create an appium instance
    driver = appium.Appium(sys.argv[1])
    # enter the two numbers into the fields
    print 'Entering "' + str(num1) + '" into the first text field' 
    driver.proxy('target.frontMostApp().mainWindow().textFields()[0].setValue("' + str(num1) + '");')
    print 'Entering "' + str(num2) + '" into the second text field'
    driver.proxy('target.frontMostApp().mainWindow().textFields()[1].setValue("' + str(num2) + '");')
    # submit the form
    print 'Submitting the form'
    # validate the sum
    answer = driver.proxy('target.frontMostApp().mainWindow().staticTexts()[0].value()')[0][1]
    correctanswer = num1 + num2
    if int(answer) is correctanswer:
    	print '\033[92m' + 'SUM = ' + answer + '\033[0m'
    	print '\033[91m' + 'SUM = ' + answer + ', it should be ' + str(correctanswer) + '\033[0m'
    # quit appium

    WebDriver Approach

    Step 1: Sample WebDriver Script that will computer 2 numbers in the Test App

    from selenium import webdriver
    from random import randint
    # generate two random numbers
    num1 = randint(1,9)
    num2 = randint(1,9)
    # create a webdriver instance
    command_url = 'http://localhost:4723/wd/hub'
    iphone = webdriver.DesiredCapabilities.IPHONE
    print '\nconnecting to web driver @ ' + command_url
    driver = webdriver.Remote(command_url, iphone)
    # enter the two numbers into the fields
    fields = driver.find_elements_by_tag_name('textField')
    print 'Entering "' + str(num1) + '" into the first text field' 
    print 'Entering "' + str(num2) + '" into the second text field'
    # submit the form
    buttons = driver.find_elements_by_tag_name('button')
    print 'Submitting the form'
    # validate the sum
    labels = driver.find_elements_by_tag_name('staticText')
    correctAnswer = num1 + num2
    displayedAnswer = labels[0].text
    if int(displayedAnswer) is correctAnswer:
        print '\033[92m' + 'SUM = ' + displayedAnswer + '\033[0m'
        print '\033[91m' + 'SUM = ' + displayedAnswer + ', it should be ' + str(correctAnswer) + '\033[0m'
    # quit the webdriver instance
    print 'Quitting webdriver\n'

    Step 2: Compile and find the app as you did in the previous example and then launch the webdriver server.

    python "/path/to/"

    Screen Shot 2013-01-14 at 2.19.28 AM

    Step 3: Now you can run a test against that server.


    Few Questions to Answer :

    How to capture the Locators to use in the Scripts ?(Js approach)

    Instruments, which uses the UIAutomation library will be the answer. You can Map the target as and start recording the actions.

    How to get Instruments tool ?

    Instruments tool come’s with the Xcode developer tools. Install developer tools if you haven’t.


    How to Map your App as a Target in Instruments ?

    Screen Shot 2013-01-14 at 8.01.54 PM

    Screen Shot 2013-01-14 at 8.17.42 PM
    We are done… 🙂 If time permits I will take a real App and add a screencast of the same.

    Join and Post your questions on Appium

    12 Responses to “Appium for Automating Native iOS Apps”
    1. Nesta says:

      StumbleUpon brought me here! Great submittion!

    2. Z says:

      I am a newbie to mobile automation but appium got me very curious. Is there a way to come up with a screen capture video on how to setup and run a basic test against the test app? Greatly appreciate this in advance.

    3. Manoj,

      can we use Appium for testing Android Native apps?
      Also do you have a blog for the same on Java bindings?

      Any comment is welcome!!!

      Thank you!


    4. vamsi says:

      Display pictures are not showing up in the tutorials.

      Please update them.


    5. Nikhil says:

      Can we also used Appium + selenium scripts against phonegap apps?
      any tutorial/docs on that ?

    6. shilpa says:

      can anyone please tell me how do i setup appium Xcode and eclipse. I installed Node, Appium and Xcode.
      I have juint test in eclipse.i have to run web Juint test on Safari browser. i am unable to run the tests on do i run tests from eclipse.i started an appium server.. opened the simulator from Xcode.eclipse is not communicating with the simulator safari browser to run web tests..
      My code looks like this:

      import org.junit.After;
      import org.junit.Before;
      import org.junit.Test;
      import org.openqa.selenium.By;
      import org.openqa.selenium.WebDriver;
      import org.openqa.selenium.WebElement;
      import org.openqa.selenium.remote.DesiredCapabilities;
      import org.openqa.selenium.remote.RemoteWebDriver;

      import java.util.concurrent.TimeUnit;

      import static org.junit.Assert.*;

      * Simple test which demonstrates how a test can be run against Mobile Safari running on an Appium instance.
      * The test is based on
      * @author Ross Rowe
      public class SafariTest {

      private WebDriver driver;

      * Instantiates the {@link #driver} instance by using DesiredCapabilities which specify the
      * ‘iPhone Simulator’ device and ‘safari’ app.
      * @throws Exception
      public void setUp() throws Exception {
      DesiredCapabilities capabilities = new DesiredCapabilities();
      capabilities.setCapability(“device”, “iPhone Simulator”);
      capabilities.setCapability(“version”, “6.1”);
      capabilities.setCapability(“app”, “safari”);
      driver = new RemoteWebDriver(new URL(“”),
      driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

      * Navigates to and interacts with the browser.
      * @throws Exception
      public void runTest() throws Exception {
      WebElement idElement = driver.findElement(“i_am_an_id”));
      assertEquals(idElement.getText(), “I am a div”);
      WebElement commentElement = driver.findElement(“comments”));
      commentElement.sendKeys(“This is an awesome comment”);
      WebElement submitElement = driver.findElement(“submit”));
      WebElement yourCommentsElement = driver.findElement(“your_comments”));
      assertTrue(driver.findElement(“your_comments”)).getText().contains(“This is an awesome comment”));


      * Closes the {@link #driver} instance.
      * @throws Exception
      public void tearDown() throws Exception {

    Check out what others are saying...
    1. […] Assert Selenium has posted a getting started with Appium guide on their site here. […]

    Leave a Reply

    Fill in your details below or click an icon to log in: Logo

    You are commenting using your account. Log Out /  Change )

    Google photo

    You are commenting using your Google account. Log Out /  Change )

    Twitter picture

    You are commenting using your Twitter account. Log Out /  Change )

    Facebook photo

    You are commenting using your Facebook account. Log Out /  Change )

    Connecting to %s

    %d bloggers like this: