iphone UI测试一个数字按钮
我正在尝试 iPhone 的 UITesting,我想我会使用斯坦福大学 cs193p iTunes U 课程第二讲中的简单 rpn 计算器来运行我的第一个测试。
我的 javascript 如下
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 /");
}
但是脚本运行 sin 输入 cos / 在编辑器日志中显示,
target.frontMostApp().mainWindow().buttons()[3].tap();
target.frontMostApp().mainWindow().buttons()["Enter"].tap();
target.frontMostApp().mainWindow().buttons()[4].tap();
target.frontMostApp().mainWindow().buttons()["/"].tap();
因此仪器以某种方式将我的字符串“3”转换为索引 3,然后点击第三个按钮。
因此,我可以通过索引号来调用按钮,但我更喜欢通过文本来调用它们。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

使用括号访问 UIAElementArray 的一个限制是数字被视为索引。 8-(。
只需添加
firstWithName()
:请参阅 UIAElementArray 类参考
It's a limitation with using brackets to access UIAElementArray's that numbers get treated as an indices. 8-(.
Instead just add
firstWithName()
:See UIAElementArray Class Reference