May 13, 2020 Jonny Steiner

What is Appium Server? A complete end-to-end Guide

Share this knowledge!

Appium is an open-source cross-platform and cross-technology mobile testing automation framework. In recent years Appium has made waves in the mobile automation testing segment. The tool quickly became popular because it is platform-agnostic which means you can use the same test script to test both iOS and Android apps with minimal changes. Appium supports automation testing of web apps, native apps as well as hybrid apps.

The support for multiple programming languages to write test code such as Python, Ruby, Java, JavaScript, PHP is another striking aspect of Appium. Moreover, it enables you to test real devices, emulators, and simulators. The robust performance can be attributed to the JSON Wire protocol that Appium clients use to interact with mobile devices via the Appium Server. While there is a learning curve, it is worth your time as it makes automation testing easy and effective once you get your hands on it. Developed as a CLI tool, Appium has now transformed into a powerful and vibrant GUI desktop application that can be run on Windows, MAC, and Linux distributions.

Appium architectureAppium Server architecture

Appium uses Client-server architecture. Here are the key components of the Appium Architecture:

1) Appium Server: Appium Server is the core component of the Appium architecture. It is written in Node.js and runs on the machine or in the cloud. The Appium Server receives requests from Appium client libraries via the JSON Wire Protocol and invokes the mobile driver (Android driver/iOS driver) to connect to the corresponding native testing automation frameworks to run client operations on the devices. The test results are then received and sent to the clients. The Appium Server, has the capacity to create multiple sessions to simultaneously run tests on multiple devices.

2) Appium Client Libraries: Appium clients request the server to start a test automation session using the createSession() command via the JSON Wire protocol, run tests on multiple mobile devices, and receive the rest results from the Appium Server. Appium client libraries span across multiple languages such as PHP, Java, Ruby, JavaScript, C#, Python.

3) JSON Wire Protocol: In the Appium client-server architecture, Appium clients communicate with the Appium Server via the JSON Wire protocol that is developed by WebDriver developers team. It enables developers to access standard and predefined endpoints via a RESTful API. Using JSON Wire protocol, you can test websites and apps via a mobile browser while being able to install or uninstall apps on the device during the test automation session.

4) Appium Driver: Appium is platform-agnostic and technology-agnostic. To effectively manage different platforms, Appium uses multiple drivers and converts API into automation sessions for corresponding platforms.

  1. UiAutomator2: The default Appium driver for Android device testing
  2. UiAutomator1: Appium driver for older android versions.
  3. XCUITest: Appium driver for iOS device testing
  4. WinAppDriver: Appium driver for windows device testing
  5. Espresso: New Appium driver for Android device testing

5) Automated testing frameworks: Appium uses the native automated testing frameworks to run client operations on the testing devices. It connects with the bootstrap.js that acts as a TCP server and performs test commands on the devices.

  1. UiAutomator Framework: For Android device testing
  2. XCUITest Framework: To test iOS apps

How does Appium work?

Appium Server is written in Node.js and uses the client-server architecture wherein client machines communicate with the server via a protocol. To begin an automation test session, the client machine sends a request to the Appium Server via the JSON Wire protocol. The test code can be written in multiple programming languages such as Java, Ruby, Python, PHP, C#, and JavaScript. The Appium Server creates a new test automation session and invokes the iOS/Android driver. The Appium Server then connects with the corresponding native testing frameworks to connect with the bootstrap.jar/bootstrap.js that is running on the mobile devices to perform operations on the device.

The striking feature of Appium is that it enables developers to use the same test code to test iOS and Android devices. However, the challenge here is to differentiate between test automation requests of iOS and Android devices. Appium does this by looking at the desired capabilities option. When you create a request session, you have to mention the key-value pairs such as deviceName, platformName, appPackage, appActivity etc. Based on these values, the Appium Server efficiently routes the client requests to the corresponding test frameworks.

Appium on Android Devices

  • The client machine sends a request to the Appium Server via the JSON Wire protocol to create a new test automation session.
  • A test automation session is created on the server. The server also checks the desired capabilities. For Android platform testing, the server contacts the UiAutomator2 framework which is a native testing automation framework in Android.
  • UiAutomator2 will communicate with the bootstrap.jar that is running on the device, acting as a TCP server. It works on emulators, simulators as well as real devices.
  • Bootstrap.jar receives the commands and runs the tests on Android devices. It passes the test log details to the UiAutomator2 which in turn sends this information to the Appium Server. Bootstrap.jar then passes that information onto the client.

Appium on iOS Devices

  • The client machine sends a request to the Appium Server via the JSON Wire protocol to create a new test automation session.
  • A test automation session is created on the server. The server also checks the desired capabilities. For iOS platform testing, the server contacts the XCUITest framework which is a native testing automation framework in iOS that comes with Apple XCode.
  • XCUITest framework will communicate with the bootstrap.js that is running on the device acting as a TCP server. It works on emulators, simulators as well as real devices.
  • Bootstrap.js receives the commands and runs the tests on the iOS devices. It passes on the test log details to the XCUITest which in turn sends this information to the Appium Server. This information is then communicated with the client.

JSON Wire Protocol

JSON Wire Protocol is a popular standard that facilitates communication between client libraries and the server in a heterogeneous system. Being a platform-agnostic and language-agnostic tool, Appium makes use of this feature of the JSON Wire Protocol.

JSON is a short form for JavaScript Object Notation wherein complex data structures are involved. The wire protocol is a point-to-point data transmission mechanism. In the Appium architecture, the communication between the Appium Server and client libraries is facilitated by the WebDriver that uses the JSON Wire protocol over a HTTP REST request with JSON inputs. It uses the serialization and deserialization method to convert object data into JSON format and vice versa. Being a cross-platform tool, the server doesn’t have to understand the programming languages of the client libraries but it just identifies the protocol to create and manage automation sessions.

The protocol architecture

  1. Local End: It is the client-side of the protocol, normally client libraries written in a specific programming language.
  2. Remote End: It is the server-side of the protocol
  3. Intermediary end: Proxy systems that can act as remote end as well as the local end.
  4. Endpoint node: It is the final remote end of the node structure.

The remote end is the server that reads requests from the local end clients and writes responses via a TCP socket.

For instance, you can use the New Session command to create a new WebDriver session to perform test operations on the endpoint node or use the Find Element command to retrieve specific elements.

HTTP MethodURI TemplateDescription
Post/sessionCreates a new session
Post/session/{session id}/elementRetrieves an element with a specified ID
Delete/session/{session id}Deletes a session
Get/session/{session id}/sourceIt returns the string serialization of active document DOM

Appium Installation

Appium is available in two versions.

  1. CLI-based Appium Server
  2. GUI-based Appium Desktop ( It adds a GUI layer to the Appium Server and also offers Appium Inspector)

CLI-based Appium Server Installation

Appium offers a vibrant GUI desktop app that enables you to easily manage test automation operations. However, when you integrate testing into your CI pipelines, you need to start the Appium Server using the scripts. As such, you should install the Appium Server

Step 1: Install Node.js

As Appium is written in Node.js, you need to install Node.js first to use Appium. Visit the Node.js website to download the software:

https://nodejs.org/en/download/current/

After the download is completed, install the package.

Accept the license agreement and proceed to the next screen.

Choose the Node.js path that is normally C:\Program Files\nodejs

The next screen shows the components being installed. Along with Node.js, you need a package manager. Npm is the recommended package manager for Node.js. So, install the NPM tools too.

The next screen will prompt you to allow the installation of the necessary tools to compile native modules. You can select that option or you can manually install them from GitHub when required.

Click next and complete the installation.

After the installation, check whether the environmental variable contains the path of npm and nodejs.

The system path shows the Node.js path and the user variable shows the npm path.

Right-click on Start->System->Advanced->Environment Variables

Step 2: Install Appium from the Command Prompt

Open the command prompt as an administrator and type the following command:

npm install -g Appium

Appium Server npm

The npm package manager will start the installation procedure.

Appium Server npm

After a successful installation, you can start using Appium.

To open Appium from the command prompt, type Appium followed by the IP address and the server port number.

Appium -a 127.0.0.1 -p 4723

Now, Appium is running and the REST HTTP is listening on the IP address (In the above example, localhost 127.0.0.1 and the server port 4723).

GUI-based Appium Desktop Installation

Download and install Appium Desktop

To download and install the Appium desktop, visit the Appium website:

https://Appium.io/

Appium Server

After successful installation, open the Appium desktop.

Appium Server

At the opening screen, Appium will prompt you to enter the host IP address and the server port number.

As Appium is just an HTTP server, it does nothing on its own. You need the client libraries to request and perform operations on end devices. So, it is important to configure the server port when you start Appium. The server port is what the client connects to and communicates with Appium. The default server port is 4723. When you connect to the client machines, you should specify this server port.

To change the server port, click on Advanced Tab and you will see a screen with server configuration settings. Enter the details and Start Server.

Appium Server

If you want to save these settings for next time, save them as preset and choose the preset tab settings when you open Appium next time.

Appium Server

Now Appium Desktop is ready for use.

Connecting Appium Desktop to SeeTest Platform

The SeeTest platform is an end-to-end solution to test devices and browsers over the Cloud or a remote network. SeeTest is fully compatible with tools like Appium, Selenium, XCUITest, and more. The section below provides a step-by-step procedure to connect SeeTest Cloud with Appium Desktop for Windows.

You will need a valid SeeTest Cloud account.

Step 1: Launch Appium Desktop and start a new session

Once the Appium Desktop launches, open a ‘New Session Windows…’

Appium Server

Step 2: Getting access key from SeeTest Cloud

Navigate to the SeeTest Cloud UI and click the icon representing the user. Then click Get Access Key as shown below.

Copy the access key to the clipboard from the open-access key dialog box.

Note: In this case, we used SeeTest Cloud’s public offering in the connection preferences.

Step 3: Specify SeeTest Cloud connection settings and Desired Capabilities. The previous step will open up a dialog box to connect to an Appium Server. In this step, we will specify the connection preferences of SeeTest Cloud’s Appium Server.

Select Experitest from the ‘Cloud Providers’

Provide the cloud URL and access key.

Set the “platformName” capability to iOS or Android, based on the device you would like to use.

Appium Server

Click Start Session to connect to SeeTest Cloud. This step will connect to the SeeTest Cloud.

An ongoing Appium Desktop session to the SeeTest Cloud is also available in the SeeTest Cloud User Interface. This provides the user with better control over the device.

Navigate to the Execution tab in SeeTest Cloud User Interface and click debug to use the ongoing Appium Desktop session.

This is a very convenient feature because a test user can leverage powerful features of both SeeTest and Appium in the same session. The key benefit of this session is that the test operations done using SeeTest are faster and more user friendly. Appium Inspector can be used to inspect any element in the session.

Of course, if you want to see it in real-time we have you covered with this great tutorial video.

To sum up, Appium’s popularity shows no sign of letting up as time goes on. We keep that in mind always as we develop and release the latest versions of SeeTest. As for the information in the blog post, we recommend you bookmark this page so you will always have the tutorial information available. And naturally, we would recommend that if you have not yet used our Appium integration that you take a download and see for yourself.

 

Guy ArieliCTO

 

Share this knowledge!