Thanks firstly for taking the time to read and hopefully offer some incite into my issue. At the moment, I'm quite simply trying automate logging in and logging out of an app that my company is making using Instruments. I ran into a few small issues (as you can see with the password entry, I roll char by char instead of using string because of a strange typing issue).
The issue is that when I get the alert pop up to the screen I wish to tap the Logout button. However, it seems that I never enter the block that should be handling the alert. I can deduce this because of the logMessages that I littered in the onAlert block, which do not appear in my logs when the test script is run. I know that the default handler just dismisses any alerts unless the alert is explicitly handled otherwise. I also believe that I am or at least trying to explicitly handle that alert so that I can tap the right button.
What am I doing wrong? I followed the Apple Instruments guide and I believe I'm using the exact same syntax as they offer as an example. Please find my code below, I included all of it, but the block of interest is at the very end.
var target = UIATarget.localTarget();
var password = "something"
UIALogger.logStart("Test1");
target.frontMostApp().mainWindow().scrollViews()[0].webViews()[0].textFields()[0].tap();
target.frontMostApp().keyboard().typeString("something");
UIATarget.localTarget().delay(2);
target.frontMostApp().mainWindow().scrollViews()[0].webViews()[0].secureTextFields()[0].tap();
UIATarget.localTarget().delay(2);
for (i = 0; i < password.length; i++){
var strChar = password.charAt(i);
target.frontMostApp().keyboard().typeString(strChar);
}
target.frontMostApp().mainWindow().scrollViews()[0].webViews()[0].buttons()["Log in"].tap();
target.frontMostApp().mainWindow().tableViews()[0].cells()["Wipe data after 10 attempts"].staticTexts()["Wipe data after 10 attempts"].scrollToVisible();
target.frontMostApp().mainWindow().tableViews()[0].groups()["logout default"].buttons()["logout default"].tap();
// Alert detected. Expressions for handling alerts should be moved into the UIATarget.onAlert function definition.
UIALogger.logMessage("Just before alert");
UIATarget.onAlert = function onAlert(alert){
UIALogger.logMessage("In Alert!");
UIATarget.delay(1);
var title = alert.name();
UIALogger.logMessage("Alert with title '" + title + "' encountered!");
UIALogger.alert.logElementTree();
alert.buttons()["Logout"].tap();
}