Appium/wdio - unable to dismiss location permissions alert on Android

假装没事ソ 提交于 2019-11-28 06:17:45

问题


I'm using webdriver.io to write a suite of Appium tests for a hybrid Cordova App.

"appium": "^1.10.0",
"wdio-appium-service": "^0.2.3",
"wdio-jasmine-framework": "^0.3.8",
"webdriverio": "^4.14.1",

In one of my tests I am trying to programmatically accept the Location Permissions native modal presented on App launch on top of the WebView.

I can easily do so in iOS using browser.alertAccept() but the latter does not seem to work for Android.

I also tried to switch to the native context to dismiss it but had no luck.

function dismissLocationPermissions() {
  if (browser.isAndroid) {
    new WebView().switchToContext(0);
    browser.pause(2000);
    const ANDROID_ACCEPT_ALERT_SELECTOR = "//*[@class='android.widget.Button'][2]";
    // OR '*//android.widget.Button[@text="ALLOW"]' ?
    $(ANDROID_ACCEPT_ALERT_SELECTOR).click();
    WebView().switchToContext(1);
  } else {
    browser.alertAccept();
  }
}

How can I dismiss the native alert on Android using wdio?


回答1:


  1. The permission dialog is native, so you don't need to switch to the webview to dismiss it.
  2. There is an android id associated with the allow/deny permission button, so you can use that instead of the identifier you have used.

The id for allow button is: com.android.packageinstaller:id/permission_allow_button .
The id for deny button is: com.android.packageinstaller:id/permission_deny_button




回答2:


There is autoGrantPermissions DesiredCapability, if you set it to true - Appium will automatically determine which permissions are required by your application and grant them to the application during the installation procedure.

The capability is set to false by default so you need to explicitly set it like:

DesiredCapabilities dc = new DesiredCapabilities();
dc.setCapability(MobileCapabilityType.NO_RESET, false);
dc.setCapability(AndroidMobileCapabilityType.AUTO_GRANT_PERMISSIONS, true);
driver = new AndroidDriver<>(url, dc);

More information:

  • Appium Desired Capabilities
  • Application Setup


来源:https://stackoverflow.com/questions/56072136/appium-wdio-unable-to-dismiss-location-permissions-alert-on-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!