Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 487
Suban Dhyako Avatar asked Sep 06 '18 05:09

Suban Dhyako


People also ask

How to handle permission pop-ups in Appium?

Handle permission pop-ups 1 Grant all permissions for Android apps#N#To test Android apps, use Appium’s autoGrantPermissions capability to... 2 Allow or deny all permissions for iOS apps#N#To test iOS apps, use Appium’s autoAcceptAlerts and autoDismissAlerts... 3 Allow or Deny any permission pop-up for Android and iOS apps More ...

How to enable or disable permissions for an app on Windows?

If you want to enable or disable permissions for a specific app, you’ll need to open its app settings on Windows. There are two ways you can go about that. Step 1: Open the Start menu and click on All apps at the top to view a list of installed apps. Step 2: Scroll down to locate the app for which you wish to configure permissions.

How do I test iOS apps with Appium?

To test iOS apps, use Appium’s autoAcceptAlerts and autoDismissAlerts capabilities to handle app permissions. autoAcceptAlerts will automatically accept all permission pop-ups. autoDismissAlerts will automatically dismiss all permission pop-ups. This includes privacy access permission pop-ups (e.g., location, contacts, photos).

Does Appium’s new permissions permission feature work on real devices?

One caveat: the new capability only works for simulators, so those of you running on real devices will have to sit tight and keep manually automating those popups. Setup Because Appium relies on some newfangled 3rd-party software to make the permissions magic happen, we need to get said software on our machines before we try and run our test.


3 Answers

The above answers didn't resolve my problem. I solved this problem by using the the caps of "autoGrantPermissions".

Setup:

desired_caps['autoGrantPermissions'] = True

You will have to disable the noReset caps to False, otherwise it won't work. See reference here: http://appium.io/docs/en/writing-running-appium/caps/

like image 149
anne Avatar answered Dec 26 '22 12:12

anne


Before you launch/initialise the appium driver, just give all the required permissions to the respective app through adb command as below so that the ALLOW pop up won't be displayed:

        adb -s yourDeviceSerialNumber shell pm grant your.app.packagename android.permission.READ_EXTERNAL_STORAGE
        adb -s yourDeviceSerialNumber shell pm grant your.app.packagename android.permission.WRITE_EXTERNAL_STORAGE
        adb -s yourDeviceSerialNumber shell pm grant your.app.packagename android.permission.ACCESS_FINE_LOCATION
        adb -s yourDeviceSerialNumber shell pm grant your.app.packagename android.permission.CAMERA
        adb -s yourDeviceSerialNumber shell pm grant your.app.packagename android.permission.READ_CONTACTS

You can call these through your automation code for android

OR

There is appium capabilities to grant permission : autoGrantPermissions Appium automatically determine which permissions your app requires and grant them to the app on install. Defaults to false. If noReset is true, this capability doesn't work.

http://appium.io/docs/en/writing-running-appium/caps/

like image 44
shiv Avatar answered Dec 26 '22 11:12

shiv


One solution would be to go to Settings app and automate the scenario within that. You can go to Settings app (in fact, any iOS system app) by providing the bundle ID. For settings app it's com.apple.Preferences

I am using ruby, but the idea might be the similar for other clients.

def launch_settings_app
    @driver.execute_script('mobile: launchApp', {'bundleId': "com.apple.Preferences"});
end

You can find other bundle IDs here https://emm.how/t/ios-11-list-of-default-apps-and-bundle-id-s/465 Or using command line - this will return bundle ids for all installed apps on your device: ideviceinstaller -u device_udid -l

like image 33
Andris Akacenoks Avatar answered Dec 26 '22 12:12

Andris Akacenoks