views:

52

answers:

1

Hi,

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.

A: 

set the accessibility element

alertView.isAccessibilityElement=YES;

Hi, I have tried like this. and it detects the alert title. and logs the message. But it doesn't taps the OK button, and throws error. Cannot perform action on invalid element: UIAElementNil from target.frontMostApp().alert().buttons().

Please share your inputs.

// Handle the expected alerts..

 UIATarget.onAlert = function onAlert(alert){    
target.delay(2);
var title = alert.name();
alert.logElementTree();
//UIATarget.localTarget().frontMostApp().logElementTree(); 
UIALogger.logMessage("Alert with title: '"+ title +"' encountered! ");                                                                                                  
if(title == "FAIL"){ // LOGIN fail alert title
    UIALogger.logMessage("Title :: "+title+" button len "+alert.buttons().length); // len returned as 0 ..??
   // The above log message is being displayed

    alert.buttons()["OK"].tap();  // It fails in this line..
    //alert.buttons()[0].tap();


    return true; // bypass the default handler
}
UIALogger.logMessage(" using default handler.. !");
return false; // use default handler

}

Senthil