var target = UIATarget.localTarget();
var application = target.frontMostApp();
var window = application.mainWindow();
var view = window.elements()[0];
Slide 24
Slide 24 text
var buttons = window.buttons();
// Check for a button on screen
if (buttons.length != 1) {
UIALogger.logFail("FAIL: The button is
missing.");
} else {
UIALogger.logPass("PASS: There is a
button on the screen.");
}
Slide 25
Slide 25 text
// Make sure it's the button we want
var button = buttons.firstWithName("Tap Me");
if (!button || button.toString() ==
"[object UIAElementNil]") {
UIALogger.logFail("FAIL: The button is
missing.");
} else {
UIALogger.logPass("Pass: The button is
there.");
}
Slide 26
Slide 26 text
// Tap the button
button.tap();
// Check for the alert
var alert = application.alert();
if (!alert || alert.toString() == "[object
UIAElementNil]") {
UIALogger.logFail("FAIL: The alert was not
shown after pressing the button.");
} else {
UIALogger.logPass("PASS: The alert was
shown after pressing the button.");
}