iphone UI测试一个数字按钮

发布于 01-04 03:46 字数 969 浏览 4 评论 0原文

我正在尝试 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情丝乱2025-01-11 03:46:24

使用括号访问 UIAElementArray 的一个限制是数字被视为索引。 8-(。

只需添加 firstWithName()

target.frontMostApp().mainWindow().buttons().firstWithName("3").tap();

请参阅 UIAElementArray 类参考

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

See UIAElementArray Class Reference

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文