views:

437

answers:

1

Hi All

I am exploring the newly exposed framework UI Automation in iphoneOS 4.0. Has anybody tested their application using this framework. I will appreciate any help.

I am trying to test a sample application that just contains a textfield and a button. I have written a script as


[color=#1C2837][font=arial, verdana, tahoma, sans-serif][size=2][color=#000000]UIALogger.logStart("Starting Test");

var view = UIATarget.localTarget().frontMostApp().mainWindow().elements()[0];
var textfields = view.textFields();
if (textfields.length != 1) {
    UIALogger.logFail("Wrong number of text fields");
} else {
    UIALogger.logPass("Right number of text fields");
}

textfields[0].setValue("anurag");

view.buttons()[0].tap();

[/color][/size][/font][/color]

The problem is that the value of textfield is not getting set and no button is tapped. When I run the instruments only the view(with textfield and button) appears and then notting is happening.

There is a message in instruments "Something else has happened".

A: 

If your main window contains a button and a text field (in this order in the hierarchy) then your first line of code will return you the UIAButton element, so the next line is incorrect, because you're trying to call textFields() on a button.

The first part should look like this:

var view = UIATarget.localTarget().frontMostApp().mainWindow();
var textfields = view.textFields();
if (textfields.length != 1) {
    UIALogger.logFail("Wrong number of text fields");
} else {
    UIALogger.logPass("Right number of text fields");
}

And in that case I think there are two ways of testing the tap and text field. Like this:

textfields[0].setValue("anurag");
view.buttons()[0].tap();

or like this:

view.elements()[1].setValue("anurag");
view.elements()[0].tap();

And personally I prefer getting objects by using Accessibility Label instead of index. For more information look for a UIAElement Class Reference and take a look here: UI Automation Reference Collection