[{"data":1,"prerenderedAt":20},["ShallowReactive",2],{"blog-post-en-verify-android-toggle-states-phoma-accessibility":3},{"slug":4,"lang":5,"title":6,"summary":7,"date":8,"tags":9,"tag_slugs":15,"thumbnail_url":16,"translations":17,"body":18,"asset_base":19},"verify-android-toggle-states-phoma-accessibility","en","Verify Android Toggle States in Phoma With Accessibility Checks","Learn to assert checked, selected, and toggle states in Phoma flows using Android accessibility properties instead of brittle text matches.","2026-12-06",[10,11,12,13,14],"android","phoma","qa-testing","accessibility","ui-automation",[10,11,12,13,14],"https://blog-api.phomaapp.com/api/blog/posts/verify-android-toggle-states-phoma-accessibility/thumbnail.svg?lang=en",[5],"## Why state matters more than visible text\nA switch can look enabled while the accessibility node is still animating. A checkbox can show a checkmark drawn by the app, but the node may not report checked until the app finishes saving the setting. If a flow taps and immediately reads text, it can pass by accident or fail for the wrong reason.\n\nPhoma flows can inspect the Android accessibility tree, so they can check semantic properties such as checked and selected. This is better than comparing a label because labels change with language, theme, or marketing copy. State is what the app actually uses.\n\n## Pick the element before reading its state\nStart in the mirrored phone view. Open the screen you want to test, then inspect the element tree. Look for a node whose class matches the control.\n\n- For a switch, look for android.widget.Switch.\n- For a checkbox, look for android.widget.CheckBox.\n- For a radio button, look for android.widget.RadioButton.\n- For a selected list row, look for a node with selected=true.\n\nPrefer selectors that do not depend on position. A good selector is usually one of these, in order:\n\n```\nresource-id='com.example.app:id/notifications_switch'\n```\n\n```\nclass='android.widget.Switch' AND content-desc='Notifications'\n```\n\nAvoid selectors based only on text, bounds, or child index. Text changes. Bounds change with font size. Indexes change when a list inserts an item.\n\n## Inspect first, automate second\nBefore writing the flow, answer three questions in the element tree.\n\n1. Which node represents the control itself, not the label next to it?\n2. Which property proves its state: checked, selected, or text?\n3. What selector will still match after a small app update?\n\nFor example, a settings screen may have a row with the label Notifications and a separate switch node. If you tap the row, the app may open a subpage. If you tap the switch node, the state changes. The element tree makes that difference visible.\n\n## Build a read-assert-adjust pattern\nA reliable flow does not just tap and hope. It reads the current state, changes it if needed, waits for the new state, and asserts it.\n\n### Example: turn on notifications\nUse a flow like this in the visual builder.\n\n```\nOpen App: com.example.app\nWait For Element: content-desc='Settings', timeout=10s\nTap: content-desc='Settings'\nWait For Element: resource-id='com.example.app:id/notifications_switch', timeout=10s\nRead Element: resource-id='com.example.app:id/notifications_switch'\nProperty: checked\nStore: notifications_checked\n\nIf notifications_checked = false\n  Tap: resource-id='com.example.app:id/notifications_switch'\nEnd If\n\nWait For Element: resource-id='com.example.app:id/notifications_switch'\nRead Element: resource-id='com.example.app:id/notifications_switch'\nProperty: checked\nStore: notifications_checked_after\nAssert: notifications_checked_after = true\n```\n\nThis pattern is reusable. Change the selector and expected state to test dark mode, analytics consent, or any switch.\n\n## Wait for the state to settle\nAndroid can update a control after a network request, database write, or animation. A 300 millisecond pause is not a strategy. Use a short repeat loop instead.\n\n```\nRepeat up to 5 times\n  Read Element: resource-id='com.example.app:id/notifications_switch'\n  Property: checked\n  Store: current_state\n  If current_state = true\n    Exit Loop\n  End If\n  Wait: 300 ms\nEnd Repeat\n```\n\nThen assert current_state. This keeps the flow fast when the app responds quickly and patient when it does not.\n\n## Use conditions for guards, not guesses\nConditions should express product rules. If a switch is already on, do not tap it. If it is off, turn it on and verify.\n\n```\nIf notifications_checked = false\n  Tap: resource-id='com.example.app:id/notifications_switch'\nEnd If\n```\n\nFor radio buttons, read selected. For checkboxes, read checked. For list rows, read selected only if the app reports it. Do not treat a highlight drawable as proof.\n\n## Make failures explain themselves\nWhen a state assertion fails, take a screenshot and record what the flow expected. A useful failure message says what was read, not only that something went wrong.\n\n```\nAssert: notifications_checked_after = true\nOn Failure: Save Screenshot\nOn Failure: Continue With Next Step\n```\n\nIf the state property is unreliable on a custom control, use content-desc as a secondary signal, but keep the primary assertion on the property whenever possible. Screenshot checks are a fallback, not the first choice.\n\n## Keep the flow portable across phones\nBecause these steps use element properties instead of coordinates, the same flow can run on several test phones. A selector based on resource-id or content-desc is more likely to work after a screen rotation, font-size change, or device manufacturer skin.\n\nKeep flows visual and readable. Name steps after the intent: Enable notifications, Verify notifications switch is on, Save failure screenshot. When you share the flow with a team using Phoma Team or Business, the meaning stays clear. Phoma flows run on the user's own computer and phones, and using your own phones has no phone or flow limit.\n\nThis is the practical difference between tapping where something looks like a switch and checking the Android node that represents it. State-based checks are less brittle, easier to debug, and closer to what the app actually does.\n","https://blog-api.phomaapp.com/api/blog/posts/verify-android-toggle-states-phoma-accessibility/assets",1796549932683]