Giving App permissions for Marshmallow at runtime in Appium

Hello All,

While running my tests the app is asking for permissions (location access, contacts access etc) for Android Marshmallow at runtime.

Please say how to give full permissions to app at runtime during the test script execution.

I asked about this a while back but have yet to see an answer. We worked around it by adding a method to our local adb module that can (re)install with all permissions (-g parameter)

@willosser, can you please explain it a bit more.

I tried re-installing the app with below step but somehow its not getting executed during the script run( looks like the script is skipping this step completely):
Runtime.getRuntime().exec(“adb install -g <.apk file path>”);

@pr4bh4sh, akarna8 explains the system call.

@akarna8, did you make this call before or after you started the appium driver? If it was before, then appium will reinstall your apk and wipe out the permissions you added.

@willosser, I made that call after starting of the appium driver.

@akarna8: So it sounds like your app asks for permission the moment it starts up. In order to get around this, you will need to set autoLaunch=false so you can then reinstall it with all permissions

@willosser, if I am giving
capabilities.setCapability(“autoLaunch”, false);
the script is not able to start the automation session and keeps on waiting.

Please help.

You say the script is not able to start the application, but I’m guessing you mean the application hasn’t started and you need to start it. Using Ruby, we accomplish this with the following code:

app_hash = {
    app_package: settings.app_package,
    app_activity: settings.app_activity
}
appium_driver.start_activity app_hash

I hope that is straight forward enough to convert into your language of preference