Permission prompts in automated tests: a pattern catalog
simctl privacy grant, adb shell pm grant and iOS system alert automation: set permission state per run and test the deny, permanent-deny and Allow Once paths.
- Written by
- Yuvan Sundrani
- Read time
- 8 min read
- Published

Key Takeaways
- Maestro allows all permissions by default, and adb install -g grants every manifest permission, so a suite built on either never sees the first-launch prompt.
- On Android 11 and later, a second Deny sets USER_FIXED and the dialog stops appearing; pm clear-permission-flags resets it for the next run.
- On iOS, requestWhenInUseAuthorization() does nothing once the status has left notDetermined, so the deny path needs a reset before every run.
- Apple says not to write a UI interruption monitor for an alert the test expects; the test should handle it directly.
- XCUIProtectedResource has no notifications case, so notification permission needs a separate route on iOS.
Treat permission state as test input: set it explicitly before each run, then drive the prompt only in the tests whose subject is the prompt.
Runtime permission states on iOS vs Android
| State | Android source of truth | iOS source of truth |
|---|---|---|
| Never asked | No grant, no flags | notDetermined |
| Granted | Granted | authorizedWhenInUse or authorizedAlways |
| Denied, can ask again | Denied, USER_SET flag | n/a: iOS has no second prompt |
| Denied, no more prompts | Denied, USER_FIXED flag (second Deny) | denied |
| Granted once | One-time grant (Android 11+, location, mic, camera) | Allow Once, which reverts to notDetermined |
Android's second Deny is final. The Android 11 permission changes state that tapping Deny for the same permission more than once means the user doesn't see the dialog again, and that a permanent denial carries the USER_FIXED flag. A test that denies on every run passes once, then exercises a different path from run three onward.
iOS asks exactly once. Apple's requestWhenInUseAuthorization reference says the method does nothing if the status is anything other than notDetermined, and lists Don't Allow as "no further authorization requests are allowed." Allow Once is temporary: it expires when the app is no longer in use and reverts to notDetermined.

Permission state commands: simctl privacy, adb pm grant
# Android permission state
adb shell pm grant com.example.app android.permission.ACCESS_FINE_LOCATION
adb shell pm revoke com.example.app android.permission.ACCESS_FINE_LOCATION
adb shell pm clear-permission-flags com.example.app \
android.permission.ACCESS_FINE_LOCATION user-set user-fixed
adb install -g app-debug.apk # grants every permission in the manifest
# iOS Simulator
xcrun simctl privacy booted grant location com.example.app
xcrun simctl privacy booted revoke photos com.example.app
xcrun simctl privacy booted reset all com.example.app
- pm grant and pm revoke accept any permission declared in the app's manifest on Android 6.0 and later, per the adb reference. An undeclared permission fails.
- Revoking kills the process. Android's permission guide says the app's process terminates when the user revokes a permission. A revoke mid-session is a cold start, and the test should assert on restored state.
- simctl privacy reset all returns permissions to defaults "as if the app had never been installed before," per the Xcode 11.4 release notes. Those notes point to simctl help privacy for the service list, which varies by Xcode version; check it before relying on camera.
- Notifications are separate on both platforms. On Android 13 and later, POST_NOTIFICATIONS is a runtime permission and notifications are off by default for new installs. On iOS, XCUIProtectedResource lists location, photos, camera, contacts and more, but no notifications case.
Inside XCUITest, XCUIApplication.resetAuthorizationStatus(for:) does the reset in-process. Apple's Xcode 11.4 notes describe it as the way to test first-launch and first-access flows.
Permission prompt test cases
Pattern
Android setup
iOS setup
Assert
Happy path, prompt skipped
pm grant before launch
simctl privacy grant
Feature works with access
First launch, Allow
Fresh install without -g
reset all
Prompt appears at the right moment, feature works after Allow
First launch, Deny
Fresh install, tap Deny once
reset all, tap Don't Allow
Fallback UI, no crash, no retry loop
Permanently denied
Deny twice, or set USER_FIXED
Deny once
App offers a path to Settings; no dead button
Granted once
Choose "Only this time", background the app
Choose Allow Once, background the app
Next launch asks again
Revoked mid-session
pm revoke while running
simctl privacy revoke while running
App restarts into a sane state
- Background location. Apps targeting Android 11 or later must request background location separately; per Android's location docs, asking for foreground and background together makes the system ignore the request and grant neither. The dialog also has no "Allow all the time" option there. Test the second request as its own pattern.
- Notifications on Android 13+. The push notification testing post covers delivery; this catalog covers the permission gate in front of it.

System permission dialog automation by tool
The prompt is drawn by the system, so in-process frameworks can't reach it. Android's docs place UI Automator as the framework that "lets you test an app from outside of the app's process," with a watchFor API for handling permission dialogs. Espresso, which runs in the app's process, needs UI Automator or a pre-grant.
On iOS, Apple's guide on UI interruptions is specific: an interruption monitor fires only when an unrelated UI blocks the element the test needs. For an alert the test expects, Apple says not to write a monitor and to handle the alert as part of the test.
Tool defaults then decide what gets tested:
Tool
Default
Effect on first launch
Maestro launchApp
All permissions allowed unless permissions says otherwise
Prompt never shown
Appium UiAutomator2 autoGrantPermissions
Grants all requested permissions at session start when set
Prompt never shown
Appium XCUITest autoAcceptAlerts
Accepts all alerts, including privacy alerts, when set
Deny path never taken
adb install -g
Grants every manifest permission
Prompt never shown
Each default is right for the happy-path suite and wrong for the first-launch suite. Run two configurations: one that pre-grants for speed, and one that installs clean and drives the dialog.
Autosana for permission prompt testing
Autosana is an AI end-to-end testing agent for iOS, Android and web apps. Our agent works from screenshots, so the system permission dialog is on screen like any other control, and our Autosana sandboxes can also grant permissions before the app opens.
Autosana key features for permission states
- Grants at start, notifications included. --grant on start or launch grants permissions before the app opens. On the iOS Simulator it covers location, location-always, motion, notifications, photos, camera, microphone, contacts, calendar, reminders, media library, health, HomeKit, Face ID, Siri, speech and user tracking. On Android it takes the full permission name, which the manifest must request.
- The dialog tapped like any screen. A first-launch run starts without --grant, and the agent taps the prompt using pixels in the latest screenshot. The tap math behind that is in why coordinate taps miss.
- The deny path as one instruction. Our tests are written as instructions: "Deny the location prompt and check that the app offers a way to choose a city manually." Grants belong to the sandbox and are reapplied after every install, so a first-launch deny test needs a sandbox started without them.
autosana sandbox start --platform ios --bundle-id com.example.app
autosana sandbox look --description "Location prompt on first launch"
autosana sandbox tap <x>,<y> --description "Don't Allow"
autosana sandbox launch --grant location --description "Grant, then restart"

Suite auth instructions run once before every flow, including how the agent should answer a system prompt such as the password manager. Source: Autosana Suites docs video.
Autosana customer results
- Gobi (social maps app) moved from 13 brittle Maestro tests to 30+ Autosana tests, and nightly runs caught six real bugs in five days. See the Gobi case study.
Where Autosana fits less well
- Real iPhones can't be granted permissions ahead of time; the agent taps the prompt there.
- Push notifications on private physical devices need an enterprise contract.
- We don't run existing XCTest bundles, including ones built around resetAuthorizationStatus(for:).
Why use Autosana for permission prompt testing?
- Both configurations from one tool. Pre-grant for the fast suite, leave the prompt for the first-launch suite.
- Notification permission on the simulator. --grant notifications covers the case XCUITest's reset API leaves out.
- System alerts need no special handling. The agent sees the dialog in the screenshot and taps it.
- Deny paths read like the requirement. One instruction describes the denial and the expected fallback.
- Nothing to pay up front. Pay as you go includes up to 1,000 free AI actions each month.
Conclusion
Run the pre-granted configuration on every PR; it's fast and covers the feature. Run the first-launch configuration (Allow, Deny, permanent deny, granted once) on any PR that touches permission code or onboarding, and nightly otherwise, since those paths change only when that code does.
The mobile app testing checklist lists permission checks among its release items.
The iOS Simulator guide covers the simulator setup these commands assume.
FAQs
1. What does xcrun simctl privacy grant do?
It sets a privacy permission for an app on a simulator without showing the system prompt.
2. How do I reset Android's don't-ask-again state?
adb shell pm clear-permission-flags <package> <permission> user-set user-fixed clears both flags.
3. Why does my iOS deny test only work once?
Location authorization prompts only from notDetermined. Reset with simctl privacy reset before each run.
4. Can Espresso tap a permission dialog?
The dialog runs outside the app process. Use UI Automator or pre-grant the permission.
5. Does simctl privacy cover notifications?
Its services vary by Xcode version; XCUIProtectedResource has no notifications case either.
6. Can Autosana grant notification permission on the iOS Simulator?
Yes. --grant notifications on sandbox start or launch grants it before the app starts.
Sources
- Android Developers: Permissions updates in Android 11
- Apple Developer: requestWhenInUseAuthorization()


