Robotframework Android Automation

Introduction

This is going to be a very quick tutorial to demonstrate that Robotframewok can be used to automate Android based smart phone applications. In this tutorial we are going to use Robotframework Android library which sits on top of Calabash Android framework. I tried it myself and was able to make it run however the downside is that it was not as reliable as I was expecting. For example, the setup procedure is flaky and takes time but I think it can be solved by separating the setup part from the test case part. The part that I did not personally like is clicking on text was not working consistently which is bad. Before we start I would like to repeat by saying I did not put much time on this experiment and I can not be so sure if the “not so good” results I got were because of the tools stack selection or were just my own mistakes. I would leave it to the reader to explore it more. The idea is to show that Robotframework is such an amazing automation tool that can be extended to do all kinds of test automation. As far as Android automation is concerned one can try other tools for example Robotium, Monkey Runner or even Sikuli. Let us get started by following the steps below:

Installation

  1. I am assuming Windows 7 operating system
  2. I assume you have Robotframework and RIDE already installed. For detailed information about installing these tools please refer to the following post
  3. Install Robotframework Android library:
  4. Robotframework Android library is based on Calabash Android which is in turn based on Ruby. You can get Ruby from here
  5. Add Ruby bin directory to your path environment variable for example:
  6. Install Calabash Android:
  7. Install Android SDK. You can get it from here
  8. Set the environment variable ANDROID_HOME and make it point to android SDK for example:
  9. Add JDK bin directory to path environment variable for example:
  10. Download zip command for windows from here and save it into some directory that is included in system path
  11. Create a key store which is used in signing JAR files:
  12. For some reason I got an error while resigning the android APK file. I fixed that by removing:

    from:

    as I mentioned earlier this is nothing but an experiment and I did not invest enough time
    to see if this could have any side effects. I just wanted to get rid off the annoying error
    message.

Android SDK Commands

Behind the scenes Robotframework Android library and Calabash Android framework invoke commands provided by Android SDK. Take a look at the following commands in order to get a feeling of what they do. I am going to be using the ApiDemos.apk sample application. You can download the apk file from here

1. Make sure the following bat file exists:

2. To search for SDK updates:

3. To install updates apply:

where 1 and 2 are update numbers (you can get the numbers by applying the command in step 2)

4. Create an Android virtual device:

where android-8 is the target API number and force is used to overwrite existing configuration

5. Start emulator

no-wondow option is used to supress the GUI and run it heedlessly

6. Invoke Android Debug Bridge (adb command):

It is a command line tool that lets you communicate with an emulator instance or connected Android device. For more information about adb command click here.

7. If you want to download an installed app (in the form of an APK file) from emulator or device:

8. To unsign an APK file you can apply the command:

9. In order to resign an APK file:

10. To build an instrumentation app:

11. To uninstall the app:

12. To install the app:

where [C:\\robot\\suites\\apidemos] is some directory containing the sample APK file. In this case it is the same directory containing robotframework test suite while [test_servers] is the directory created by calabash Android when building the instrumentation app (in this case: myapp.apk)

Robotframework Syntax

Here is how the Robotframework test suite look like. Please note that the text was formatted to better fit in the page so if you just copy and paste, it might need minor editing to work with Robotframework. For example some long lines were broken into multiple lines:

Robotframework Android Library Keywords

Here is the full list of Robotframework Android library supported keywords.

Please use the comments section below for questions, corrections or feedback. Thanks for reading.

One Comment

Add a Comment

Your email address will not be published. Required fields are marked *