Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handling Alert with UIAutomation

I'm trying to test the presence of an UIAlertView with UIAutomation but my handler never gets called.

At the beginning of my javascript i write :

UIATarget.onAlert = function onAlert(alert) {
    UIALogger.logMessage("alertShown");
    return false;
}

As i understand it, as soon as i specify my onAlert function, it should get called when an alertView appears during my tests. So i run a test that shows an alertView, here is the code that shows the alert :

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:message message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
alertView.accessibilityLabel = @"alerte d'avertissement";
[alertView show];

I run my test in instruments, the alert shows up but my handler is never called. Has anybody been able to use event handlers with UIAutomation ?

Thanks, Vincent.

like image 360
vdaubry Avatar asked Sep 06 '10 12:09

vdaubry


1 Answers

The documentation seems to be wrong. It turns out that alerts are handled on the same thread your script tries to run. So if you want the alert handler to be called, you need to sleep, e.g.,

UIATarget.onAlert = { ... }
window.buttons().triggerAlertButton.tap();
UIATarget.localTarget().delay(4);

Also, it appears that the alert's name and value are always set to null. I was, however, able to access the first static text which contained the alert's title.

like image 143
Drew Crawford Avatar answered Sep 21 '22 14:09

Drew Crawford