Reputation: 53
Environment:
I need to accept any permission alerts(Android 6.0 -- sms,location and etc) automatically.
What I tried:
Use driver.switchTo().alert().accept();
Result:
org.openqa.selenium.WebDriverException: Not yet implemented. Please help us: http://appium.io/get-involved.html
Set capabilities
:
capabilities.setCapability("autoGrantPermissions", "true");
capabilities.setCapability("autoAcceptAlerts", "true");
Result: it doesn't work
Upvotes: 1
Views: 21371
Reputation: 11
capabilities.setCapability(AndroidMobileCapabilityType.AUTO_GRANT_PERMISSIONS, true);
It does work.
You can try it.
Upvotes: 1
Reputation: 21
It will definitely work for you.
DesiredCapabilities cap=new DesiredCapabilities();
cap.setCapability(AndroidMobileCapabilityType.AUTO_GRANT_PERMISSIONS,true);
Upvotes: 2
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
Reputation: 93
try adding capability:
'autoGrantPermissions': 'true',
had the same issue, this solved it for me.
Upvotes: 0
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
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