Adi Saxena has an article on codeproject.com with a very good step by step guide to using this tool (see http://www.codeproject.com/KB/iPhone/UI_Automation_Testing.aspx).
This site has a very good tutorial on the tool – http://blog.manbolo.com/2012/04/08/ios-automated-tests-with-uiautomation.
Altf also has an article on this here http://altf.wordpress.com/2010/11/14/automating-ios-user-interface-testing-with-uiautomation/ .
I will be using Adi’s article as reference to explain the steps.
Step 1: Open Instruments and select Automation
Use Spotlight to to search for it. What’s Spotlight? On the top righthand corner of your Mac you’ll see a magnifying glass icon. Click on it and search for “Instruments”. Click on that. You will see the Instruments app show up.
Next click on “Automation” icon.
Step 2: Select Target
Next step is to select the target app. On the top left corner you will see a drop down labelled “Choose Target”. Select “Choose Target”.
Select the target app by navigating to it. You should be able to locate the app under the “build/Debug-iphonesimulator” folder.
If you wish to try out the tool, the codeproject site has a sample app with test JS.
Step 3: Run Script
On the lower left hand corner there is a “Choose script .. ” option. Use that to load the test JS script. We will deconstruct the JS code later.
Next click on the “Record” button – the one with the red dot. You will see the iPhone simulator pop up loading the app and the steps of the JS script will be run.
Deconstructing the JS test code
I’ll be using Adi’s JS code to explain how the tests work – so we’ll be referencing the code from the codeproject article.
// Get the handle of applications main window
var window = UIATarget.localTarget().frontMostApp().mainWindow();
As described in the comment – it’s to obtain the handle for the main window of the app.
var textfields = window.textFields();
This gets the array of text fields from the main window of the app.
// Check number of Text field(s)
UIALogger.logFail("FAIL: Inavlid number of Text field(s)");
UIALogger.logPass("PASS: Correct number of Text field(s)");
This test checks if the number of text fields is correct. The
UIALogger JS logger object is used by UI Automation (hence the name) to log pass or fail cases
//TESTCASE_001 : Test Log on Screen
//Check existence of desired TextField On UIScreen
if(textfields["username"]==null || textfields["username"].toString() ==
UIALogger.logFail("FAIL:Desired textfield not found.");
UIALogger.logPass("PASS: Desired UITextField is available");
This checks to see if the textfield is the correct one showing up.
textfields["username"]. What does “username” refer to? This is the accessibility label of the textfield UI object. If you open Interface Builder on Xcode (or IB) by clicking on the .xib file of the app’s Xcode project – you’ll be able to find it.
These lines of code basically fills in the input fields with accessibility labels “username”, “password” and selects button with accessibility label “logon” and taps on the button.