THE XORIANT BLOG

Robot Framework For Mobile Test Automation

The first rule of any technology used in a business is that automation applied to an efficient operation will magnify the efficiency. The second is that automation applied to an inefficient operation will magnify the inefficiency.

-Bill Gates

Mobile Apps are a new window to user solutions in IT. With every user need shifting to mobile, the numbers of mobile apps are increasing, therefore increasing the competition to deliver quality apps. Testing mobile apps is thus becoming a key process before rolling out app releases to users. Hence, mobile test automation is the need of the hour, to facilitate thorough testing of mobile apps efficiently and in less amount of time.

Robot framework is an open source test automation framework used for Acceptance-Test Driven Development (ATDD) implemented using python. It has an ecosystem which consists of various test libraries and tools that adhere to the keyword driven approach of robot framework. One of the external test libraries for mobile test automation is Appium Library which uses Appium to communicate with android and iOS applications. This blog is a walkthrough of how robot communicates with appium to bring out the best of robot framework and appium to mobile test automation with the help of a demo on running a test suite for testing a basic android application.

Robot framework

Robot Framework is a generic test automation framework released under Apache License 2.0. Robot has standard test libraries and can be extended by test libraries implemented either with Python or Java.

Key Features of Robot Framework

Business Keyword driven, tabular and easy to understand syntax for test case development

Allows creation of reusable higher-level keywords from the existing keywords

Allows creation of custom keywords

Platform and application independence

Support for standard and external libraries for test automation

Tagging to categorize and select test cases to be executed

Easy-to-read reports and logs in HTML format

Setup

Robot framework requires installation of the following on the system:

Java (JRE and JDK)

Python

Robot framework package (pip install)

Python IDE (PyCharm)

Appium Library

Appium Library is one of the external libraries of robot framework for mobile application testing which only supports Python 2.x. It uses Appium (version 1.x) to communicate with Android and iOS applications. Here most of the capabilities of Appium are framed into keywords, which are easy to understand and help understand the purpose of the test case by reading the script.

Key Features of Appium

No recompilation or modification of app to be tested is required

App source code is not needed

Tests can be written in any language using any framework

Standard automation specification and API

Setup

To use appium library with robot framework for mobile app test automation requires installation of the following on the system:

Node js

Robot framework appium library package (pip install)

Appium Desktop Client (Appium Server)

Android SDK (For Android apps)

Xcode (For iOS apps)

Robot – Appium Interaction

A basic flow of robot framework’s interaction with the application under test is illustrated in the following diagram.

Fig 1: Interaction of robot framework with the application under test

Test Suites consisting of test cases written using robot’s keyword-driven approach are used to test the mobile application (Android/iOS). Appium server, robot’s Pybot and Appium-Python Client play a significant role in this interaction.

Appium Server – Appium is an open source engine running on Node.js. It is mainly responsible for the interaction between the app’s UI and robot’s appium library commands. It needs to be up and running to facilitate this interaction.

Pybot – This is a robot framework module used to trigger the test scripts written in Robot framework format. Pybot reads the different framework files from framework’s code base and executes the tests by interacting with Appium Library. On completion of test case/suite execution, pybot generates report and log files with complete details of the test run.

Appium-Python Client – Appium-Python Client facilitates the interaction between appium library and appium server using JSON Wire Protocol. This client initiates a session with the appium server in ways specific to appium library, resulting in a POST /session request to the appium server, with a JSON object. The appium server then starts an automation session and responds with a session ID. This session ID is used in sending further commands to the server.

This is illustrated in the below flow diagram.

Fig 2: Flow Diagram of Robot – Appium Interaction

Example

The following example is for testing the Calculator App on an Android device using robot framework’s appium library.

Test Suite

A test suite is a .robot file which can be written and executed using a python IDE. The basic skeleton of a test suite written using robot framework’s syntax consists of the following sections.

Variables – This section consists of all the variable declarations for the variables used in the test suite. (Fig 4)

Keywords – This section consists of the higher level keywords formed using in built keywords from robot’s standard libraries and appium library. (Fig 5)

Test Cases – This section consists of all the test cases that belong to the test suite. (Fig 5)

Fig 4: Settings and Variables section of test suite

Fig 5: Keywords and Test Cases section of test suite

UIAutomator

UIAutomator is a tool used to obtain the locators of all the elements on a particular android application. It is a part of the android SDK. The locators in the form of xpaths were obtained using UIAutomator for the calculator app (Fig 6)

Fig 6: UIAutomator screenshot for Calculator App for Android

Test Reports and Logs

The above test suite can be executed using the following command on python terminal:

pybot -d Results\TestSuite TestSuite.robot

On execution of the test suite, report and log files are created in the form of HTML documents. These files have a detailed summary of the test case execution and all the necessary statistics related to the test case execution. (Fig 7, 8)

Fig 7: Report of the execution of Test Suite for Calculator App

Fig 8: Log of the execution of Test Suite for Calculator App

In conclusion, the appium library of robot framework facilitates automation of test cases for mobile applications with a simple tabular syntax, which is easy to read and is platform independent, without altering the source code of the application under test. The keyword driven approach of robot framework ensures the reusability and readability of the test cases, thus making the automation framework robust and tester friendly.

5 comments

Hi Sayalee,
I have gone through the Robot framework Mobile automation scripts on your blog and it looks very impressive.
Could you please help me how to install and launch .APK file through robot framework
Regards
Raj..

Hi Raj, you can use the following keywords to install and launch apps:

Install Application
[Documentation] Installs the application using package name and the physical path of your apk. You need to store the apk in some folder in your project structure.
Install App Path_To_Your_APK_File_In_Project_Structure Your_Package_Name

Hii Sayalee,
I went through your document its very good written. I want to automate Native app for iOS & Android using Python with Robot Framework. Do i require to write any script ? Or can i start my automation using the information which you have provided in your blog ?