Appium/Wdio-无法关闭Android上的位置权限警报 [英] Appium/wdio - unable to dismiss location permissions alert on Android
问题描述
我正在使用 webdriver.io 编写一套 Cordova 应用进行测试.
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",
在我的一项测试中,我试图以编程方式接受在WebView顶部启动的应用程序上显示的 Location Permissions native modal .
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.
我可以轻松地在iOS中使用 browser.alertAccept() ,但后者似乎不适用于Android.
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();
}
}
如何使用wdio消除Android上的本机警报?
How can I dismiss the native alert on Android using wdio?
推荐答案
- 权限对话框是本机对话框,因此您无需切换到Web视图即可将其关闭.
- 与允许/拒绝权限按钮相关联的android
id
,因此您可以使用它代替已使用的标识符.
- The permission dialog is native, so you don't need to switch to the webview to dismiss it.
- There is an android
id
associated with the allow/deny permission button, so you can use that instead of the identifier you have used.
allow
按钮的id
是:com.android.packageinstaller:id/permission_allow_button
.
deny
按钮的id
是:com.android.packageinstaller:id/permission_deny_button
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
这篇关于Appium/Wdio-无法关闭Android上的位置权限警报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!