https://kotlinlang.org logo
#android
Title
# android
a

AntoineJojo

08/30/2018, 3:43 PM
Hi! Does anyone know how to revoke a permission before a UI test? I use GrantPermissionRule to grant Location permission but once granted it stays granted and I can’t test the case when permission is not granted.
m

max.cruz

08/30/2018, 4:04 PM
adb shell pm revoke com.name.app android.permission.READ_PROFILE
a

AntoineJojo

08/30/2018, 4:08 PM
and you can it in @after method during instrumented tests?
m

max.cruz

08/30/2018, 4:18 PM
a

AntoineJojo

08/31/2018, 7:19 AM
Hum... perfect, I’ll try it. It’s crazy that there’s almost no resources about testing permissions on the web.
If anyway you heard about nice articles about it I’ll be really interested
I managed to have it working after lot of researches (not well documented). Here is how I revoke permission:
Copy code
val uiAutomation = InstrumentationRegistry.getInstrumentation().uiAutomation
uiAutomation.executeShellCommand("pm revoke ${getTargetContext().packageName} $ACCESS_FINE_LOCATION")
2 Views