Imaginea is contributing to Appium and its recent contributions UIAutomator2 Driver and Server modules are released recently for end users.

Here would like to share insight about the Server module and how it works.

Intro:

  • appium-uiautomator2-server module is targeted to re implement appium-android-bootstrap‘s bootstrap module using Google’s  UIAutomator V2 API.
  •  appium-android-bootstrap built on top of Google’s UIAutomator v1 and Google’s UIAutomator v1 API is broken and officially depreciated now.
  •  Google UIAutomator v2 fixes most of the problems in v1. The most important difference is decoupling the upgrade process of the framework from the underlying Android OS.

 Bootstrap vs appium-uiautomator2-server:

Both bootstrap and appium-uiautomator2-server modules are responsible to implement handlers to interact with Android Native and Hybrid apps.
Below points will describe more details about these modules and development stack.

Bootstrap:

  • Will be packaged as AppiumBootstrap.jar and injected into the device/emulator while executing the tests.
  •  Contains ServerSocket,  running to process the requests given by appium-android-driver.
  • Uses Google UIAutomator v1 to perform the actions.

appium-uiautomator2-server:

  •  Will be packaged as appium-uiautomator2-server-vX.X.X.apk (X.X.X specifies version) and installed in the device/emulator while executing the tests.
  •  Contains Netty Server running to process the requests given by appium-uiautomator2-driver. Using Netty Server gives better performance and less memory consumption over using ServerSocket.
  •  Uses Google UIAutomator v2 to perform the actions. UIAutomator v2 has fixes for most of the UIAutomator v1 bugs and architectural level changes.


appium_uiautomator2_server_flow_diagram

 

Prerequisites for using appium-uiautomator2-server: This module should support from Android 5.0 (API Level 20) and above.

Usage: From Appium server, it is requested by specifying the desired capability automationName  as uiautomator2  when starting a session.


How it works ?

When a client (test script) requests to create a new AndroidDriver session, the client passes desired capabilities to the appium node server. Based on the automationName  property in the desired capabilities, appium redirects to the corresponding driver (by default appium passes to appium-android-driver on the absence of automationName ).

  • When a client (test script) requests to create a new AndroidDriver instance with automationName  as UIAutomator2 ,  server modules apks will be installed in the corresponding Device/Emulator by appium-uiautomator2-driver.
    1. appium-uiautomator2-server-vx.x.x.APK responsible for executing handlers.
    2. appium-uiautomator2-server-debug-androidTest.apk contains a single test to start the server.

appium_ui2-server_flow

 

  •  AppiumServlet is responsible for handling and responding to requests by redirecting request s to corresponding handler.
  • Handler will request UIAutomator v2 to perform corresponding action and status of the handler will be captured in AppiumResponse.
  •  Captured AppiumResponse will be returned to appium-uiautomator2-driver and driver sends the response to client.

Thanks for reading, you can refer source code in the appium github repo.

Do let us know if you have any queries or would like know any other details.