为什么 UI 自动化工具无法确定此处的按钮是否已启用?
我正在使用 Xcode 4.0.1 和 Instruments 尝试实现一些 UIAutomation 测试。
截至目前,我正在尝试确定主窗口 (mainWindow = app.mainWindow();
) 上的按钮是否已启用。
这是一个在 iPad II 上运行的应用程序,但现在我还没有感受到爱。
有人可以帮忙吗?
这是我尝试使用的语法;这看起来正确吗?
var title="Checking that Sign-In button is disabled";
try {
if (mainWindow.buttons()["Sign In"].isEnabled())
UIALogger.logPass("Try: " + title + " has passed.");
}
catch (error) {
UIALogger.logError(error);
target.logElementTree();
UIALogger.logFail("Try: " + title + " has failed.");
}
I am working with Xcode 4.0.1 and Instruments trying to implement some UIAutomation tests.
As of right now, I am trying to determine if a button on my MainWindow (mainWindow = app.mainWindow();
) is enabled.
This is an app running on an iPad II, and right now I am not feeling the love.
Can anyone assist?
Here is the syntax I am trying to use; does this seem correct?
var title="Checking that Sign-In button is disabled";
try {
if (mainWindow.buttons()["Sign In"].isEnabled())
UIALogger.logPass("Try: " + title + " has passed.");
}
catch (error) {
UIALogger.logError(error);
target.logElementTree();
UIALogger.logFail("Try: " + title + " has failed.");
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
嘿。
我同意索苏利文的观点。一般来说,按钮访问可能会出现问题。另外,如果 mainWindow.buttons() 不包含名称为“Sign In”的按钮,那么整个代码是否会在没有任何输出的情况下执行?我可以确定,该按钮位于对象树中,验证其位置(以便我可以访问它),然后调用 .isEnabled() 以查看它是否为用户启用。
也许可以尝试以下代码来启动:
首先检查
if
将检查是否在树结构中找到按钮(在主应用程序下)。如果它不能解决问题,请检查按钮在树结构中的位置,然后将正确的位置验证作为检查它是否启用的先决条件。Hey.
I agree with Sosullivan. There may be problem with button access in general. Additionally, if mainWindow.buttons() doesn't contain one with name "Sign In" isn't whole code executed without any output? I would get sure, that button is in object tree, verify its position (so I can access it) then call .isEnabled() to see if it is enabled for user.
maybe try this code for start:
First check in
if
will check if button was found in tree structure (under main app). If it doesn't solve the issue check where in your tree structure the button is located, then put proper location verification as precondition to checking if it is enabled.在您的代码中,如果按钮被禁用,则以下表达式将为 False
,并且您的代码没有相应的 else 语句,并且也不会抛出错误。
您应该有其他结构,甚至更好 - 首先检查您正在访问的对象是否存在于当前窗口中,如 yoosiba< 的答案所示/a>.
In your code if button is disabled the following expression will be False
and your code do not have else statement for that and error won't be throwed as well.
You should have else structure or even better- check first if object you are accessing exists at all in your current window as shown in answer by yoosiba.
在这种情况下,您应该使用方法 .isVisible,因为您想检查对象是否存在。
You should use method .isVisible in this case as you want to check if a object exists or not.
嗯。好的....
我们使用一个名为“alexvollmer-tuneup_js”的 UIAutomation 开源框架,取自 SourceForge。它是免费提供的,并且鼓励修改(作者要求您分支他的代码版本以与其他人共享)。
他有一个名为assertions.js 的文件,其中有两个函数assertTrue() 和assertFalse()。
我在他包含的另一个文件中使用这些文件,该文件名为“uiautomation-ext.js”,该文件已导入到我的测试文件中。在 uiautomation-ext.js 中,我添加了两个函数:
这两个函数被放置在 uiautomation-ext.js 中名为“extend(UIAWindow.prototype”)的 JDOS 对象中。
我不完全确定我已经传达了我/我们的意思已经按照我的意愿完成了,但我已经尽力了,祝大家好运
!
Hrm. Ok....
We work using a UIAutomation opensource framework called, "alexvollmer-tuneup_js" taken off of SourceForge. It is freely available, and modifications are encouraged (and the author requests that you branch your versions of his code to share with others).
He has a file named assertions.js to which he has two functions assertTrue(), and assertFalse().
I use those in another file that he includes called 'uiautomation-ext.js' that is imported into my test file(s). In uiautomation-ext.js, I have added two functions:
These two functions are placed within a JDOS object within uiautomation-ext.js called 'extend(UIAWindow.prototype'.
I am not entirely sure that I have conveyed what I/we have done as clearly as I would like, but I have done my best here. Good luck to all!
SteveO