UIAutomation : Cancel button on Alert view is tapped without actually doing it

两盒软妹~` 提交于 2020-01-13 11:36:09

问题


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?


回答1:


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
}

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



来源:https://stackoverflow.com/questions/17733587/uiautomation-cancel-button-on-alert-view-is-tapped-without-actually-doing-it

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