Test Android App Permissions with Phoma Flows
Permission prompts are a small part of an app, but they cause a large share of first-run bugs. A flow that tests only the happy path will miss the case where a user denies camera access, taps Open settings, returns, and expects the app to recover cleanly. Phoma is useful here because it can drive both the app and Android system dialogs from a Windows PC, without writing code. This guide focuses on one practical pattern: a permission-state flow that checks allow, deny, rationale, and recovery.
Why permission states need dedicated checks
Android permission behavior changes across OS versions, OEM skins, locale settings, and app versions. The same button may be labeled Allow, While using the app, or Don't allow. A manual tester may accept one path and never try the other. For QA, that leaves regressions hidden until a user hits them.
A Phoma flow gives you three advantages:
- It repeats the same sequence on every connected phone.
- It captures screenshots at the moment a dialog appears, which makes bug reports easier.
- It forces you to define expected behavior for denied permissions instead of assuming the app handles them.
Before you build the flow
Prepare the device and the test case first.
- Connect the phone to Phoma over USB or Wi-Fi and confirm the screen is visible.
- Install a build that has a known permission behavior. If possible, use a debug or QA build with stable element IDs.
- Decide the expected result for each permission. For example: camera denied should show a placeholder and a Grant access button; notifications denied should not crash; location denied should disable a map layer.
- Set the phone to a known state. If the app already has permission granted, the prompt will not appear. Clear the app data from Android Settings before the run, or use a fresh test device state if your build supports it.
This preparation matters because Phoma can only assert what you expect. If the flow says tap Allow but the dialog never appears, the failure is ambiguous. A clean starting state removes that ambiguity.
Map the permission sequence
Open the app manually once and write down the order of screens and dialogs. A typical sequence might be:
- Launch app.
- Splash screen.
- First-run welcome screen.
- Camera permission prompt.
- In-app rationale screen if the user denies.
- Notification permission prompt.
- Home screen with degraded features.
For each step, decide what Phoma should do: wait, tap, read text, or take a screenshot. Keep the flow small enough to debug. If the sequence has too many branches, split it into separate flows for each permission rather than one giant flow.
Pick selectors that survive updates
When you inspect an element, prefer selectors in this order:
- Resource ID, because it usually points to a specific control.
- Content description, because it often describes the action for accessibility.
- Text, but only when the text is stable and localized deliberately.
Example element attributes you might see:
resource-id=com.example.app:id/permission_allow_button
text=Allow
content-desc=Allow camera access
For system permission dialogs, resource IDs may belong to the permission controller and can vary by Android version. If the dialog is localized, text selectors can break when the phone language changes. For reliable tests, either set the test device to English, use resource IDs when available, or add a fallback selector based on content description.
A good pattern is to configure the tap step with one primary selector and one fallback. If the primary selector is not found within the timeout, Phoma tries the fallback. This is not cheating the app; it is making the test resilient to normal Android variation.
Build the allow path
Start with the simplest branch: the user grants permission.
- Add an Open App step for your package name.
- Add a Wait for Element step for the first permission dialog. Use a 5 to 10 second timeout on a cold start.
- Add a Tap step on the allow button.
- Add a Wait for Element step for the next screen or the in-app feature that depends on the permission.
- Add a Read Text step to capture a label that proves the feature is active, such as Camera ready or Notifications enabled.
- Add a screenshot checkpoint after the grant.
If the app shows a rationale screen before the system dialog, insert a Tap step for the Continue or Next button before the system prompt. Keep the rationale text in a Read Text step so the flow fails if the copy disappears.
Build the deny path
The deny path is where most permission bugs live.
- Launch the app from a clean state.
- Wait for the permission dialog.
- Tap the deny button. Depending on Android, this may be Don't allow, Deny, or a text button.
- Wait for the app response. It may show a rationale, disable a feature, or send the user to app settings.
- Use a condition to check which branch appeared.
A simple condition looks like this:
If element Open settings exists
Tap Open settings
Verify system app-info screen appears
Press Back
Verify app screen returns
Else
Verify rationale text is visible
End If
This condition is the heart of the test. It proves the app does not silently fail when permission is denied. If the app opens the system settings page, the flow should verify that the correct app page is shown, then press Back and confirm the app is still usable.
Add loops only when they clarify the test
Some apps ask for multiple permissions in one launch. Instead of duplicating many steps, use a loop that handles up to three permission prompts.
Repeat 3 times
If any permission dialog is visible
Tap the expected button for this test case
Wait for the dialog to disappear
Else
Exit loop
End If
End Repeat
Use loops carefully. A loop that blindly taps Allow can hide a bug where the app asks for a permission it should not request. For permission testing, it is often better to make each permission explicit so the failure report names the exact prompt that broke.
Verify recovery after denial
After the deny branch, reopen the app or return to the home screen. Then check the degraded state.
For example:
- If camera was denied, verify the camera placeholder is visible and the Grant access button exists.
- If notifications were denied, verify the app does not show a duplicate prompt on every launch.
- If location was denied, verify map tiles are disabled or a message explains why.
Take a screenshot after recovery. This gives developers evidence that the app is in the expected state, not just that the flow reached the end.
Run the flow on several Android versions
Permission dialogs are one of the most version-sensitive parts of Android. Run the flow on at least one device near your minimum supported version, one near the current version, and one OEM-modified device if your users have them.
If a selector fails on one device, inspect the element tree on that device before changing the flow. Do not replace a stable resource ID with a broad text selector just to make one phone pass. Instead, add a fallback selector and record why it exists.
Common failure modes
- The dialog never appears because the permission was already granted. Clear app data before the run.
- The flow taps the wrong Allow button because the app has its own consent screen. Use resource ID or content description to distinguish app UI from system UI.
- The deny button text changes by locale. Use a resource ID, set the test device to English, or use content description.
- The flow times out on a cold start. Increase the initial wait and wait for the splash screen before expecting the dialog.
- The app opens system settings and Phoma loses the app context. Verify the settings screen, then press Back and continue.
A reusable checklist
Before you call the flow done, confirm that it can answer these questions:
- Does the correct permission prompt appear on a clean install?
- Does the allow path enable the feature?
- Does the deny path show a rationale or safe fallback?
- Does the app recover when the user returns from system settings?
- Are screenshots captured for both allow and deny outcomes?
- Does the flow fail with a clear step name when a selector is missing?
A permission flow built this way is not just a test script. It is a repeatable definition of how your app should behave when users make different choices. That makes it valuable for regression testing, device lab checks, and bug reproduction without writing code.
