[{"data":1,"prerenderedAt":19},["ShallowReactive",2],{"blog-post-en-automate-android-ui-validation-with-phoma-ocr-steps":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},"automate-android-ui-validation-with-phoma-ocr-steps","en","Automate Android UI Validation with Phoma OCR Steps","Learn how to use Phoma’s OCR step to read and verify text in Android apps, enabling visual UI checks without manual inspection.","2026-11-17",[10,11,12,13],"phoma","android-automation","ocr","ui-testing",[10,11,12,13],"https://blog-api.phomaapp.com/api/blog/posts/automate-android-ui-validation-with-phoma-ocr-steps/thumbnail.svg?lang=en",[5],"## Introduction\nWhen you automate UI testing on Android devices, visual verification is often as important as functional checks. Seeing the exact text that appears on the screen—version numbers, error messages, toast notifications, or dynamic data—helps catch layout bugs, localization issues, and unexpected content changes. Phoma’s built‑in OCR (Optical Character Recognition) step lets you extract text from screenshots and compare it to expected values without writing any code.\n\nThis guide walks you through a complete end‑to‑end workflow: connecting your phone, building a visual validation flow, and using OCR to assert UI content. By the end you’ll have a reusable template that you can apply to any app, whether you’re running a single test phone or a fleet of devices.\n\n## Why OCR is a Critical Step in UI Automation\n\n- **Human‑readable validation**: UI bugs are often textual—missing strings, wrong grammar, or untranslated words. OCR translates pixels into usable data that can be evaluated in your flow.\n- **No reliance on element selectors**: Some screens expose UI elements through a WebView, custom view, or dynamic layout that makes stable selectors hard to create. OCR bypasses the need for perfect element trees.\n- **Dynamic content verification**: Real‑time data like order IDs, timestamps, or user‑specific fields change each run. OCR can read those values and feed them into downstream steps (e.g., logging or API calls).\n- **Cross‑app consistency**: Whether you’re testing a banking app, an e‑commerce client, or an internal tool, OCR works uniformly across any Android UI rendered on the screen.\n\n## Prerequisites\n\n1. **Phoma installed** on a Windows PC.\n2. **Android phone** with USB debugging enabled (or Wi‑Fi ADB pairing if you prefer wireless).\n3. **ADB drivers** installed for your device model.\n4. **Target app** installed and functional on the phone.\n\n> *Tip*: If you run into connection issues, see the quick‑start guide “Fix an Android Phone That Won't Connect to Phoma Over USB” for a checklist.\n\n## Step‑by‑Step Flow: Validate a Version Number with OCR\n\nBelow is a concrete example that checks the app’s “About → Version” screen. The same pattern can be reused for any text you want to verify.\n\n### 1. Connect the Phone\n\n- **USB**: Plug the phone into the PC, enable USB debugging, and accept the developer prompt. Phoma will auto‑detect the device.\n- **Wi‑Fi**: Open Phoma, go to *Settings → ADB → Enable Wireless ADB*, then follow the pairing instructions.\n\n### 2. Open the Target App from Phoma\n\nIn Phoma’s flow editor, add a **Launch App** step, specify the package name (e.g., `com.example.myapp`).\n\n```\n// Visual representation of the Launch App step in Phoma\nStep: Open App\nPackage: com.example.myapp\nActivity: .\nWait for launch: 2 sec\n```\n\n###  Zas 3. Navigate to the Version Screen\n\nAdd a **Tap** step targeting the “About” button (use a stable selector like `@type=Button/text=About`).\n\n```\nStep: Tap About Button\nSelector: @text=\"About\"\n```\n\n### 4. Wait for the UI to Load\n\nAdd a **Wait for Element** step with the version TextView selector.\n\n```\nStep: Wait for Version TextView\nSelector: @resourceId=\"com.example.myapp:id/version_text\"\nTimeout: 5 sec\n```\n\n### 5. Capture a Screenshot for OCR\n\nInsert an **Screenshot** step (named “Version Screenshot”). This step saves a PNG to the flow’s workspace, ready for OCR.\n\n```\nStep: Take Screenshot\nFile Name: version_screenshot.png\n```\n\n### 6. Run OCR on the Image\n\nAdd an **OCR** step, referencing the screenshot file.\n\n```\nStep: OCR Version Text\nImage Path: version_screenshot.png\nLanguage: eng\nOutput Variable: version_text\n```\n\n**What happens?** Phoma runs the device’s native OCR engine, extracts the visible characters, and stores the result in the variable `version_text`. You can inspect the output in the flow’s debug pane.\n\n### 7. Assert the Extracted Text\n\nCreate an **Assert Text** step (or **If** condition) that compares `version_text` against the expected version string (e.g., `1.4.3`).\n\n```\nStep: Assert Version Matches\nCondition: version_text == \"1.4.3\"\nOn Fail: Log \"Version mismatch – UI may have changed\"\n```\n\nIf the assertion fails, the flow stops (or continues, depending on your settings) and you receive a clear log indicating the OCR mismatch.\n\n### 8. Optional: Store the OCR Result for Later Use\n\nAdd an **Set Variable** step to save `version_text` into a flow‑level variable, e.g., `app_version`. This makes the extracted value available for subsequent steps like HTTP requests or reporting.\n\n```\nStep: Save Version to Variable\nVariable: app_version\nValue: version_text\n```\n\n## Real‑World Example: Validating Dynamic Order Total\n\nMany e‑commerce apps calculate totals based on user input. You can use OCR to verify that the displayed total matches a calculation performed in your test script.\n\n1. **Add a “Calculate Total” step** in your flow (using arithmetic steps built into Phoma).\n2. **Tap “Add to Cart”** for a known SKU.\n3. **Wait for the “Total” TextView** to appear.\n4. **Screenshot** the cart screen.\n5. **OCR** the screenshot, targeting the total amount region (you can crop the image using Phoma’s built‑in image editor).\n6. **Assert** that `total_text` equals your calculated value.\n\nThis pattern works for any numeric field: shipping cost, discount percentage, or remaining battery level.\n\n## Best Practices for Reliable OCR\n\n- **High‑contrast text**: Ensure the UI text has a dark foreground on a light background. If the app uses a dark theme, flip the contrast or enable “invert colors” temporarily.\n- **Consistent fonts & sizes**: OCR performance drops with exotic fonts or very small text (\u003C12sp). Set a minimum font size in the app’s theme if possible.\n- **Stable screenshots**: Use a **Screenshot** step instead of a **Screen Record** step, as the latter can produce variable frame rates.\n- **Crop to text region**: Phoma’s OCR step includes a simple crop UI. Isolating the text reduces noise and improves accuracy.\n- **Batch language detection**: If your app supports multiple languages, set the OCR language to `eng+fra+deu` (English + French + German) to cover all possibilities.\n- **Fallback to selector**: When OCR confidence is low, combine it with a traditional element selector. For example, capture OCR text and also read a hidden `content-desc` attribute for cross‑validation.\n\n## Troubleshooting Common OCR Issues\n\n| Symptom | Likely Cause | Fix |\n|---------|--------------|-----|\n| OCR returns empty string | No text detected (blurred image, low contrast) | Increase screenshot brightness/contrast, enable “night mode” for better contrast, crop tighter. |\n| OCR misreads numbers (e.g., “0” → “O”) | Font style or low resolution | Use a higher‑resolution screenshot (Phoma supports 2× scaling), ensure text is not italic. |\n| OCR step hangs | Large screenshot or heavy processing | Reduce screenshot size or split into smaller regions. |\n| OCR output contains extra whitespace | OCR engine includes spaces | Add a **Trim Whitespace** step after OCR to clean the variable. |\n\n## Extending OCR Beyond Simple Assertions\n\n- **Generate test reports**: Combine OCR results with **HTTP Request** steps to POST the extracted data to a CI dashboard. Example payload:\n```json\n{\n  \"test\": \"version_check\",\n  \"device\": \"SM-G991B\",\n  \"extracted_version\": \"{{app_version}}\",\n  \"timestamp\": \"{{now}}\"\n}\n```\n- **Dynamic data capture**: Store OCR results in a **CSV** step to build a log of UI text over multiple runs, useful for regression trend analysis.\n- **Conditional flow branching**: Use an **If** step that checks OCR text length; if too short, trigger a **Screenshot** step for manual review.\n\n## Putting It All Together – A Sample Flow Diagram\n\n1. **Launch App**\n2. **Tap About**\n3. **Wait for Version TextView**\n4. **Screenshot**\n5. **OCR**\n6. **Assert Version**\n7. **Log Success / Fail**\n8. **HTTP Request (optional)**\n\nYou can save this as a **Template Flow** inside Phoma, then duplicate it for each app or each device in your fleet. Because Phoma flows are visual, team members can edit the selectors without touching code, keeping the workflow maintainable.\n\n## Conclusion\n\nOCR turns a static screenshot into actionable data, bridging the gap between visual UI testing and automated validation. By integrating Phoma’s OCR step into your automation flows, you gain the ability to verify textual content that would otherwise require manual inspection. The approach is flexible—perfect for checking static version strings, dynamic order totals, error messages, or any other on‑screen text—while remaining easy to maintain across multiple apps and devices.\n\nStart with the version‑check example above, experiment with cropping and language settings, and gradually layer OCR results into your broader test reporting pipeline. Before long you’ll have a robust, no‑code method for ensuring that the UI not only works but also displays the correct text every time.\n","https://blog-api.phomaapp.com/api/blog/posts/automate-android-ui-validation-with-phoma-ocr-steps/assets",1796035639891]