Try setting your onAlert
handler before you take the instance of UITarget
.
For example:
// first alert box "Where are you shopping"
UIATarget.onAlert = function onAlert(alert) { // this is never called
var title = alert.name();
UIALogger.logWarning("Alert with title ’" + title + "’ encountered!");
if (title == "Where are you shopping?") {
alert.buttons()["Skip"].tap();
return true; // bypass default handler
}
return false;
}
var target = UIATarget.localTarget();
var app = target.frontMostApp();
var window = app.mainWindow();
var testName = "Test 1";
UIALogger.logStart(testName);
var buttonScan = target.frontMostApp().windows()[0].buttons()["scan btn"];
//UIATarget.localTarget().pushTimeout(1);
target.delay(1);
//app.logElementTree();
if (buttonScan.isValid()) {
buttonScan.tap();
//alert should happen here