Andrey
Andrey

Reputation: 53

How to automatically accept Alerts with Appium -- permissions Android 6.0

Environment:

I need to accept any permission alerts(Android 6.0 -- sms,location and etc) automatically.

What I tried:

  1. Use driver.switchTo().alert().accept();

    Result:

    org.openqa.selenium.WebDriverException: Not yet implemented. Please help us: http://appium.io/get-involved.html

  2. Set capabilities:

    capabilities.setCapability("autoGrantPermissions", "true"); capabilities.setCapability("autoAcceptAlerts", "true");

    Result: it doesn't work

Upvotes: 1

Views: 21371

Answers (6)

Abby
Abby

Reputation: 11

capabilities.setCapability(AndroidMobileCapabilityType.AUTO_GRANT_PERMISSIONS, true);

It does work.

You can try it.

Upvotes: 1

Gourav Mahindra
Gourav Mahindra

Reputation: 21

It will definitely work for you.

DesiredCapabilities cap=new DesiredCapabilities();
cap.setCapability(AndroidMobileCapabilityType.AUTO_GRANT_PERMISSIONS,true);

Upvotes: 2

Emjey
Emjey

Reputation: 2063

Just add 'autoGrantPermissions': 'true', to your desired capabilities!

Please note! This will auto accept all the permissions where-ever applicable and is only valid for android system permissions. This is not applicable for app customized developed permissions.

Upvotes: 1

Isaac A
Isaac A

Reputation: 93

try adding capability: 'autoGrantPermissions': 'true',

had the same issue, this solved it for me.

Upvotes: 0

SaiPawan
SaiPawan

Reputation: 1194

It wont work in appium.If your alert contains 'ALLOW' button.Try to use below code:

driver.findElementByAccessibilityId("ALLOW").click();

This will click on "ALLOW" button which means accepting the alert.

Upvotes: 2

Vinod
Vinod

Reputation: 976

You can give all the required permissions to the app before you launch the app. Below is the list of commands for required permissions. You can execute these commands through your Java code.

    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
    adb -s yourDeviceSerialNumber shell pm grant your.app.packagename android.permission.WRITE_CONTACTS

Upvotes: 1

Related Questions