Espresso - click on the button of the dialog
I see that you're trying to test app permission. I think it might be pretty impossible to test it with Espresso. You may need to take this action another UI testing tool called uiatomator
.
uiatomator
, another great tools made by Google allows you to test your Android system functions like notifications and screen lock. You can use it with Espresso test framework.
For finding more info, please read this article:
http://qathread.blogspot.com/2015/05/espresso-uiautomator-perfect-tandem.html
and uiautomator documentation, which you would find here.
Well, it can be as simple as
onView(withText("Allow")).perform(click());
Of course this is not a perfect solution, so there are two ways to go to make it more robust: either analyze the app with hierarchyviewer to find hints on how to identify the button (e.g. content description), or dive into the Android source code for the tips (e.g. button's resource ID).
EDIT
Well, it's not that simple. I wrote an article about using UiAutomator to make this work.