4

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);

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()

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

4

1 回答 1

9

除非onAlert回调返回,否则始终点击警报上的取消按钮以防止应用程序阻塞true。通过返回true,您告诉警报处理机制将处理点击相应的按钮以解除警报。

将您的警报回调更改为如下所示:

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或省略返回值向警报处理机制发出信号,表明应该点击取消按钮。

于 2013-07-19T01:51:48.807 回答