[{"data":1,"prerenderedAt":19},["ShallowReactive",2],{"blog-post-en-build-self-healing-phoma-flows-that-adapt-to-ui-changes":3},{"slug":4,"lang":5,"title":6,"summary":7,"date":8,"tags":9,"tag_slugs":14,"thumbnail_url":15,"translations":16,"body":17,"asset_base":18},"build-self-healing-phoma-flows-that-adapt-to-ui-changes","en","Build Self‑Healing Phoma Flows That Adapt to UI Changes","Learn how to create Phoma flows that automatically detect UI updates and recover without manual re‑selection, boosting reliability for daily automation tasks.","2026-11-27",[10,11,12,13],"phoma","android","automation","selfhealing",[10,11,12,13],"https://blog-api.phomaapp.com/api/blog/posts/build-self-healing-phoma-flows-that-adapt-to-ui-changes/thumbnail.svg?lang=en",[5],"## Why Self‑Healing Flows Matter\n\nAutomation 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.\n\n## Understanding UI Volatility\n\n### Common causes of UI breakage\n- **App updates** that rename resource‑ids or change content descriptions.\n- **Layout refinements** that move elements within a hierarchy.\n- **Dynamic content** that loads different views based on user state or regional settings.\n- **Platform changes** such as new Android versions that affect window insets or safe areas.\n\n### Impact on Phoma flows\nWhen 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.\n\n## Strategy 1 – Choose Stable, Multi‑Attribute Selectors\n\nInstead of relying on a single attribute, combine two or more stable properties:\n\n1. **resource‑id** (if the app provides a consistent ID).\n2. **content‑description** (accessibility text).\n3. **class‑name** (UI component type).\n4. **ancestor‑class** (e.g., parent button).\n5. **index** (positional) as a last resort.\n\n**Example selector JSON**:\n```json\n{\n  \"selector\": \"resource-id:com.example.app:id/username content-desc:Enter your username\"\n}\n```\n\nIf the primary attribute changes, Phoma will try the secondary one, increasing the chance of success.\n\n## Strategy 2 – Add Screenshot Checkpoints\n\nVisual 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.\n\n**How to add a checkpoint**:\n1. In the flow editor, click **Add Step → Screenshot**.\n2. Name it *Verify Home Screen*.\n3. Set the tolerance (e.g., 0.2).\n4. Optionally attach a fallback selector.\n\nIf the screenshot fails, you can configure the flow to **Retry with alternative selector** or **Abort and notify**.\n\n## Strategy 3 – Conditional Logic for Fallback Selectors\n\nPhoma supports `if` steps that evaluate a boolean expression. Use this to test whether a primary selector exists, and if not, try a secondary one.\n\n**Pseudo‑code example**:\n```\n# Step 1: Try primary selector\nTrySelect Element \"resource-id:com.example.app:id/username\"\n\n# Step 2: If not found, try fallback\nIfNotFound Then\n    TrySelect Element \"content-desc:Enter your username\"\nEndIf\n```\n\nIn the visual editor you create an **If** block, set the condition to *Element not found*, and add the fallback action inside the block.\n\n## Strategy 4 – Leverage External AI for Selector Updates\n\nWhile 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.\n\n**Workflow**:\n1. Export the failing selector as a JSON snippet.\n2. 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.\"\n3. Receive a revised selector.\n4. Replace the old selector in Phoma.\n\nBecause the AI runs on your own subscription, there are no extra costs.\n\n## Strategy 5 – Modular Sub‑Flows for Reusable Actions\n\nComplex 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.\n\n**Creating a sub‑flow**:\n1. In the flow editor, click **New Sub‑Flow**.\n2. Name it *LoginScreen*.\n3. Add steps: open app, wait for login field, type username, type password, tap login.\n4. Save.\n5. In any main flow, add **Run Sub‑Flow → LoginScreen**.\n\nNow a UI change in the login screen only requires a single edit.\n\n## Practical Example – Self‑Healing Login Flow\n\nLet’s build a flow that logs into a generic app and demonstrates the techniques above.\n\n1. **Start** – *Launch App* (use *adb shell am start* or the built‑in *Open App* step).\n2. **Wait** – *Wait for Element* with selector `resource-id:com.example.app:id/login_field` (primary).\n3. **Screenshot Checkpoint** – *Verify Login Screen* (tolerance 0.2).\n4. **If Not Found** – *If Element not found* → *TrySelect* `content-desc:Enter your username` (fallback).\n5. **Type Username** – *Type Text* on the element found.\n6. **Type Password** – *Type Text* on `content-desc:Enter your password`.\n7. **Tap Login** – *Tap* on `resource-id:com.example.app:id/login_button`.\n8. **Wait for Home** – *Wait for Element* `resource-id:com.example.app:id/home_icon`.\n9. **End** – *Success* message.\n\n**Key points**:\n- The primary selector is tried first; if the app updates the ID, the *If Not Found* block activates the fallback.\n- The screenshot checkpoint ensures that even if the element hierarchy changes but the visual layout stays similar, the flow can continue.\n- All steps are modular; you could extract steps 2‑7 into a sub‑flow *PerformLogin* for reuse.\n\n## Testing and Monitoring\n\n### Unit‑test each selector\nRun 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.\n\n### Continuous verification\nSchedule the flow to run nightly on a dedicated test phone. Enable **Email notification** on failure so the ops team can act quickly.\n\n### Version control for selectors\nStore 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.\n\n## Summary of Actionable Steps\n\n1. **Audit existing selectors** – list primary and secondary attributes for each step.\n2. **Add screenshot checkpoints** after critical UI transitions.\n3. **Introduce If‑Not‑Found logic** to switch to fallback selectors.\n4. **Create reusable sub‑flows** for common actions.\n5. **Document selector changes** in a shared changelog.\n6. **Test nightly** on a stable device and enable alerts.\n\nBy following these steps, your Phoma flows become resilient to UI churn, reducing maintenance overhead and keeping your automation pipelines reliable.\n","https://blog-api.phomaapp.com/api/blog/posts/build-self-healing-phoma-flows-that-adapt-to-ui-changes/assets",1796035639052]