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 applications are a new window to user solutions across businesses. With every user need shifting to mobile, the numbers of mobile apps are increasing. Therefore, the increasing competition to deliver quality apps is on the rise.
Testing mobile applications is 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 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 framework 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
- Ensures 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
- Provides Platform and application independence
- Supports standard and external libraries for test automation
- Allows tagging to categorize and select test cases for execution
- Provides easy-to-read reports and logs in the HTML format
Setup of the Robot Framework
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
Following are the key features of Appium:
- No requirement of recompilation or modification of app to be tested
- No need of an application source code
- Easy-to-write tests across any language using any framework
- Standard automation specification and API
To use Appium library with Robot framework for mobile application 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.
Example of Robot Framework Appium Library
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. This 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.