Appium up & running with Robot Framework

So, you want to start testing a mobile app using appium? Great idea!!

How the heck do you get started? What is the setup involved, tools required, etc?
I had the same questions when I started up & figured out things by looking around.
So decided to blog it, with all information in one place so that people can get started in no time.

I promise I’ll keep it simple & easy, anyways I’ll try.
Sounds good? Carry on.

What is the setup involved?

appium
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

 Hopefully everything went smooth with the Client Setup. With the server setup, the main step is the installation of Appium. For testing the app, the server needs to be directly connected to the mobile devices as shown in the diagram or simulators need to be run. We need vendor specific SDKs to run simulators.

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

Windows: The Appium executable for Windows can be downloaded from the link http://appium.io/downloads.html

Run the installer & once done, launch appium. Just make sure in the settings, the server address field is set to ‘0.0.0.0’ & port is set to ‘4723’.

Now start the service. To check if the service is running in windows, run the below command in DOS prompt.

 netstat -an | findstr “4723"

ii> Java JDK: Install the latest java idk. Google for ‘java idk download’ & install the latest jdk. This is a prerequisite for installing Android SDK.

iii> Android SDK:  In this blog we will concentrate on setting up our system for android app testing. Setting up just IOS SDK is for another day.

(For detail on IOS setup, check this blog)

Install the latest Android SDK from http://developer.android.com/sdk/index.html
The SDK is available both for OSX & Windows.
After installing the SDK, you need to set ANDROID_HOME to be our Android SDK path and add the tools and platform-tools folders to your PATH variable.

OSX:

You need to add the below 2 lines in your ~/.bash_login file.

Just make sure you add the correct path of Android SDK. In my case the path is /Users/shivaram/Documents/Android/sdk/

export ANDROID_HOME=/Users/shivaram/Documents/Android/sdk
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools

Windows:

If you are running appium using the exe, then the SDK path needs to be set as shown in the screenshot below.

2016-07-06-2

To set the tools & platform-tools path in Windows, check the below snapshot.

Follow the steps.
2016-07-06

 

Device Setup

 

Now we are done with the client & server setup. We just need a mobile device with the app installed which we need to test. Setting up emulators for both IOS & Android is for a different post.

For quickly testing your setup, let’s run a test case against a Android device.

As shown in the above diagram, we need to connect the Android device through USB cable to the server.

The prerequisite is to enable Developer options & enable USB debugging in your Android phone.

For steps to do that I would suggest you to google ‘How to enable Developer options & USB debugging in Android <version>’

There would be plenty of links which would assist you in getting this done. I won’t repeat the same steps here.

After you connect this Android device to the server through USB, a window would pop up in the mobile device asking to allow USB debugging, just make sure you click on ‘Always allow from this computer’.

That’s it, you are now set to test your app.

 

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

Run the below command to check the mobile devices connected.

 adb devices

Run the below command to check the app packages installed in the mobile device

 adb shell pm list packages -f

Check if appium server is up & running

 netstat -an | grep 4723

 Sample Robot Framework Test case

 Copy the below test case to a text file.

*** Settings ***

Library        AppiumLibrary

Documentation   demo for appium library

Force Tags      demo

 
*** Test Cases ***

test_demo

    [Tags]  regression

    Open Application  http://localhost:4723/wd/hub  platformName=Android  platformVersion=5.1.1  deviceName=fd1bee6e  app=com.android.browser  automationName=appium  appPackage=com.android.browser  appActivity=AddBookmarkPage

platformVersion – Mobile device android version.

deviceName – the name you got from the above ‘adb devices’ output.

app – The app name you get after executing the command ‘adb shell pm list packages -f’. In this example we are choosing the default browser app for testing.

appPackage – Will write a separate blog to find the package name

appActivity – Will write a separate blog to find the Activity name.

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_andoid_app.txt

test_android_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.

 

Cheers.

 

Few Related posts

How to setup android virtual devices(AVD)(Emulator) for Android test automation:

 

Structure for Appium Test Cases – Robot Framework

 

uiautomatorviewer – To find Element IDs or xpath for Android Apps

 

Testing Android App – How to find out the CPU & Memory utilisation of the device?

 

 

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.

65 thoughts on “Appium up & running with Robot Framework

  1. Hi,

    I am working on appium with robot framework. I am new to both.
    I am seeing the following error, while using clickElement. Seems like this error comes when a locator is identified.

    Clicking element ‘xpath=/html/body/ion-app/ng-component/ion-nav/ng-component/ion-content/div[2]/div/ion-row/button’.
    FAIL KeyError: ‘platformName’.

    Please help.

    I use the following.

    AppiumLibrary.Open Application http://localhost:4723/wd/hub platformName=Android platformVersion=5.0.2 deviceName=device autoWebview=true newCommandTimeout=300 appPackage=com.ionicframework.leanion485543 appActivity=com.ionicframework.leanion485543.MainActivity

    appium version 1.4.13.1

    1. Hi Gomathi –

      Hopefully you had set the correct deviceName in your script.
      I cannot make out any issue with the lines you have mentioned in your message.
      Would you be able to send me the entire or relevant part of your script to look at it further?

      Shivaram

      1. Hi ,

        THis is my code

        @{context}= AppiumLibrary.Get Contexts
        MinWait
        AppiumLibrary.Switch To Context WEBVIEW_com.ionicframework.leanion485543
        MinWait
        AppiumLibrary.Click Element xpath=/html/body/ion-app/ng-component/ion-nav/ng-component/ion-content/div[2]/div/ion-list/ion-item/ion-checkbox

        Log:

        Documentation:
        Click element identified by `locator`.
        Start / End / Elapsed: 20170110 15:44:37.250 / 20170110 15:44:37.250 / 00:00:00.000
        00:00:00.000KEYWORD BuiltIn . No Operation
        Documentation:
        Does absolutely nothing.
        Start / End / Elapsed: 20170110 15:44:37.250 / 20170110 15:44:37.250 / 00:00:00.000
        15:44:37.250 INFO Clicking element ‘xpath=/html/body/ion-app/ng-component/ion-nav/ng-component/ion-content/div[2]/div/ion-row/button’.
        15:44:37.250 FAIL KeyError: ‘platformName’

        1. Hi –
          This is not looking like a script issue.
          Is the app opening up in your Android device through the script?
          Are there any other calls to the android device which are passing before this in your script?

          Shivaram

          1. Just before this keyword, can you add the below keywords in your Robot test case
            Capture Page Screenshot
            Close Application

            If it works fine & fails at the earlier line, then please send the report.html & output.xml files.

  2. Hello All
    I am using Robot framework – appium library with appium server for automation on Mac Os Sierra, when i am running the application on Appium inpector (simulator) i am facing slowness in running a simple test cases suite , can anyone suggest me to run the tests with a good rate of time for executions .

  3. I am looking for a way to write scripts so that I can run same set of scripts for iOS and Android. I understand that Android and iOS has different argument for appium on Robot Framework (Also, device name, appPackage etc will be different). How can I write some if/else condition so that I determine if the simulator is Android then run xyz keywords but if the simulator is iOS then run abcd keywords? Please let me know if any of you has some approach in mind.

    1. Hello Prameet –

      Interesting problem.
      What you are looking is desired capabilities for appium. You can google it, you will get more information on it.

      Copying a snippet of information from appium.io website.

      “Desired Capabilities
      Desired capabilities are a set of keys and values (i.e., a map or hash) sent to the Appium server to tell the server what kind of automation session we’re interested in starting up. There are also various capabilities which can modify the behavior of the server during automation. For example, we might set the platformName capability to iOS to tell Appium that we want an iOS session, rather than an Android or Windows one. Or we might set the safariAllowPopups capability to true in order to ensure that, during a Safari automation session, we’re allowed to use JavaScript to open up new windows. See the capabilities doc for the complete list of capabilities available for Appium.”

      Will write a pseudo code here.

      #Android
      Open Application http://localhost:4723/wd/hub platformName=Android platformVersion=5.1.1 deviceName=fd1bee6e app=com.android.browser automationName=appium appPackage=com.android.browser appActivity=AddBookmarkPage

      # ios
      Open Application http://localhost:4723/wd/hub platformName=iOS platformVersion=8.1 deviceName=iPhone Simulator app= automtionName=appium

      Run Keyword If ‘${platform}’==’iOS’

      Also can checkout
      Run Keyword Unless

      1. Thanks a lot for your reply. I found something online. I started implementing the stuff using “–variable env:iOS or env:Android” and it works fine for me. Though, I have separated my iOS and Android keywords and I import those keywords using “Resource Keywords.txt” in test suite.

  4. Hi Shivaram! I am following your steps but I am unclear on adding the paths to the bash_login. After installing the Android SDK I have a folder in my user folder called AndroidStudioProjects… /Users/davidmontgomery/AndroidStudioProjects

    So does that mean my entries would be?? Look forward to your reply

    export ANDROID_HOME=/Users/davidmontgomery/AndroidStudioProjects
    export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools

    1. Hello David –

      How are you doing?
      Yes, if the above folder contains the robotframework-appiumlibrary binary, that would be correct.
      If not, there might be a folder called sdk, just check inside it.

      My folder contains these files.

      Shivaram:sdk shivaram$ pwd
      /Users/shivaram/Documents/Android/sdk
      Shivaram:sdk shivaram$ ls
      SDK Readme.txt extras platforms system-images
      add-ons licenses robotframework-appiumlibrary tools
      build-tools platform-tools skins

  5. Hello,
    Query regarding Appium + Robot Framework. set up.
    I have completed the client and server set ups successfully.For device setup – adb devices and adb shell pm list packages -f are fine too. While executing netstat -an | grep 4723 , im getting the error – ‘grep’ is not recognized as an internal or external command,. Could you please help on this.

    Thanks,
    Siva

  6. Hi Shivram,
    I executed few test in android app and its working fine. When i try to execute the same in native browser or chrome browser in emulator, i could see the below error.
    1.Browser keep launching and closing . Am i wrong in below code. Please comfirm

    Open Application http://localhost:4723/wd/hub platformName=Android platformVersion=6.0.0 deviceName=192.168.201.101:5555 appPackage=com.android.chrome appActivity=org.chromium.chrome.browser.ChromeTabbedActivity

    Thanks,
    Siva

      1. Hi Shivaram, Go To Url is working fine. Could you please help the way to identify the locator in the mobile browsers?

        Thanks

          1. Hi,

            UIautomatorview, i could find elements ID for app . I need way to find the elements that are in the chrome browser in the android devices.

            Thanks

          2. I believe you are talking about the locators in a web application. I haven’t tried this. Have you done Selenium automation?
            In the computer find the xpath of the same location using Firebug or Developer tools and use that in your test case. Check if it works.

  7. Thanks Shivaram I can find the locators with the help of firebug or developer tools for the web application. I’m just trying to find the elements in the chrome browser in the mobile devices.

    Thanks again.

  8. Hi another query
    .
    Below is my code to invoke chrome browser and launch a website. When i run this from robot framework, chrome browser launched with data:, as in the address bar and the browser gets closed and relaunced again and again. Can you please help me to overcome this issue
    Open Application http://localhost:4723/wd/hub platformName=Android platformVersion=6.0.0 deviceName=192.168.188.101:5555 appPackage=com.android.chrome appActivity=org.chromium.chrome.browser.ChromeTabbedActivity
    Close All Application

    Please click this link to view the recordings – https://app.hyfy.io/v/ab6mdKWXQi/

    Can you please help me on this

    Thanks

  9. Hi Shivaram,

    Thanks. Here we can launch the recordings in the chrome. I’m pasting the code below

    Testcase_07_Browser
    [Documentation] Launch browser – gmail
    Open Application http://localhost:4723/wd/hub platformName=Android platformVersion=6.0.0 deviceName=192.168.188.101:5555 appPackage=com.android.chrome appActivity=org.chromium.chrome.browser.ChromeTabbedActivity

    Go To Url http://gmail.com

  10. From the log I can see that the chrome browser is not getting launched. But you seem to see that chrome is getting closed & reopened again. I’ll try to run the same test case & check it out. Will let you know.

  11. Hi Shivaram,

    I am basically working on Mobile Hybrid application in an Organisation with Hybrid Mobile application.
    I have many challenges in automating this app, especially using locators and performing events in Robot Framework.
    Since this app is existing since 2 years and don’t have developer support. Which means ATDD automation we are tying to perform.
    So please help me on this..

    I am struck with Scroll functions, can you provide more examples on Scroll, Scroll Down and Scroll Up keyword correct examples

    Thanks in Advance.

      1. Thanks Shivaram,

        I tried using below keyword and its works well for me.

        :FOR ${i} IN RANGE 1 16
        \ Long Press Keycode 67

  12. Testing failed with below msg, pls advise:

    [ WARN ] Keyword ‘Capture Page Screenshot’ could not be run on failure: No application is open
    test_demo | FAIL |
    WebDriverException: Message: A new session could not be created. (Original error: ‘java -version’ failed. Error: Command failed: C:\WINDOWS\system32\cmd.exe /s /c “java -version”
    ‘java’ is not recognized as an internal or external command,
    operable program or batch file.
    )

  13. Hi Shivaram,

    How to execute multiples android mobile devices using single script in robot framework, please suggest

    Thanks in Advance
    Dominic L

  14. Thanks for such a excellent blog… I was installing from last 2 days from different links but got fail. But this article help me a lot and i am able to run my first test case on appium. Thnx a lot. 🙂

  15. Hi Shivaram,

    Thank you sharing. Could you tell me how to run the test with multiple devices at the same time? Thanks!

      1. Yes, exactly. I’ve been trying to do that but still stuck with one device. Looking forward to your next update! Thank you so much!

  16. Dear Shivaram Subramanya, I am new to Robotframework and Appium. Can u plz guide me how to check the status of checkbox if it is checked or uncheck?

  17. Hi Shivaram,

    Thanks for the supper helpful writing. I have followed your instructions and manage to run the demo code.
    Unfortunately, I am not able to interact with any web elements in the android browser. Do I need any additional setup/configuration for this?

    For example: I tried the following steps:
    1. Open the android browser —–> passed
    2. Open http://facebook.com URL ——> passed
    3. Wait for the email input field to load ——-> failed
    4. Input email id into the email field ——> failed
    5. …….and so on ——–> all failed

    Bellow are my demo code:

    *** Settings ***

    Library AppiumLibrary

    Documentation demo for appium library

    Force Tags demo

    *** Test Cases ***

    test_demo

    [Tags] regression

    Open Application http://localhost:4723/wd/hub platformName=Android platformVersion=5.1.1 deviceName=Nexus-4-API-22 app=com.android.browser automationName=appium appPackage=com.android.browser appActivity=BrowserActivity

    Go To Url http://facebook.com
    Sleep 5
    Wait Until Page Contains Element xpath=//input[@type=’email’]
    Input Text xpath=//input[@type=’email’] test@gmail.com

    Can you help me out with this? I am badly stuck here for days but could not find an solution.
    Thanks in advance.

  18. Hi Shivaram,

    Here’s the good news. Finally I was able find a solution. I just changed the open application string as follow and it worked:

    Open Application http://localhost:4723/wd/hub platformName=Android platformVersion=5.1.1 deviceName=Nexus-4-API-22 app=com.android.browser browserName=Browser

  19. It is important to say that you were using python version from the system. This is not recommendable. I didn’t know it and now I had to go through various problems trying to install different python packages, I recommend to install python2 from “brew install python2” command and then make it your default environment. It will avoid a lot of compatibility problems and if you have to do modifications you will not modify system’s python.

  20. Hi Shivaram, Any idea how to capture toast messages in Android and validate them using Appium+Robot framework? In UIAUTOMATORVIEWER toast messages are not captured. Thanks in advance.

Leave a Reply