Android Hybrid Testing

Testing Android Hybrid Apps

What are Hybrid apps? Hybrid apps are a special kind of mobile application that consists of a native container and a webview layer. A native container has UI elements and code that come from the mobile operating system's SDK itself. In other words, it is a layer in which you can make use of Google's Android APIs and display standard or custom Android elements like list views, buttons, and so on. A webview is a browser window with invisible borders that displays a website, hosted either on the Internet or locally within the app itself. Thus the app is a "hybrid" of native and web. The purpose of developing a hybrid app is to be able to use official Android APIs while at the same time building all or part of the app using web technologies, which often allow a speedier development cycle.

Testing Android hybrid apps using a framework like Appium is extremely easy. In fact, Appium is the best automation framework for testing hybrid apps because it uses the WebDriver API, which was explicitly designed and popularized for testing web browsers. Thus, Appium allows you to seamlessly switch between automating the native portion of a hybrid app and automating the web portion of a hybrid app. This is made possible using Appium's CONTEXT API. The basic strategy is as follows:

  1. Use your Appium client to get a list of available contexts. That list will usually include "NATIVE_APP" to refer to the native layer, and any number of other strings that refer to webviews.
  2. Call the command to set the current context, passing in the string referring to the webview you want to automate (or the native layer).
  3. Now, if you are in a web context, you can automate the inner website easily by simply using the Appium client as if it were a vanilla Selenium WebDriver client.

That's it! For more information on the CONTEXT API, see the Appium documentation. And don't forget that Appium can run tests on both emulators and real devices. It's easy to get set up to test on all kinds of Android platforms using Sauce Labs. Be sure to check out our white paper on the proper way to divide tests between emulators and real devices in your test flow.