UIAutomation:未实际点击“警报"视图上的“取消"按钮 [英] UIAutomation : Cancel button on Alert view is tapped without actually doing it

查看:119
本文介绍了UIAutomation:未实际点击“警报"视图上的“取消"按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在UIAutomation中面临着这个奇怪的问题.

I'm facing this weird problem in UIAutomation.

我正在检查警报.在这种情况下,我试图记录警报标题和警报消息.我的代码是:

I am checking an alert. In that, I am trying to log alert title and alert message. My code for this is:

UIATarget.onAlert = function onAlert(alert) {
UIALogger.logMessage("alert Shown");
UIALogger.logMessage(frontApp.alert().name());
UIALogger.logMessage(frontApp.alert().staticTexts()[1].value());
}

var target = UIATarget.localTarget().frontMostApp().mainWindow();
target.scrollViews()[0].buttons()["saveB"].tap();
UIATarget.localTarget().delay(2);

我没有点击警报中的取消"按钮将其关闭.但是,它会自动被窃听.我不知道为什么即使在logMessages中,我也看到

I am not tapping on cancel button in the alert to dismiss it. But, it is getting tapped automatically. I don't know why. Even in the logMessages, I see

target.frontMostApp().alert().cancelButton().tap()

此行自动执行.我的脚本文件中的任何地方都没有此行.是iOS中的错误吗?

this line getting executed automatically. I don't have this line anywhere in my script file. Is it a bug in iOS?

推荐答案

总是敲击警报上的取消"按钮,以阻止应用程序阻塞除非onAlert回调返回true.通过返回true,您告诉警报处理机制将点击相应的按钮以解除警报.

The cancel button on an alert is always tapped to keep the application from blocking unless the onAlert callback returns true. By returning true, you are telling the alert handling mechanism that you will handle tapping the appropriate button to dismiss the alert.

更改警报回调,使其看起来像这样:

Change your alert callback to look like this:

UIATarget.onAlert = function onAlert(alert) {
    UIALogger.logMessage("alert Shown");
    UIALogger.logMessage(frontApp.alert().name());
    UIALogger.logMessage(frontApp.alert().staticTexts()[1].value());
    return true;   // <-- Adding this line
}

相反,返回false或忽略返回值,则完全向警报处理机制发出信号,提示应轻按取消"按钮.

Conversely, returning false or leaving out a return value altogether signals to the alert handling mechanism that the cancel button should be tapped.

这篇关于UIAutomation:未实际点击“警报"视图上的“取消"按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆