Mobile Automation Testing with Appium: A Step-By-Step Tutorial For Beginners

IPWITHEASE | Blog,Services and Applications
Advertisements

It’s widely known that the mobile industry is experiencing rapid growth. To speed up application delivery, companies rely heavily on mobile automation testing. A recent survey showed that in the mobile domain, 35% of organizations prefer Appium over other free or open-source test automation tools.

This blog aims to provide comprehensive and up-to-date steps for downloading and setting up Appium from scratch, as well as writing automation test scripts in Java for both mobile apps and mobile browsers.

Mobile Automation Testing with Appium

What is Appium?

Appium is an open-source framework for UI testing of mobile applications, available for free. It supports testing of native, hybrid, and web applications and enables automation testing on both physical devices and emulators and simulators. Additionally, Appium provides cross-platform application testing capabilities, meaning that a single API can be used for developing test scripts for both Android and iOS platforms.

Advertisements

Appium does not rely on the mobile device’s operating system, as it utilizes a framework or wrapper that translates Selenium Webdriver commands into either UIAutomation (for iOS) or UIAutomator (for Android) commands, depending on the device type rather than the OS type.

Classification of mobile apps

  1. Native apps – These apps are built using platform-specific iOS, Android, or Windows SDKs. They are designed to work on a specific platform or device.
  2. Hybrid apps – Hybrid apps are a type of mobile application that combines web technologies such as HTML and CSS with a native application wrapper on top of UIWebView for iOS and “webview” for Android apps.
  3. Mobile web apps – These are apps accessed using mobile browsers, and they don’t require installation on the device.

How does Appium operate?

Appium operates as an HTTP server, is developed using the Node.js platform, and utilizes the Webdriver JSON wire protocol to drive iOS and Android sessions. Prior to initializing the Appium Server, it is necessary to pre-install Node.js on the system.

Once the download and installation of Appium are complete, a server is set up on the machine that exposes a REST API. It accepts connection and command requests from the client and executes these commands on the designated mobile device (Android/iOS). Appium then provides HTTP responses back to the client.

Appium uses mobile test automation frameworks to interact with the user interface of mobile applications and execute the requests sent through the REST API. For iOS, it uses Apple Instruments (available only in Xcode 3.0 or later with OS X v10.5 and later), while for Android API level 16 or higher, it uses Google UI Automator, and for API level 15 or less, it uses Selendroid.

The Appium Framework

The Appium framework operates on a client/server architecture and functions as an HTTP server built on the Node.js platform. It includes a REST (Representational State Transfer) API and implements Selenium WebDriver. The available WebDriver client can be used to execute tests with Appium.

The following responsibilities are carried out by the REST API:

  1. Receiving connections from the client-side.
  2. Listening to commands from the client.
  3. Executing commands on the designated mobile device.
  4. Returning the command execution status as an HTTP response to the client.

Prerequisites for using Appium

To use Appium, certain prerequisites must be met, including:

  • Installation of the Android SDK (Studio) from the provided link.
  • Installation of the Java Development Kit (JDK) from the provided link.
  • Installation of Eclipse from the provided link.
  • Installation of TestNG for Eclipse from the provided link.
  • Installation of the Selenium Server JAR from the provided link.
  • Installation of the Appium Client Library from the provided link.
  • Access to the APK app info on Google Play from the provided link.
  • Installation of Appium Desktop.
  • (Not Required) Installation of Node.js – whenever the Appium server is installed, it comes with “Node.exe” and NPM by default, which are included in the current version of Appium.

Installing Appium

To install Appium, there are two methods you can use:

  1. Install through NPM (Node Package Manager)
  2. Install using the Appium Desktop, which is a GUI application.
  • To use the NPM method, you will need to have Node.js and NPM installed on your system. You can install Node.js using nvm, n, or brew install node. However, it is important to note that using sudo or root may cause issues during installation. Appium supports Node.js 12+, and it is recommended to use the latest stable version.
  • Once you have Node.js and NPM installed, you can run the following command in the terminal to install Appium:

npm install -g appium

  • Alternatively, you can also install Appium using the Appium Desktop, which can be downloaded from the Appium Release page.

You can start Appium testing on a cloud-based digital experience testing platform like LambdaTest by following the comprehensive Appium testing support documentation that walks you through the process of running your first Appium test script on a cloud Appium Grid. With LambdaTest’s cloud Appium Grid, you won’t need to worry about any Appium infrastructure challenges, and there is guaranteed zero downtime.

Not only that, but LambdaTest also offers your first 100 Appium testing minutes for free with just a simple sign-up, allowing you to test your mobile applications without incurring any initial costs. Furthermore, you can also take advantage of manual cross browser testing, automation testing, Visual UI testing, responsive testing, manual app testing, and more, all with lifetime free access to LambdaTest.

Appium Inspector

  • Appium Inspector is a popular tool that enables users to inspect the elements of mobile applications and record and playback their behavior. It works similarly to the record and playback feature of Selenium IDE, but with added functionalities specifically designed for mobile testing.
  • The Inspector tool is capable of inspecting the Document Object Model (DOM) of a mobile application, allowing users to view and interact with the various elements that make up the app’s user interface. It then generates test scripts in the language of the user’s choice, which can be used for automating tests on the mobile app.
  • However, it is important to note that currently, the Appium Inspector does not support Microsoft Windows. While it is possible to launch the Appium Server on a Windows machine, the Inspector fails to inspect elements in the application. As a workaround, the UIAutomator viewer can be used to inspect elements on Windows.
  • UIAutomator viewer is a tool provided by Android Studio that allows users to inspect the elements of Android applications. It provides a graphical representation of the app’s user interface, allowing users to identify and interact with various elements of the app. Although it is not as versatile as the Appium Inspector, it can still be used as an alternative for inspecting elements on Windows machines.

For Android device

Appium is a tool that employs the UIAutomator framework (or Selendroid) to automate Android application testing by interacting with the Android user interface. The bootstrap.jar file acts as a TCP server, transmitting test commands to the Android device through the UIAutomator or Selendroid framework, enabling the execution of desired actions.

For iOS device

Like with Android devices, Appium also utilizes the JSON wire protocol when testing iOS devices. Specifically, it leverages Apple’s UIAutomation API to automate the testing of iOS devices by interacting with their user interface elements. The bootstrap.js file functions as a TCP server, transmitting test commands to the iOS device through the Apple UIAutomation API framework, enabling the execution of desired actions.

Advantages of Appium

The following points highlight Appium’s advantages over other mobile test automation tools:

  • Appium operates like a server and runs in the background, similar to Selenium Server.
  • Appium can automate any mobile application that is developed using different programming languages and frameworks.
  • Mobile devices do not require Appium installation to test mobile apps.
  • It includes a built-in UI Automator that enables detailed inspection of mobile apps, generating comprehensive logs and reporting structures.
  • Appium employs Selenium WebDriver JSON Protocol to work with native Android and iOS mobile applications.
  • Using Appium, testing can be conducted on Emulators and Simulators, as well as on real device cloud.
  • It provides complete access to back-end APIs and databases through test scripts.
  • Appium allows parallel testing of automation scripts with Xcode, UIAutomator, and UIAutomation, which can be performed by referring to our Appium Parallel Testing guide.
  • Appium integrates seamlessly with the TestNG testing framework.
  • It simplifies regression testing of mobile applications.

Limitations of Appium

  • Inability to test Android versions lower than 4.2, which can be problematic for those who need to test their applications on older Android devices or versions.
  • Limited support for hybrid app testing, may make it difficult to fully test the functionality of hybrid apps, particularly when testing the switching action of an application from the web app to the native app and vice versa.
  • Appium Inspector cannot be run on Microsoft Windows due to a lack of support, which may be inconvenient for Windows users who want to use this tool for inspecting and debugging mobile apps. However, alternative tools and solutions are available for inspecting and debugging mobile apps on Windows.

Conclusion

Setting up Appium involves downloading and installing several tools and configuring system variables, which can be a challenging process. This article covered each step in detail, with additional information to guide even complete beginners.

Besides Appium, many other open-source tools are available for mobile testing automation. However, most of these tools require an extra agent to compile the majority of the application code to interact with native mobile apps. 

Continue Reading:

Hybrid vs Native Mobile App

Mobile Application Testing Process: The Main Steps

ABOUT THE AUTHOR


Leave a Comment

Your email address will not be published. Required fields are marked *

Shopping Cart