Can't click Allow button in permission dialog in Android using Appium

后端 未结 5 1800
予麋鹿
予麋鹿 2021-02-08 21:30

I am unable to tap on Deny or Allow buttons on the permissions dialog in Android using Appium+Java. Do I need to add any capabilities before going to tap on those buttons? Below

5条回答
  •  闹比i
    闹比i (楼主)
    2021-02-08 22:03

    Appium gives you an API that detect the activity. Depending upon your device, you could get two activities - the package name may get stripped off or not:

    'com.android.packageinstaller.permission.ui.GrantPermissionsActivity',
    '.permission.ui.GrantPermissionsActivity'
    

    After detecting this activity, you need to find an element by locator(id/xpath):

    'com.android.packageinstaller:id/permission_message'
    

    Then you can obtain the text of that message if you are interested in it. If you care which permission it is, you can match it against expected strings or regular expressions. If not, you can blindly accept by finding and clicking the element by id:

    'com.android.packageinstaller:id/permission_allow_button'
    

    If you'd rather not click 'allow' on all those windows, you can use adb to add all the permissions at once before you start testing (but after Appium has installed your app). If you know all the perms your app will need, you can add them with one command:

    pm grant $app_name $space_delimited_set_of_perms
    

    Or you can add all permissions one at a time, which takes 1.5-2 seconds per attempt.

    Reference : https://discuss.appium.io/t/android-m-and-permissions/5760/13

提交回复
热议问题