Appium up & running with Robot Framework – iOS

Phew!!!!!

Finally got this setup done.

To start with, if you want to start from scratch, suggest you to close all your social networking sites & set aside half a day.

Go Ahead Now. Do it. Closed?

Ok.

Few pre-requisites before we start, so that you don’t get stuck anywhere.

1> If you have iOS 10.x/Xcode 8.x, then you need to have appium 1.6.x installed. This version of appium has support for Apple’s new XCUITest framework. You can google more on the framework or details are available at https://discuss.appium.io/t/appium-1-6-0-released/12661

So, in short the versions you require

iOS – 10.x

Xcode – 8.x

Appium – 1.6.x

The above versions will use the XCUITest framework by default.

If you have any previous version of the above & want to automate with it, then this blog won’t help.

2> Unlike Android apps, you cannot start testing or automating any Enterprise app, i.e. if you want to open Twitter or Facebook iOS app through appium, then that’s not possible. The .ipa file(google more on this file, don’t want to digress here) needs to be signed with a Development provisioning profile or cert. So, if you want to be  automate say a Google app, then you would need an id with valid Development provisioning profile & authenticated against Google. Otherwise forget it.

But if you have an internal App of your company, you can re-sign using your apple id & install it for automating.

If your aim is just to have a setup ready with some default app, then read along.

More details on the signing process for the iOS apps can be found here.

https://gigaom.com/2015/02/07/how-ios-developers-use-code-signing-to-get-their-apps-on-iphones/

 

So, with that out of the way & understood, let’s get started.

The next few sections are a repetition of earlier  blog, but just adding it here so that I don’t confuse you more by switching back & forth.

If you are aware of anything just skim through it.

 

What is the setup involved?

Appium is a client/server architecture.
Client is used to run the test cases.
Server is used to run the Appium Server.
The mobile devices or the emulators are required to run the tests against the app which we are testing.
Client & Server mentioned above could be 2 different hosts or can be a same host. Currently in my setup, both client & server are installed in the same OSX host.

Client Setup

Client is basically used to run the test cases. Tests can be written using any WebDriver-compatible language such as Java, Objective-C, JavaScript, Ruby, Python, PHP & RobotFramework.
Everyone has their own preference, but I prefer Robot Framework as it provides all the keywords needed to test mobile apps.
The beauty of Robot Framework is you can start automating learning few tools & techniques & can as well automate without knowing any scripting language.
Good till here?
If you already have a setup for client, then just skip this section & go directly to Server Setup
Now, for the all important part of installing tools. Will note down all those that I use & required for my testing.

i> Python:

Required for Robot Framework. But python is something every automation engineer would have.

     OSX – Nothing to be done, python is present by default.
     Windows – Download the latest python & install.

ii> Robot Framework:

Robot Framework is a generic test automation framework for writing test cases. This is my preferred method of writing test cases both for mobile app & as well browser(selenium) automation.

OSX & Windows: With python installed, run the below command to install Robot Framework.

pip install robotframework
For more details for installing Robot Framework, please refer https://github.com/robotframework/robotframework/blob/master/INSTALL.rst

iii> Appium Library for Robot Framework:

Appium Library is a app testing library for Robot Framework. Getting confused? Believe me, once you have the setup done & successfully tested run a test case, you can come back & read the documentation to better understand what each component is doing.

OSX & Windows: With python, Robot Framework already installed, run the below command to install the Appium Library.

pip install robotframework-appiumlibrary

Details on Appium related keywords in Robot framework is available at http://jollychang.github.io/robotframework-appiumlibrary/doc/AppiumLibrary.html

iv> Sublime Text:

This is optional & really a personal choice for each one of you. There are many text editors & IDEs we can use. But my favourite for any coding or text editing is Sublime Text.

OSX & Windows: Nothing complicated here for installation. Just go to the below link & follow instruction.

http://www.sublimetext.com/2

Server Setup

Please note IOS SDK can be run only on OSX, whereas Android SDK can be installed both on OSX & Windows. More on this later. But first look at Appium installation.

i> Appium Server:

Appium is an open source test automation framework for use with native, hybrid and mobile web. People familiar with Selenium, appium is the selenium for mobile apps.

For more details, please go to the website http://appium.io

For installation, follow the below steps.

OSX: Execute the below commands to install appium & start the service

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

To check if the appium service has started, check with the below command & the socket needs to be in Listening mode.

 netstat -an | grep 4723

ii> Setting up appium-xcuitest-driver: 

Some of the external dependencies required for appium to work.
> brew install ideviceinstaller
> brew install carthage
> npm install -g ios-deploy
> npm install -g deviceconsole
> gem install xcpretty
> brew install libimobiledevice --HEAD
All the above commands should get installed without errors. If there are errors, try executing with sudo.
Run the below command to check if all the appium dependencies are installed properly.
 appium-doctor 

If appium-doctor is not installed, you can install it using the command “npm install -g appium”

More detail of this driver is available at https://github.com/appium/appium-xcuitest-driver

iii> Setting up Webdriver Agent.

Below is a snapshot taken from https://github.com/facebook/WebDriverAgent

WebDriverAgent is a WebDriver server implementation for iOS that can be used to remote control iOS devices. It allows you to launch & kill applications, tap & scroll views or confirm view presence on a screen. This makes it a perfect tool for application end-to-end testing or general purpose device automation. It works by linking XCTest.framework and calling Apple’s API to execute commands directly on a device. WebDriverAgent is developed and used at Facebook for end-to-end testing and is successfully adopted by Appium.

1> Go to cd /usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent/

2> Run the below script

./Scripts/bootstrap.sh

3> Open WebDriverAgent.xcodeproj in Xcode using the below command

 
open -a Xcode WebDriverAgent.xcodeproj
Xcode should open

4> Click on WebDriverAgentLib & sign with your Development Provisioning profile or for now use your personal profile.

5> Click on WebDriverAgentRunner & sign in using your profile.
You might see an error in Provisioning Profile & Signing Certificate. Ignore it till you make changes in the next step.
6> Click on Build Settings & change the Product Bundle Identifier from it’s default to any other name.
Now go back to General, the errors you had in the previous step should not be there.

7> Now clicking on both WebDriverAgentLib & WebDriverAgentRunner, you need to build it once & check if everything is working fine.

The build should succeed in both the cases.

8> Click on IntegrationApp & sign in using your profile & change the name of the Bundle Identifier from it’s default.
9> With all the steps completed, if you make a build on any of the simulators, then the app should open in the simulator.

Quick checks to see if the device is ready for testing. 

Check if appium server is up & running

 netstat -an | grep 4723

Check if all dependencies of appium are working fine.

appium-doctor

As mentioned in the previous step, check if the build is succeeding after all the settings.
Now off you go to run a Robot test case.

Sample Robot Framework Test case

 Copy the below test case to a text file.

*** Settings ***

Library           AppiumLibrary

*** Variables ***
${REMOTE_URL}     http://127.0.0.1:4723/wd/hub      # URL to appium server
${PLATFORM_NAME}    iOS
${PLATFORM_VERSION}    10.2
${DEVICE_NAME}    iPhone Simulator
#Appium uses the *.app directory that is created by the ios build to provision the emulator.
${APP_LOCATION}        /Users/shivaram/Library/Developer/Xcode/DerivedData/WebDriverAgent-brdadhpuduowllgivnnvuygpwhzy/Build/Products/Debug-iphonesimulator/IntegrationApp.app
${BUNDLE_ID}         com.facebook.IntegrationApp-testnblog

*** Keywords ***
Open App
     Open Application    ${REMOTE_URL}    platformName=${PLATFORM_NAME}    platformVersion=${PLATFORM_VERSION}    deviceName=${DEVICE_NAME}      app=${APP_LOCATION}       automationName=appium            bundleId=${BUNDLE_ID}
Close All Apps
     Close All Applications

*** Test Cases ***
test_demo
     Open App
     Close All Apps

platformVersion – iPhone Simulator version.

app – The app location in your Server. It would be in DerivedData directory. Find your app in similar directory.

bundleId – Bundle Identifier given in the Xcode.

For now concentrate on passing the test case with the data given here.

How to run the test case?

 From cli, go to the directory where you have saved your test case file.

Then execute the following command.

 pybot test_ios_app.txt

test_ios_app.txt is the test case file.

Let me know what happened? Did your test case pass?

Now you are all set to dive deeper to test an app. Happy testing!!!!

If the test case failed, let me know what happened. Perhaps we can debug together.

For a video tutorial of this, you can refer to https://www.youtube.com/watch?v=ySglJIrDVMQ&t=2224s
This has a neat explanation of all the steps.
Enjoy!!!

 

Hi there. I'm Shivaram. Security & Network Professional with around 10+ years of experience. Here on this blog to share all my testing related experience. I'm a problem solver & key to that is to come up with the right questions. Of course we then have Google for all the answers.

6 thoughts on “Appium up & running with Robot Framework – iOS

  1. Hii Shivaram,

    The context provided for Appium up & running with Robot Framework – iOS was really helpful to me. My setup is working and app is interacting with appium. Thank to you 🙂
    I want to start writing script using Python. Any good document do you have which i can refer to start writing my script ? What assert i have write for the script ? If i am using eclipse do i have to integrate with appium ? How to use asserts & XC element. Can you guide me ? That will be really helpful for me

    1. For python you can refer to any online tutorials. To start off with you can refer to w3resource.
      Also Appium library for robot has most of the keywords for running any scenarios. If there are no keywords then you can think about writing a library in python.

  2. Hi Shivaram,

    I am getting the ff error when trying to run “npm install -g deviceconsole” in MacOS 10.12 using Xcode 9

    > deviceconsole@1.0.1 install /usr/local/lib/node_modules/deviceconsole
    > make

    Making deviceconsole…
    ld: framework not found MobileDevice
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    make: *** [all] Error 1
    npm ERR! code ELIFECYCLE
    npm ERR! errno 2
    npm ERR! deviceconsole@1.0.1 install: `make`
    npm ERR! Exit status 2
    npm ERR!
    npm ERR! Failed at the deviceconsole@1.0.1 install script.
    npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

  3. Hi Shivaram!
    Greetings!
    Excelent your guide for setting up Robot Framework on Appium in iOS.
    I hope you can help me with the unsuccessful running of the demo test you show in the tutorial. I have everything set up for iOS, and checked every step twice. But I’m going crazy trying to figure out what’s wrong since I’m not getting my App to open and close as I set it up. I made the neccesary changes on the configurations in order to use the App I want to automate but I get a FAIL every single time. And I couldn’t find any solution as of now. I’m gonna leave the log that the console shows me:
    For security reasons i will replace the name of the app for another name in every place that I know it has to be entered.
    test_demo [HTTP] –> POST /wd/hub/session {“capabilities”:{“alwaysMatch”:{“platformName”:”iOS”},”firstMatch”:[{}]},”desiredCapabilities”:{“deviceName”:”iPhone Simulator”,”app”:”/Users/vickor/code/SampleApp.app”,”platformVersion”:”10.3″,”platformName”:”iOS”,”automationName”:”appium”,”bundleId”:”com.MyProject.SampleApp”}}
    [debug] [MJSONWP] Calling AppiumDriver.createSession() with args: [{“deviceName”:”iPhone Simulator”,”app”:”/Users/vickor/code/SampleApp.app”,”platformVersion”:”10.3″,”platformName”:”iOS”,”automationName”:”appium”,”bundleId”:”com.MyProject.SampleApp”},null,{“alwaysMatch”:{“platformName”:”iOS”},”firstMatch”:[{}]}]
    [debug] [BaseDriver] Event ‘newSessionRequested’ logged at 1507750414548 (16:33:34 GMT-0300 (-03))
    [Appium] Requested iOS support with version >= 10, using XCUITest driver instead of UIAutomation-based driver, since the latter is unsupported on iOS 10 and up.
    [Appium] Creating new XCUITestDriver (v2.51.1) session
    [Appium] Capabilities:
    [Appium] deviceName: ‘iPhone Simulator’
    [Appium] app: ‘/Users/vickor/code/SampleApp.app’
    [Appium] platformVersion: ‘10.3’
    [Appium] platformName: ‘iOS’
    [Appium] automationName: ‘appium’
    [Appium] bundleId: ‘com.keenvil.SampleApp’
    [BaseDriver] Session created with session id: 1d11fab8-6649-461b-b773-18a29736c3a3
    [debug] [XCUITest] Xcode version set to ‘8.3.3’ (tools v9.0.0.0.1.1504363082)
    [debug] [XCUITest] iOS SDK Version set to ‘10.3’
    [debug] [BaseDriver] Event ‘xcodeDetailsRetrieved’ logged at 1507750414572 (16:33:34 GMT-0300 (-03))
    [debug] [XCUITest] Changing deviceName from ‘iPhone Simulator’ to ‘iPhone 6’
    [iOSSim] Constructing iOS simulator for Xcode version 8.3.3 with udid ‘C006FB73-7C97-4890-BCBD-B0B7664CBDA7’
    [XCUITest] Determining device to run tests on: udid: ‘C006FB73-7C97-4890-BCBD-B0B7664CBDA7’, real device: false
    [BaseDriver] Using local app ‘/Users/vickor/code/SampleApp.app’
    [debug] [BaseDriver] Event ‘appConfigured’ logged at 1507750414736 (16:33:34 GMT-0300 (-03))
    [debug] [XCUITest] Checking whether app ‘/Users/vickor/code/SampleApp.app’ is actually present on file system
    [debug] [XCUITest] App is present
    [debug] [BaseDriver] Event ‘resetStarted’ logged at 1507750414736 (16:33:34 GMT-0300 (-03))
    [XCUITest] Not scrubbing third party app in anticipation of uninstall
    [debug] [BaseDriver] Event ‘resetComplete’ logged at 1507750414801 (16:33:34 GMT-0300 (-03))
    [debug] [iOSLog] Starting iOS 10.3 simulator log capture
    [debug] [iOSLog] System log path: /Users/vickor/Library/Logs/CoreSimulator/C006FB73-7C97-4890-BCBD-B0B7664CBDA7/system.log
    [debug] [BaseDriver] Event ‘logCaptureStarted’ logged at 1507750414877 (16:33:34 GMT-0300 (-03))
    [XCUITest] Setting up simulator
    [debug] [iOS] No reason to set locale
    [debug] [iOS] No iOS / app preferences to set
    [debug] [iOSSim] The count of running Simulator UI client instances is 0
    [debug] [iOSSim] Killing all iOS Simulators
    [debug] [iOSSim] Simulator is not running. Continuing…
    [iOSSim] Starting Simulator UI with command: open -Fn /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app –args -CurrentDeviceUDID C006FB73-7C97-4890-BCBD-B0B7664CBDA7 -ConnectHardwareKeyboard 0
    [debug] [iOSSim] The count of running Simulator UI client instances is 1
    [iOSSim] Simulator with UDID C006FB73-7C97-4890-BCBD-B0B7664CBDA7 booted in 15 seconds
    [debug] [BaseDriver] Event ‘simStarted’ logged at 1507750430855 (16:33:50 GMT-0300 (-03))
    [debug] [XCUITest] Reset requested. Removing app with id ‘com.MyProject.ironthrone’ from the device
    [debug] [XCUITest] Installing ‘/Users/vickor/code/SampleApp.app’ on Simulator with UUID ‘C006FB73-7C97-4890-BCBD-B0B7664CBDA7’…
    [debug] [XCUITest] The app has been installed successfully.
    [debug] [BaseDriver] Event ‘appInstalled’ logged at 1507750437252 (16:33:57 GMT-0300 (-03))
    [XCUITest] Using WDA path: ‘/usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent’
    [XCUITest] Using WDA agent: ‘/usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent/WebDriverAgent.xcodeproj’
    [debug] [XCUITest] Capability ‘useNewWDA’ set to false, so trying to reuse currently running WDA instance at ‘http://localhost:8100/’
    [debug] [JSONWP Proxy] Proxying [GET /status] to [GET http://localhost:8100/status%5D with no body
    [debug] [XCUITest] WDA is not listening at ‘http://localhost:8100/’. Rebuilding…
    [debug] [BaseDriver] Event ‘wdaStartAttempted’ logged at 1507750437256 (16:33:57 GMT-0300 (-03))
    [XCUITest] Launching WebDriverAgent on the device
    [debug] [XCUITest] Carthage found: ‘/usr/local/bin/carthage’
    [debug] [XCUITest] Killing running processes ‘xcodebuild.*C006FB73-7C97-4890-BCBD-B0B7664CBDA7, iproxy 8100, C006FB73-7C97-4890-BCBD-B0B7664CBDA7.*XCTRunner’ for the device C006FB73-7C97-4890-BCBD-B0B7664CBDA7…
    [debug] [XCUITest] ‘pgrep -nif xcodebuild.*C006FB73-7C97-4890-BCBD-B0B7664CBDA7’ didn’t detect any matching processes. Return code: 1
    [debug] [XCUITest] ‘pgrep -nif iproxy 8100’ didn’t detect any matching processes. Return code: 1
    [debug] [XCUITest] ‘pgrep -nif C006FB73-7C97-4890-BCBD-B0B7664CBDA7.*XCTRunner’ didn’t detect any matching processes. Return code: 1

    I hope you can help me to solve this issue!!!
    Best Regards!

    Vic

  4. Hi Shivaram,

    is the webdriver Agent setup is a one time process or do i need to set it up each and everytime when i restart the PC ?

    Also do i need to run the Webdriver integration App on background everytime ?

  5. If appium-doctor is not installed, you can install it using the command “npm install -g appium”
    should be:
    If appium-doctor is not installed, you can install it using the command “npm install appium-doctor -g”

Leave a Reply