UIAutomation 如何判断 UIAElement.isVisible() 是否存在
我有一个具有以下结构的视图:
GrandView
-Parent View1
-Parent View2
--Child View1
--Child View2
子视图几乎占据了父视图2的所有边界,但边缘周围仍然有一些空间。如果单击边缘,我可以使用辅助功能检查器在模拟器中选择 Parent View2
。如果我使用的话,我还可以在 UIAutomation 中点击 Parent View2
:
tapWithOptions({tapOffset:{x:0.15, y:0.95}});
但是,我对 isVisible()
的调用始终返回 0
。我希望如果我可以点击该元素,或者使用辅助功能检查器选择它,它应该返回 1
。
UIAutomation 如何确定 UIAElement
是否可见?
I have a view with the following structure:
GrandView
-Parent View1
-Parent View2
--Child View1
--Child View2
The child views take up almost all of the bounds of Parent View2
, but there is still some space around the edges. I can select Parent View2
in the simulator with the accessibility inspector if I click on the edges. I can also tap Parent View2
in UIAutomation if I use:
tapWithOptions({tapOffset:{x:0.15, y:0.95}});
However, my calls to isVisible()
always return 0
. I expect that if I can tap the element, or select it with the accessibility inspector, it should return 1
.
How does UIAutomation determine whether a UIAElement
is visible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您对元素执行的每个操作都有超时。这在 Apple 文档中并不明显,但如果您查看: setTimeout ,它告诉我们:
setTimeout
本身只是更改默认值(就像推送和弹出一样)。您真正想做的是在视图上执行操作,如果它永远不可用,则超时失败(默认超时为 5 秒)。WWDC 2010 会议“使用仪器自动进行用户界面测试”确实进行了稍微深入一点,它可以在 ADC WWDC 上找到2010 页面,包含视频和幻灯片。在您的情况下,您需要在视图上执行 tap() 。如果由于某种原因,UIAutomation 在 5 秒内无法使用该视图,您应该会看到异常。
通过执行以下操作来尝试更改超时:
var oldTimeout = target.timeout();
target.pushTimeout(10);
在代码之前,
target.popTimeout(oldTimeout);
在代码之后。
Every operation you perform against an element has a timeout. This isn't obvious from the Apple documentation, but if you look at: setTimeout , it tells us:
setTimeout
itself just changes the default value (as do push and pop). What you really want to do is perform your action on your view, and fail on the timeout if it never becomes available (the default timeout is 5 seconds).The WWDC 2010 session "Automating User Interface Testing with Instruments" does go into this a little, it's available on the ADC WWDC 2010 page, with both video and slides. In your case, you'd want to execute the tap() on your view. If, for some reason, that view isn't available to UIAutomation within 5 seconds, you should see an exception.
Experiment with changing the timeout by doing:
var oldTimeout = target.timeout();
target.pushTimeout(10);
before your code, and
target.popTimeout(oldTimeout);
after.
如果它是 UIView,则应使用
hidden
属性来驱动它。如果它不是视图,而是容器,则应由 accessibilityElementsHidden 驱动。但一般来说,您不想将其用于 UIAutomation。相反,无论您要在视图上执行什么操作(在本例中为 tap()),请继续执行,并在超时时让系统抛出错误。一般来说,这是您希望在脚本中遵循的模型,而不是首先测试某些内容是否可用。 Sine UIAutomation 是 UIAccessibility 信息的 DOM 脚本,当诸如动画视图转换之类的事情发生时,事情就会不同步。有时脚本的执行速度比 UI 动画快,有时则相反! waitForInvalid 可能是您找到解决方案的捷径。
Alex Vollmer 的 UIAutomation 的uneup.js 库使编写测试变得更加容易,并且易于扩展。
https://github.com/alexvollmer/tuneup_js
If it's a UIView, it should be driven the the
hidden
property. If it's not a view, and it's a container, it should be driven byaccessibilityElementsHidden
.In general though, you don't want to use this for UIAutomation. Instead, whatever you were going to do on the view - in this case, a tap() - go ahead and do it, and let the system throw an error if it times out. In general this is the model you want to follow in your scripts rather than testing whether something is available first. Sine UIAutomation is DOM scripting the UIAccessibility information, when things like animated view transitions happen things get out of sync. Sometimes the script executes faster than the UI animates, and sometimes the opposite! waitForInvalid may be a shortcut to a solution for you.
Alex Vollmer's tuneup.js library for UIAutomation makes writing tests much easier, and is easy to extend.
https://github.com/alexvollmer/tuneup_js