UIAutomation: the Cancel button in the Warning window is used without actually executing

I ran into this strange problem in UIAutomation.

I am checking the warning. In this case, I am trying to write a warning and alert header. My code for this:

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 do not press the cancel button in the warning to reject it. But it automatically works. I do not know why. Even in logMessages I see

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

this line is executed automatically. I do not have this line in my script file. Is this a bug in iOS?

+4
source share
1 answer

The cancel button in the alert is always used to block the application if the onAlert does not return true . By returning true , you are reporting an alert handling mechanism that you will process by clicking the appropriate button to reject the alert.

Change your view 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 rejecting the return value fully signals the warning processing mechanism that the cancel button should be pressed.

+9
source

Source: https://habr.com/ru/post/1492171/


All Articles