I'm trying out UITesting for the iPhone, and I thought I would use the simple rpn calculator from the lecture 2 of stanford's cs193p iTunes U class to run my first tests on.
my javascript is as follows
var target = UIATarget.localTarget();
target.frontMostApp().mainWindow().buttons()["3"].tap();
target.frontMostApp().mainWindow().buttons()["Enter"].tap();
target.frontMostApp().mainWindow().buttons()["4"].tap();
target.frontMostApp().mainWindow().buttons()["/"].tap();
var display = target.frontMostApp().mainWindow().staticTexts()[1].value();
if (display == "0.75") {
UIALogger.logPass("3 E 4 /");
} else {
UIALogger.logFail("3 E 4 /");
}
However the script runs sin enter cos / In the editor log it is showing
target.frontMostApp().mainWindow().buttons()[3].tap();
target.frontMostApp().mainWindow().buttons()["Enter"].tap();
target.frontMostApp().mainWindow().buttons()[4].tap();
target.frontMostApp().mainWindow().buttons()["/"].tap();
So somehow instruments is converting my string "3" into the index 3 and then tapping the third button.
So I could call the buttons by their index number, but I would much prefer to call them by their text.
It's a limitation with using brackets to access UIAElementArray's that numbers get treated as an indices. 8-(.
Instead just add firstWithName()
:
target.frontMostApp().mainWindow().buttons().firstWithName("3").tap();