Mobile application automation testing using Appium
Due to the increasing volume of mobile applications in development, we’ve seen a great number of tools for testing them appearing on the market. People involved in software testing try to find a tool that could be used to test as many functionalities of these apps as possible. The process of choosing the right solution can be difficult because of the growing market requirements and high expectations of customers. In our work, we use Appium mainly thanks to its cross-platform nature that enables the creation of test scripts on iOS and Android platforms using the same API.
What is Appium?
Appium is an open-source tool for automated testing of web, native, and hybrid applications. The Appium cross-platform nature allows writing tests on iOS and Android platforms using the same API. Thanks to the server-client architecture, a client written in any language can be used to send appropriate HTTP requests to the server.
In Appium, a web server using REST API receives connections with the client, listens for commands, and also executes them on a given mobile device. The results of executing a given command are visible thanks to the reaction to HTTP responses. Not having to recompile the application for automation is a big advantage of this tool. Moreover, due to the widespread use of Selenium WebDriver, Appium has extended its API with specific methods of testing mobile applications (e.g. MobileElement, AndroidElement, IOSElement).
Automated tests in Appium: an example
The example I will present here is an automated test in the Gmail application, which adds an existing e-mail address. Using the Appium tool to write automated tests requires the following tools:
- Java,
- Android SDK,
- Appium,
- A device or an emulator with Android or iOS (connect the physical device to the computer using a USB cable or WiFi),
- An application to test.
The device on which I carry out tests is an emulator created in Android Studio, running on Android version 10.0. In the Android Studio tool, we create a new project where we define the connection parameters to the Appium server. Then we initialize the Appium driver.
When creating automated tests, we use the Page Object Model (POM) scheme. While writing scripts, testers often encounter problems related to the changes in the tested software. To facilitate the process of creating scripts and prevent such problems, it is worth using the Page Object Model pattern. This scheme separates the elements and methods on the page from the tests. Thanks to this approach, the tests are easier to implement and much simpler to maintain later on.
The class where we initialize elements and perform operations on them:
Each test ends with an assertion checking whether the condition has been met. The test class is as follows:
To run the test, we use the @Test annotation from the TestNG library.
Each test is reported using Extent Reports. This is a fully customizable HTML report that can be integrated with Selenium WebDriver.
Thank You
Harpreet Singh
Sr Software Engineer-QA
Senior Associate at PwC
3yGood job Harpreet