What is working on android side?

I am interested in that what APK or something else is responsible for receive requests from an appium server, do all automation staff and send responses to the server back.
In other words what is responsible for doing all background magic in android side?
Custom Google UI Automator (Android 4.2+)?
Does Appium install something to Android silently?
Is it possible to run test (webdriver test) inside Android only?

Yes, Appium installs a set of applications to the device to help it do what it needs. To start, there are the Appium Settings and Unlock applications. As their names suggest, these apps help Appium configure and unlock the device.


The magic, however, is actually not performed by an installed application on the device. When Appium starts an Android driver session, it pushes a special file called “bootstrap.jar”, and it executes this file using the device’s built-in uiautomator command.

This next part is a bit fuzzy for me, but there is a way that uiautomator searches for which classes to run. The tool accomplishes this by either scanning the Jar file for classes that extend a particular test case class, or it is given an argument through the command line to know which classes to execute (check Appium’s logs to be sure).

In any case, bootstrap.jar’s entry point class and method will be executed. During this moment, bootstrap.jar binds to port 4724 (by default) on the device and starts a server that listens on the corresponding socket. Let us call this server that runs on the device the “device server”. This server listens for requests that come from the Appium Node.js server that is running on the host machine. I will call the Appium Node.js server the “host server”.

When the device server receives a request, it parses the request to figure out what to do. There are a list of actions that are programmed in to bootstrap.jar that translate the requests and commands into Uiautomator commands on devices running API 17 and newer. The Uiautomator commands are the same commands you’d find from the Android Uiautomator API.


Running WebDriver tests on device only

First and foremost, WebDriver defines an API, and Appium is just one particular implementation of that API. You can do on-device WebDriver WebView testing (almost like testing with just a browser), but it will not be Appium’s WebDriver.

I don’t believe it’s immediately possible to run an Appium WebDriver test purely on the device without the assistance of a host machine because you will have to convert the setup steps done by Appium to be done on the device. Even then, access to adb is very important because adb has lots of power over the device’s system. In any case, if you wanted to have your test run completely on the device without help from a host machine, most people would recommend you write your tests completely natively using the Uiautomator APIs directly.

5 Likes

Nice explanation by @afwang

afwang, thanks a lot for your excellent reply.