https://developer.apple.com/library/mac/#documentation/DeveloperTools/Conceptual/InstrumentsUserGuide/UsingtheAutomationInstrument/UsingtheAutomationInstrument.html
https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ScriptableCocoaApplications/SApps_debugging/SAppsDebugging.html
http://developer.apple.com/library/ios/#documentation/DeveloperTools/Reference/UIAutomationRef/_index.html
Note: To fully understand this section, you should be familiar with the information in iOS Human Interface Guidelines.
http://blog.thepete.net/2010/07/frank-automated-acceptance-tests-for.html
#import "<path-to-library-folder>/TestUtilities.js"
UIATarget.localTarget().frontMostApp(); //To reach the app window, the main window of your app, you would specify UIATarget.localTarget().frontMostApp().mainWindow();
UIATarget.localTarget().frontMostApp().mainWindow().tableViews()[0]; UIATarget.localTarget().frontMostApp().mainWindow().tableViews()[0].cells()[0]; UIATarget.localTarget().frontMostApp().mainWindow().tableViews()[0].cells()[0].elements()["Chocolate Cake"];
// List element hierarchy for the Recipes screen UIALogger.logStart("Logging element tree …"); UIATarget.localTarget().logElementTree(); UIALogger.logPass();
// List element hierarchy for the Unit Conversion screen var target = UIATarget.localTarget(); var appWindow = target.frontMostApp().mainWindow(); var element = target; appWindow.tabBar().buttons()["Unit Conversion"].tap(); UIALogger.logStart("Logging element tree …"); element.logElementTree(); UIALogger.logPass();
// Switch screen (mode) based on value of variable var target = UIATarget.localTarget(); var app = target.frontMostApp(); var tabBar = app.mainWindow().tabBar(); var destinationScreen = "Recipes"; if (tabBar.selectedButton().name() != destinationScreen) { tabBar.buttons()[destinationScreen].tap(); }
UIATarget.localTarget().frontMostApp().navigationBar().buttons()["Add"].tap(); UIATarget.localTarget().tap({x:100, y:200}); UIATarget.localTarget().doubleTap({x:100, y:200}); UIATarget.localTarget().twoFingerTap({x:100, y:200}); UIATarget.localTarget().pinchOpenFromToForDuration({x:20, y:200}, {x:300, y:200}, 2); UIATarget.localTarget().pinchCloseFromToForDuration({x:20, y:200}, {x:300, y:200}, 2); UIATarget.localTarget().dragFromToForDuration({x:160, y:200}, {x:160, y:400}, 1); UIATarget.localTarget().flickFromTo({x:160, y:200}, {x:160, y:400}); var recipeName = "Unusually Long Name for a Recipe"; UIATarget.localTarget().frontMostApp().mainWindow().textFields()[0].setValue(recipeName); var tabBar = UIATarget.localTarget().frontMostApp().mainWindow().tabBar(); var selectedTabName = tabBar.selectedButton().name(); if (selectedTabName != "Unit Conversion") { tabBar.buttons()["Unit Conversion"].tap(); } UIATarget.localTarget().frontMostApp().mainWindow().tableViews()[0] .scrollToElementWithPredicate("name beginswith ‘Turtle Pie’");
UIATarget.localTarget().pushTimeout(2); //You then run the code to perform the action and pop the custom timeout off the stack. UIATarget.localTarget().popTimeout(); UIATarget.localTarget().delay(2);
var testName = "Module 001 Test"; UIALogger.logStart(testName); //some test code UIALogger.logPass(testName); /////////// var testName = "Module 001 Test"; UIALogger.logStart(testName); //some test code UIALogger.logMessage("Starting Module 001 branch 2, validating input."); //capture a screenshot with a specified name UIATarget.localTarget().captureScreenWithName("SS001-2_AddedIngredient"); //more test code UIALogger.logPass(testName);
var cell = UIATarget.localTarget().frontMostApp().mainWindow().tableViews()[0].cells() .firstWithPredicate("name beginswith ‘Tarte’"); if (cell.isValid()) { UIALogger.logPass(testName); } else { UIALogger.logFail(testName); }
UIATarget.onAlert = function onAlert(alert) { var title = alert.name(); UIALogger.logWarning("Alert with title '" + title + "' encountered."); // return false to use the default handler return false; }
UIATarget.onAlert = function onAlert(alert) { var title = alert.name(); UIALogger.logWarning("Alert with title '" + title + "' encountered."); if (title == "The Alert We Expected") { alert.buttons()["Continue"].tap(); return true; //alert handled, so bypass the default handler } // return false to use the default handler return false; }
var target = UIATarget.localTarget(); var app = target.frontMostApp(); //set orientation to landscape left target.setDeviceOrientation(UIA_DEVICE_ORIENTATION_LANDSCAPELEFT); UIALogger.logMessage("Current orientation now " + app.interfaceOrientation()); //reset orientation to portrait target.setDeviceOrientation(UIA_DEVICE_ORIENTATION_PORTRAIT); UIALogger.logMessage("Current orientation now " + app.interfaceOrientation());
UIATarget.localTarget().deactivateAppForDuration(10);