All posts

Build Self‑Healing Phoma Flows That Adapt to UI Changes

Build Self‑Healing Phoma Flows That Adapt to UI Changes

Why Self‑Healing Flows Matter

Automation flows built in Phoma are powerful, but they break when an app’s UI changes. A button moves, a resource‑id updates, or a new layout replaces the element you selected. When that happens the flow stops, you have to pause work, locate the new selector, and edit the flow. In a busy QA or ops environment that downtime costs time and money. A self‑healing flow detects the change, tries alternative selectors, or falls back to a visual check, then continues automatically.

Understanding UI Volatility

Common causes of UI breakage

  • App updates that rename resource‑ids or change content descriptions.
  • Layout refinements that move elements within a hierarchy.
  • Dynamic content that loads different views based on user state or regional settings.
  • Platform changes such as new Android versions that affect window insets or safe areas.

Impact on Phoma flows

When a step fails because the element cannot be found, the whole flow stops. Without a resilient design you spend minutes or hours fixing a single step, which defeats the purpose of “no‑code” automation.

Strategy 1 – Choose Stable, Multi‑Attribute Selectors

Instead of relying on a single attribute, combine two or more stable properties:

  1. resource‑id (if the app provides a consistent ID).
  2. content‑description (accessibility text).
  3. class‑name (UI component type).
  4. ancestor‑class (e.g., parent button).
  5. index (positional) as a last resort.

Example selector JSON:

{
  "selector": "resource-id:com.example.app:id/username content-desc:Enter your username"
}

If the primary attribute changes, Phoma will try the secondary one, increasing the chance of success.

Strategy 2 – Add Screenshot Checkpoints

Visual validation can catch layout shifts that are not obvious in the element tree. After a critical step (e.g., opening a screen), insert a screenshot checkpoint. If the captured screenshot differs beyond a tolerance, the flow can pause and retry with alternative selectors.

How to add a checkpoint:

  1. In the flow editor, click Add Step → Screenshot.
  2. Name it Verify Home Screen.
  3. Set the tolerance (e.g., 0.2).
  4. Optionally attach a fallback selector.

If the screenshot fails, you can configure the flow to Retry with alternative selector or Abort and notify.

Strategy 3 – Conditional Logic for Fallback Selectors

Phoma supports if steps that evaluate a boolean expression. Use this to test whether a primary selector exists, and if not, try a secondary one.

Pseudo‑code example:

# Step 1: Try primary selector
TrySelect Element "resource-id:com.example.app:id/username"

# Step 2: If not found, try fallback
IfNotFound Then
    TrySelect Element "content-desc:Enter your username"
EndIf

In the visual editor you create an If block, set the condition to Element not found, and add the fallback action inside the block.

Strategy 4 – Leverage External AI for Selector Updates

While Phoma does not ship an AI agent, you can export the current selector, ask an external AI (e.g., ChatGPT) to suggest a more robust version, and then paste the new selector back into the flow. This keeps the flow up‑to‑date without manual hunting.

Workflow:

  1. Export the failing selector as a JSON snippet.
  2. Prompt the AI: "The element with resource-id com.example.app:id/username no longer exists after the latest update. Suggest a stable selector using content‑description and class‑name."
  3. Receive a revised selector.
  4. Replace the old selector in Phoma.

Because the AI runs on your own subscription, there are no extra costs.

Strategy 5 – Modular Sub‑Flows for Reusable Actions

Complex flows often repeat the same interaction (e.g., "log in", "search", "download"). Build a sub‑flow for each reusable action. If the UI of that action changes, you only edit the sub‑flow, and every main flow that calls it benefits automatically.

Creating a sub‑flow:

  1. In the flow editor, click New Sub‑Flow.
  2. Name it LoginScreen.
  3. Add steps: open app, wait for login field, type username, type password, tap login.
  4. Save.
  5. In any main flow, add Run Sub‑Flow → LoginScreen.

Now a UI change in the login screen only requires a single edit.

Practical Example – Self‑Healing Login Flow

Let’s build a flow that logs into a generic app and demonstrates the techniques above.

  1. Start – Launch App (use adb shell am start or the built‑in Open App step).
  2. Wait – Wait for Element with selector resource-id:com.example.app:id/login_field (primary).
  3. Screenshot Checkpoint – Verify Login Screen (tolerance 0.2).
  4. If Not Found – If Element not found → TrySelect content-desc:Enter your username (fallback).
  5. Type Username – Type Text on the element found.
  6. Type Password – Type Text on content-desc:Enter your password.
  7. Tap Login – Tap on resource-id:com.example.app:id/login_button.
  8. Wait for Home – Wait for Element resource-id:com.example.app:id/home_icon.
  9. End – Success message.

Key points:

  • The primary selector is tried first; if the app updates the ID, the If Not Found block activates the fallback.
  • The screenshot checkpoint ensures that even if the element hierarchy changes but the visual layout stays similar, the flow can continue.
  • All steps are modular; you could extract steps 2‑7 into a sub‑flow PerformLogin for reuse.

Testing and Monitoring

Unit‑test each selector

Run the flow in Debug mode on a single device. Use the Log panel to see which selector was actually matched. If a step fails, inspect the log to see which attribute was missing.

Continuous verification

Schedule the flow to run nightly on a dedicated test phone. Enable Email notification on failure so the ops team can act quickly.

Version control for selectors

Store selector JSON files in a Git repository alongside your flow definitions. When a UI change occurs, diff the old and new selectors to understand what changed.

Summary of Actionable Steps

  1. Audit existing selectors – list primary and secondary attributes for each step.
  2. Add screenshot checkpoints after critical UI transitions.
  3. Introduce If‑Not‑Found logic to switch to fallback selectors.
  4. Create reusable sub‑flows for common actions.
  5. Document selector changes in a shared changelog.
  6. Test nightly on a stable device and enable alerts.

By following these steps, your Phoma flows become resilient to UI churn, reducing maintenance overhead and keeping your automation pipelines reliable.