Appium — Mobile App Automation
Mobile App Automation with Appium | Part 1
It is a well-known fact today that the numbers of platforms and device types are more varied now than ever before. Customers continue to demand the latest devices, features and functionality, as well as increased mobility and accessibility. In parallel, the demand for mobile applications is also tremendously increasing, as mobile applications are very handy for customers. In response to the consumer’s demand, most of the enterprises are converting their websites into respective mobile applications.
When it comes to mobile industry, user behavior also needs to be considered. The average smartphone user spends 3 hours and 10 minutes each day using their device. About 2 hours and 51 minutes of this time is spent on apps (apps account for roughly 90% of smartphone usage). Based on the researches, there are 80+ apps installed on the average smartphone. But with that said, people aren’t using all of those apps.
The average person uses 9 mobile apps per day and 30 apps per month. If the average smartphone user has 80 apps on their phone, this means that more than 62% of those apps don’t get used every month.
What does this mean? It’s simple. People are downloading apps and not using them. In fact, 25% of apps are used only once after being downloaded, and then never used again. There might be some other personal reasons, however it is mostly related with the failure/bug or performance issues. Based on the statistics of “The App Attention Index” 60% of people have deleted an app or leave a website after just one attempt to use it, if there were problems with performance, and a total of 80% will eventually delete an app if problems continue.
At this point, mobile testing comes into the picture and plays a vital role regarding mobile app development. At early stages of the testing, test scenarios were mostly manually executed on real devices or emulators by executing the all expected behaviors with different scenarios. This approach is still used with shorter release cycles if there are enough experienced manual testers available. However, after a certain number of releases those scenarios become even larger, and it becomes hard to execute manually as it requires more human intervention. Besides, with complex features, which requires complex algorithm logic or calculations that prone to human error, it is also hard to execute it manually in order to ensure the best quality application in the market. This has led to the rise of Mobile Automation Testing. A stable Mobile Automation Testing framework ensures the testing time is reduced considerably with high quality of testing. Naturally, there is a growing demand for more efficient and cost-effective testing across all platforms. As a result of this, the workload of developers, and especially testers, has greatly increased.
Currently, there are a wide range of mobile automation testing tools and frameworks available and user can select any of them depending on their requirements. Among these tools, Appium has become one of the most favored tool for mobile automation testing.
In this article, I will try to cover the following topics:
- What is Appium?
- Why Appium?
- Appium architecture
- How Appium works? On Android and on iOS devices?
What is Appium?
Appium is an open-source tool for automating native, mobile web, and hybrid applications on iOS mobile, Android mobile, and Windows desktop platforms.
The apps that are written using the traditional iOS, Android, or Windows SDKs are known as native applications. The web applications that can be accessed using a mobile web browser are known as Mobile web applications. For instance, Appium supports Chrome on Android and Safari on iOS. Applications that encapsulates the native control-web-view for interacting with the web content are known as Hybrid Apps. Hybrid applications merge the best of native and web applications. While these applications can be downloaded from the play store and can also access all the features of the device. They are web applications written in HTML5, CSS and JavaScript, wrapped inside native containers. This allows them to run on any platform.
Why Appium?
In order to find the exact and unbiased answer to that question a lot of time has been invested on the internet, forums and seminars /webinars. I will try to summarize all these points based on my experience.
As can be seen from the chart and statistics above that it is one of the most popular testing tools for mobile apps in the market. Depending on the project and company needs it might differ, however the aim of this article not to prove that Appium is the only option, rather it will be discussed that how Appium works and what kind of advantages it might offer to us.
Please find below most important advantages of the Appium.
- It is open source and has a huge community support.
- Opens the door to cross-platform mobile testing, which means the same test would work on multiple platforms.
- Provides support to Native application, Hybrid application and Web Browsers on mobile.
- Support major programming languages such as Java, Python, C#, Ruby, Javascript, PHP etc.
- Integrates seamlessly with Continuous Integration tools such as Jenkins, Bitrise, CircleCI, Perfecto.
- Your test code can run on emulators, simulators, real devices and cloud based mobile automation services such as AWS Device Farm, BrowserStack, Sauce Labs, TestProject etc.
- Unlike native mobile automation frameworks like XCUITest and Espresso, it runs on a built application file, which doesn’t require to recompile the application code in order to run tests.
- Your automation programming language is not dependent on your developer’s programming language. This makes it very flexible for the automation testers. For instance: Your developer has written Android/iOS application in Flutter, or Android application with Kotlin and/or iOS application with Swift, but you are comfortable with Java. No problem!!
Importantly, Appium is “cross-platform”: it allows you to write tests against multiple platforms (iOS, Android, Windows), using the same API. This enables code reuse between iOS, Android, and Windows testsuites.
Appium Architecture? | How Appium works?
At the core, Appium is an HTTP server written in nodejs that exposes REST API. The client communicates with Appium server via REST API’s, and it is handled by Mobile JSON Wire Protocol.
It establishes a connection with the client, captures the commands, executes those commands on a physical device, and sends the result of the command execution via an HTTP response. The client initiates the session by sending a request to the server consisting of session related information in key-value pairs, called as Desired Capabilities. There are slightly differences between iOS and Android platforms and launch a session on real device or /simulator/emulator.
A session initiation is basically a POST /wd/hub/session request by client. Appium responds to this request in the form of a session id.
Once the session is established, client and Appium server interacts with the session ID as reference.
How Appium works on Android:
Appium uses the UIAutomator test case to test the Android user interface to automate Android devices. The UI Automator is a native UI automation framework for Android.
The requests are sent to the Appium Server using Mobile JSON Wire Protocol. Appium server forward these requests to Android real device/emulator. These commands are interpreted by bootstrap.jar which converts them into mobile understandable UIAutomator format. The UIAutomator commands can now be performed on the device/emulator.
How Appium works on iOS:
Like Android devices, Appium uses Apple’s XCUITest API to test the user interface element for automating apps on IOS devices. That is, it utilizes the principle of RESTful services by sending JSON files. These files then work with an iOS application using UI elements such as buttons and text labels.
{
"platformName": "iOS",
"platformVersion": "13.3",
"deviceName": "iPhone 11",
"automationName": "XCUITest",
"bundleId": "org.wolf.SwagLabMobileApp",
"app": "/Users/IdeaProjects/appium-cucumberbdd-master /src/test/resources/apps/SwagLabsMobileApp.app"
}
Above is the example of Desired Capabilities to interact with iOS device.
Client libraries convert the user written commands to the REST API requests. These requests are sent to the Appium Server using Mobile JSON Wire Protocol. Appium server forward these requests to the target iOS device/simulator. These commands are interpreted by WebDriverAgent.app which converts them into mobile understandable format by calling Apple’s XCUITest API. The commands are now performed on the device/simulator.
Summary
In spite of its limitations and the general complexity of configuration, which I will cover in the second part of these series, Appium is still a perfect tool for performing mobile automation testing. It offers many common features, easily integrates with other systems and frameworks, and supports a lot more devices and programming languages than its competitors. Apart from that, a broad and active Appium community saves users from wasting time on all the unnecessary troubleshooting.
If you are looking for a solution which covers all types of mobile applications (Native, web or hybrid) and can be cross-platform (iOS, Android, Desktop App) executable, which is also open source, then Appium might be the one of the best solution.
In the following articles, I will go into details on how to execute automated test cases on Android and on iOS devices, starting with all prerequisite setups. I will cover also the logic to build a native mobile framework from the scratch, using the latest technologies such as cucumber, POM, parallel and cross-platform testing on different types of the devices (iOS & Android). It will include both real devices and emulators/simulators.
Take care. Keep Learning. Stay safe and stay tuned :)