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

Steve

02/14/2020, 5:51 PM
Using Espresso, is there a way to determine if the app under test has a certain permission granted? I've tried calling checkPermission on the target context, but the tests seem to run as a different user than the app, so it always indicates the permission is denied.
Also, this is the one permission (Write_Settings) that can't be automatically granted using the GrantPermissionRule 😿
s

stantronic

02/14/2020, 5:59 PM
Can you just test the intent that requests permissions?
s

Steve

02/14/2020, 6:16 PM
I'm actually not trying to test the permission. The issue I have is that it's requested right away, and depending on whether it's a fresh install or the app was already installed, the permission might have been granted
I don't care about the permission in the context of my tests. I just want to know if I should wait for the dialog to show and dismiss it or not
i

Ianmedeiros

02/14/2020, 6:26 PM
Maybe you can use UIAutomator just to detect the dialog?
s

Steve

02/14/2020, 6:28 PM
I'll check it out, thanks.
I don't think that's what I want. I can't see how to detect the dialog if there
z

Zach Kovar

02/14/2020, 7:11 PM
If you don't care about the permission in the context of my tests — it sounds like using
GrantPermissionRule
may be a good course of action. This lets you ensure that the permissions you need will already be granted and you don't need to worry about the uncertainty.
s

Steve

02/14/2020, 7:16 PM
As I said earlier, this is the one permission (Write_Settings) that cannot be granted that way
z

Zach Kovar

02/14/2020, 7:28 PM
Ah — sorry, missed that comment.
s

Steve

02/14/2020, 7:43 PM
No worries. It looks like UiAutomator had what I need to quickly match or skip a dialog
5 Views