Healenium: Unlock stability in Appium Test Automation

Appium, a powerful tool for mobile test automation, often grapples with the persistent issue of test flakiness. This instability arises from the dynamic nature of mobile apps, where UI elements frequently change, leading to test failures and increased maintenance overhead. To address these challenges, Healenium emerges as a revolutionary solution, which can significantly enhance the reliability and help us to unlock the stability in Appium test automation.

Understanding the Appium Challenge

Appium, Although is very versatile, faces hurdles in maintaining test stability due to:

  • Frequent UI changes: If Mobile app UI tends to change frequently sprint over sprint. Modifications in app layout or element attributes can render existing locators obsolete, causing test failures.

  • Maintenance overhead: Updating test scripts to accommodate new UI changes is a time consuming and error-prone process.

Introducing Healenium: A Self-Healing Solution

Healenium is an innovative open-source library that helps to addresses these challenge in Appium. It acts as a mediator between your test script and the Appium server, intelligently handling NoSuchElement test failures and adapting to dynamic UI changes.

Benefit of Healenium

  • Improved Stability: It employs a sophisticated mechanism to identify multiple potential locators for a UI element, increasing the chances of finding a valid match even if the primary locator fails.

  • Dynamic Element Handling: Healenium can dynamically adjust test interactions based on real-time UI changes, ensuring that test scripts remain resilient to modifications.

  • Minimize Maintenance: When a test encounters an error, Healenium can attempt to recover by performing alternative locators. This reduces the flakiness in test and result in less maintenance works.

  • Root Cause Analysis: Healenium provides detailed reports on test failures, including information about the attempted healing, screenshot and new locators that can help in root cause analysis and test improvement.

  • Plugin for Intellij IDE: Healenium provides plugin for Intellij IDE that can automatically update the broken locators in your codebase.

How Healenium Works

Healenium employs a combination of advanced algorithms and techniques to achieve its self-healing capabilities.
It offers two primary integration methods:

  1. Healenium-Proxy: A versatile, language-agnostic solution positioned between your test runner and the web application. It supports multiple languages and requires configuring your test to connect to the proxy as a RemoteWebDriver.

  2. Healenium-Web:Specifically for Java, this method integrates directly into your test code for a tighter coupling.

Both approaches leverage Healenium's core capabilities: intelligent locator selection, dynamic element handling, self-healing actions, and detailed reporting.

Healenium working with appium test automation

As shown in above flow chart, Healenium comprises three core services:

  1. Healenium Backend: This central component processes healed locators, manages storage, handles screenshots and reports, and orchestrates communication between the other services.

  2. Healenium DB: A PostgreSQL database storing baseline locators, elements, and healed locators for subsequent runs.

  3. Healenium Selector Imitator: The core healing engine that reconstructs user-defined selectors based on HTML changes, suggesting potential alternatives while preserving the original selector structure.

Integrating Healenium with Appium

Pre-Requisites

  1. Docker: Installed and running on your system. As Healenium uses docker to run their self healing mechanism. To install Docker, you can follow the guide: here

  2. Appium: Set up for mobile test automation as Healenium integrates with Appium. You can refer here for instruction.

  3. Required language dependencies: Install necessary tools for your test automation framework (e.g., Java, Python, JavaScript).

Step By Step Guide

Step 1: Starting Healenium Proxy:

We can start Healenium proxy with docker-compose file that can start all the 3 services mentioned above and healenium proxy as well in the docker. But We recommend cloning the Healenium repository as it simplifies setup.

  • Use the following git command in your terminal to clone the repository.

Bash

git clone https://github.com/healenium/healenium.git
  • Once cloned, navigate to the root directory of the Healenium repository:

Bash

cd ./healenium

Healenium repository structure

  • These instructions assume you're using a local Appium server. If not, update the docker-compose-appium.yaml file with the following line:

YAML

    - APPIUM_SERVER_URL=http://host.docker.internal:4723/wd/hub
  • Ensure your Docker desktop is running. Then, start Healenium Proxy using the following command:

Bash

docker-compose -f docker-compose-appium.yaml up -d
  • You'll see following console logs indicating all four services have started.

Healenium: A Game-Changer for Appium Test Automation

  • Allow a few minutes for everything to be fully up and running.

Healenium services started in docker

  • To confirm Healenium Backend is operational, navigate to localhost:7878 in your web browser. You should see the Healenium landing page.

Healenium dashboard

Step 2: Configuring Your Appium Driver

To route Appium driver requests through the Healenium proxy, replace the Appium server URL with the Healenium proxy's address. This typically looks like following:

Java

// Use Healenium proxy URL instead of Appium server URL
WebDriver driver = new AndroidDriver(new URL("http://localhost:8085"), caps);

Step 3: Execution:

With Healenium Proxy running and the Appium driver configured, you're ready to execute your first test.
You can use AppiumJava_BoilerPlate for POC.

Note: To enable Healenium's self-healing, run a successful test initially to establish a baseline of locators.

After completing your test suite, visit http://localhost:7878/healenium/selectors/ to view the saved locators. These serve as a foundation for future healing attempts.

Healenium selectors baseline

To test Healenium's self-healing capabilities, modify a locator in your app. For instance, change the "Log In" link to "Sign In" in your test app. Re-run the test.

Note: I'm using my-demo-app-android from SauceLabs for this demo.

Changing element attributes to test self healing in Appium test automation

Normally, this change would cause the test to fail. However, Healenium should identify the modified element and attempt to heal the locator.

Self healing in healenium

To review healed elements, navigate to http://localhost:7878/healenium/report and select your test run. This provides details about healed locators and accompanying screenshots.

Self healed report of Healenium

Conclusion

Healenium is a valuable tool that significantly reduces maintenance efforts for Appium test scripts, especially when dealing with minor UI changes like button text or element IDs. However, it's essential to be aware of potential drawbacks.

For instance, Healenium's self-healing capabilities might inadvertently mask UI changes that impact user experience. Let's say If text of a "Cancel" button is replaced with the text of "Submit" button, Healenium could mistakenly heal the locator, potentially leading to unexpected application behavior.

To mitigate this risk, Healenium offers granular control over which elements should be self-healed.