Skip to content

7. Mobile apps: Appium QA

Self-healing for mobile tests usually lives inside a paid device cloud, as a black box. k11 Appium QA is open source and runs wherever your Appium tests already run: a laptop with an emulator, your CI, or any device cloud. It brings the healing approach of Chapters 5 and 6 to native and hybrid Android and iOS apps.

The key difference: the saved screen

A web page can be reopened at any time; a mobile screen deep inside an app is hard to get back to. So Appium QA heals against the exact screen the test failed on: a small pytest plugin saves the screen (Appium's page source XML) at the moment an element isn't found. Every tool works on either:

  • a saved screen (no device needed), or
  • the live device, when .qa-mcp/appium.yaml points at an Appium server.

Locators are evaluated offline against the saved XML: accessibility id, id, class name, XPath, UiSelector and iOS predicate, for UiAutomator2 (Android) and XCUITest (iOS) screens.

Set up

pip install "k11-appium-qa-mcp[live]"     # [live] adds the Appium client; saved screens need nothing extra

Plugin: /plugin install appium-qa@k11-appium-qa, which adds the /heal-mobile-tests command. For live sessions, copy the repository's docs/appium.example.yaml to .qa-mcp/appium.yaml: the server URL and capabilities, with secrets as ${ENV:NAME}. BrowserStack, Sauce Labs and other device clouds are configured the same way.

The tools

Tool What it does
inspect_screen Elements with locators verified to match exactly one element, most stable first
check_locator How many elements a locator matches (1 = good) and whether it's visible
capture_baseline While tests pass, records each locator's element, per platform, in .qa-mcp/appium-baselines.json
heal_locator Finds the intended element and suggests a verified replacement, in Python or Java form
accessibility_check Tappable elements a screen reader can't name, and duplicate accessibility ids
save_screen Saves the live device's current screen to .qa-mcp/appium-screens/ for device-free work later
run_tests Runs the pytest suite; failures include the locator, the line, the platform and the saved screen

Accessibility ids are preferred in every suggestion. Missing accessibility ids are why mobile tests are fragile, and why screen readers fail, so accessibility_check finds both problems at once.

A real heal

A login screen redesign broke three locators in one test and one in another. k11-appium-qa-mcp heal-ci --apply:

3 healed and verified, 1 needs review, 1 failure not caused by locators.

Test Old locator New locator Confidence Re-run
test_log_in (AppiumBy.ID, "et_email") (AppiumBy.ACCESSIBILITY_ID, "email-field") 94% passed
test_log_in (AppiumBy.ACCESSIBILITY_ID, "password-input") (AppiumBy.ACCESSIBILITY_ID, "password-field") 100% passed
test_log_in (AppiumBy.ACCESSIBILITY_ID, "login-button") (AppiumBy.ACCESSIBILITY_ID, "sign-in-button") 77% passed

Why "sign-in-button"? accessibility id similar (62%) · resource id similar: btn_login → btn_sign_in · text equivalent: "Log in" → "Sign in" · class matches.

Needs a person: the sign-up button lost its accessibility id; best guess btn_register at 42%, so it was not changed.

The changes land in the Page Object (tests/pages/login_page.py), not scattered across tests.

heal-ci

k11-appium-qa-mcp heal-ci            # dry run
k11-appium-qa-mcp heal-ci --apply    # apply, verify on the device, revert what fails
  1. Runs the pytest suite with the plugin, which saves the screen of every test that fails on a missing element.
  2. Heals each broken locator against that screen and the committed baseline.
  3. Applies a change only at 70% confidence or more (--min-confidence), clearly ahead of the runner-up. Tests sharing a broken locator are healed together, with one change.
  4. Re-runs the healed tests on the device. A test that now gets further and breaks on the next locator gets that one healed too, for up to five rounds. Each change is kept only if all the tests using it pass.
  5. Leaves non-locator failures alone and writes heal-report.md and heal-report.json.

Unlike the web tools, heal-ci here has --fail-on unresolved (the default: exit 1 if anything needs a person) or never. The repository's docs/heal-mobile-locators.yml runs it on an Android emulator in GitHub Actions.

There's also a device-free helper: k11-appium-qa-mcp inspect screen.xml lists a saved screen's elements with verified locators.

Java suites

The MCP tools and source rewriting support Java: Page Objects with @AndroidFindBy/@iOSXCUITFindBy (each keeps its own platform) and AppiumBy/MobileBy/By calls. heal-ci itself runs pytest suites; for Maven or Gradle, save the screen on failure (driver.getPageSource()) and use heal_locator or /heal-mobile-tests.

What it is not

Appium QA doesn't drive the app for exploration. Use a device-control server such as the official Appium MCP or mobile-mcp for that, and Appium QA to keep your existing suite healthy.

Evidence for the gate

The heal report has the same format as Playwright and Selenium QA, so Release Gate reads it as ui_heal evidence, with the same rules (Chapter 5).