Monday, 24 May 2021

Android GrantPermissionRule does not work with api-27

I've the permission rule configured as below in my MainActivityTest class

@Rule
public GrantPermissionRule permissionRule =
    GrantPermissionRule.grant(RECORD_AUDIO, WRITE_EXTERNAL_STORAGE);

When I run below command to execute the tests on emulator with api 27

./gradlew connectedCheck

It fails with the below error

com.example.myapplication.MainActivityTest > testLaunch_main_activity[Pixel_XL_API_27(AVD) - 8.1.0] FAILED 
        androidx.test.espresso.NoActivityResumedException: No activities in stage RESUMED. Did you forget to launch the activity. (test.getActivity() or similar)?
        at dalvik.system.VMStack.getThreadStackTrace(Native Method)

Surprisingly the permissions are showing as granted in the app info settings, but still its asking for permissions when the test is run on emulator with api version 27 (or lower)

Can someone please confirm if it is a bug in some android plugin or if I am missing anything here.

Source Code - https://github.com/vivekweb2013/test-android-project



from Android GrantPermissionRule does not work with api-27

No comments:

Post a Comment