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.
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 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
Robot framework requires installation of the following on the system:
- Java (JRE and JDK)
- Robot framework package (pip install)
- Python IDE (PyCharm)
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
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.
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.
The following example is for testing the Calculator App on an Android device using robot framework’s appium library.
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.
- Settings – This section consists of the test suite documentation, imports of libraries and resource files, suite and test level setup and teardown. (Fig 4)
- 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)
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)
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)
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.