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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With