What is Appium & how it works?

What is Appium & how it works?
What is Appium & how it works?

Appium is a cross-platform, open-source tool for automated testing of mobile applications, native applications, web applications as well as hybrid applications. The primary function of Appium is to test the working of an application. It was developed by the Sauce labs to allow parallel testing of
an application in multiple devices.

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 have an inclusive wrapper that encapsulates the native control-web-view for interacting with the web content are known as Hybrid Apps. A platform like Apache’s Cordova or Phonegap allows us to build an application using web technologies that can be later modified into a hybrid app by bundling it into a native wrapper.

Appium is a highly flexible platform, because of the following features:

  • It allows testing of all three mobile applications, namely: native, hybrid, and mobile web
  • It allows user to run automated tests on tangible devices, simulators as well as emulators
  • It allows user to perform tests against heterogeneous platforms, namely: Android, iOS and Windows
  • Appium has been a blessing to the developers as it allows them to run tests against multiple platforms (iOS, Android, Windows), using a sharable API. This enables them to reuse a single code among iOS, Android and Windows test suites and eliminate the requirement of maintaining three different code bases.

Nowadays, in the tech sector, the demand for mobile applications is tremendously increasing, as mobile applications are very handy for customers. In response to the consumer’s demand, most of the enterprises and start-ups are converting their websites into respective mobile applications. Before the release of any application, it is essential to carry out the Beta testing covering all the possible corner cases, so that the consumers do not report any grievances later. The ecosystem of Android, iOS, and Windows are highly diverse in terms of supporting libraries and functionalities.

Earlier, the developers had to cheque the compatibility of the final product with the three platforms separately, which was a very time-consuming and effort-taking job. With the ingress of Appium, we can perform an out and out automated testing of the end-product by using a unified platform. Earlier, Appium was restricted to only IOS and Android applications, but now with subsequent updates, we can test desktop applications for Windows operating systems as well. With Appium, you can use the same APIs for the three varied platforms; it allows us to pick a language according to our comfort and doesn’t dictate any framework or language upon the developers.

You must be wondering that what makes Appium this versatile and what the working process is! We have answered all your questions to quench your curiosity.

Top features of Appium:

  • Appium provides multi-platform support, i.e., we can run the same test cases on multiple platforms
  • Appium reduces the testing time exponentially by allowing parallel execution of the test scripts
  • If we make any small amendments in the code, the re-installation of the application is not required again
  • We don’t need to write any source code or install libraries for running tests on Appium
  • Most of the languages that include Selenium client library are supported by Appium, apart from the usual languages like C#, PHP, Python, Java, Ruby, JavaScript with Node.js, etc
  • Appium support community is really very dense and active

Let’s go through the basic concepts of Appium first

The Appium Desktop
Appium provides the users with a graphical user interface wrapper that can be downloaded on various operating systems, namely: iOS, Windows and Android. You need to worry about nodes, as it comes as a complete package. When running tests, you can cheque out the hierarchy of your app, using the inspector that comes along with the package itself.

The Appium Server
When we download the Appium application, we basically download the server. The Appium Server has been programmed using Node js and implements Selenium WebDrive. It allows developers to the use of in-built WebDriver client for launching tests, following that, your mobile application starts acting like a web application, where the DOM is represented by View hierarchy.

We can build it and install it from the source or directly through NPM.
We can run the following commands to install it from the NPM:

$ npm install -g appium
$ appium

The beta of Appium can be installed by using NPM:
$ npm install -g appium@beta

It is the beta version, so it is highly subjected to breaking changes
It can be uninstalled by running the command:
$ npm uninstall -g appium@beta

blog banner 1

Please make sure that you have uninstalled the beta version before installing contemporary versions
in order to have a distinct set of dependencies

Appium Clients
Most of the programming languages have client libraries that support Appium’s extensions to access
the WebDriver protocol like Java, PHP, Ruby, Python, JavaScript, and C#. You should use these client libraries instead of your regular WebDriver client while using Appium.

Maintaining Sessions
Automation can be scheduled the best in the context of a session. The clients have to initiate a session with the server in a specific way for each library, but they end up sending a POST session request to the server, instead, along with a JSON object known as the ‘desired capabilities’ object. In such cases, the server begins an automated session and responds with a session ID, which is used for transmitting further commands.

Desired Capabilities
A set of keys and values are created using a map or a hashmap; these are known as Desired capabilities. They are transmitted to the server to create customised sessions according to the developers’ needs. There are also dynamic desired capabilities, which can modify the behaviour of the server while automated testing is going on. For instance, we might set the “platform-name” as iOS to create an iOS session, instead of Windows and Android.

The Appium Client/Server Architecture
In the core, Appium is a web server that exposes any REST API. 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. Using the traditional client/server combination opens up a lot of possibilities for the developer, we can run tests in any programming language that includes an HTTP client API. However, Appium client libraries can be considered as they are easier to use. We may place the server on a machine, other than our test machine. We can even use any cloud services like Sauce Labs to capture and interpret the commands by just writing test codes.

So Appium server predominantly exposes REST API which performs the following tasks:

  • Establishes a connection between the client and the server
  • Captures the commands
  • Executes the commands
  • Send the command execution status as a response to the client

The diagram given below explains the Appium architecture completely.

Image Source: GitBooks

How Appium works in iOS?

Appium clients like Java, Python, Ruby connect with the Appium Server and connect via the JSON protocol suite. Appium Server then generates an automation session with the client, cheques the client’s desired capabilities, and connects with the specific vendor-provided framework for UI Automation. After this, UI Automation communicates with bootstrap.js running inside the Simulator, Emulator, or physical device for carrying out client operations. Bootstrap.js performs an action on the “Application Under Test”.

On iOS, Appium gives commands to a user interface automation script that runs in the Mac ecosystem. Apple dispenses applications known as ‘instruments’ that carry out activities like building profiling and controlling iOS apps. It also provides a command-line interface where the user can write commands in Javascript, which uses UI Automation APIs to interact with the App UI for automation.

The command life-cycle is as follows:

  • The Selenium webdriver picks a command form the source-code such as (Element.click) and transmits it as JSON via an HTTP request to the Appium server
  • Appium server is aware of the automation context like the iOS, Windows and Android. It directs these commands to the Instruments command server, which waits for the Instruments command client (written in node.js) to capture it and executes it in bootstrap.js inside the iOS instruments ecosystem
  • Once the command is executed successfully, the client reverts the message to the Appium server, which logs the command execution cycle in its console
  • The above cycle keeps recurring until all the commands have been executed
Image Source: 3pillarGlobal

How Appium works in Android?

The situation is almost similar in Android, where Appium dispenses commands to a User Interface Automator which runs test cases on the device. The “UI Automator” is the Android’s native UI automation framework, which supports running JUnit test cases directly inside the physical device from the command-line interface. It primarily uses java as the default programming language, but Appium allows it to run from any of the WebDriver supported languages. We use Bootstrap.jar instead of bootstrap.js that represents the test cases on being compiled in Java. As soon as it is launched, it generates a TCP server. The TCP server resides inside the target device, and the client is in the Appium process, which is just the converse of the iOS

Image Source: 3pillarGlobal

To read more about Android and mobile development, click here.

By Vanshika Singolia