Search code examples
appiumappium-iosappium-android

How to enable/disable app permission using Appium?


My app need the multiple app permission. I need to check how my app behaves by allowing or denying the different permission. How can i enable/disable the app permission from the appium to create the multiple scenario?

For example lets say my app need to permissions: permission1 and permission2.

scenario 1 = allow permission1 allow permission2

scenario 2 = allow permission1 deny permission2

scenario 3 = deny permission1 allow permission2

scenario 4 = deny permission1 deny permission2

Solution

  • I found the solution for android using adb shell command.

     String packageName= ((AndroidDriver) driver).getCurrentPackage();
     String grantCameraPermission= "adb shell pm grant " + packageName +" android.permission.CAMERA";
     String grantLocationPermission= "adb shell pm grant " + packageName +" android.permission.ACCESS_FINE_LOCATION";
     String revokeCameraPermission= "adb shell pm revoke " + packageName +" android.permission.CAMERA";
     String revokeLocationPermission= "adb shell pm revoke " + packageName +" android.permission.ACCESS_FINE_LOCATION";
            try {
                Runtime.getRuntime().exec(grantCameraPermission);
                Runtime.getRuntime().exec(revokeLocationPermission);
    
            } catch (IOException e) {
                e.printStackTrace();
            }
    

    Here is the list of the Android Permission