anurag
anurag

Reputation: 111

UI Automation FrameWork for iPhone

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


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();

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".

Upvotes: 0

Views: 2740

Answers (2)

ana
ana

Reputation: 11

All this stuff is gonna work only if the application is made with that accessibility thing (its own accessibility protocol: by tagging all its UI controls in Interface Builder with names, by setting the Accessability label to a unique value for the view). Or if you work with iPhone standard controls.

If the application doesn't contain anything like that, you won't be able to do much with UI Automation and will see only a 320x480 empty canvas.

You can check this link for some more details.

For example, I work on a OpenGL application that was not built with any accessibility tag and I cannot see anything through UI Automation besides a 320x480 empty form.

Upvotes: -2

losic
losic

Reputation: 611

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

Upvotes: 4

Related Questions