iOS UIATarget 检测 UIViewController 在 tap() 之后何时加载?

标签 ios ios-ui-automation

我正在为我的 iOS 应用程序编写自动化测试,我正在尝试弄清楚如何在 View Controller 完全加载并显示在屏幕上时在 javascript 脚本中进行检测...

例如,现在脚本点击了一个按钮:

target.frontMostApp().mainWindow().buttons()["loginButton"].tap();

然后,一旦应用程序登录(可能需要几秒钟或更短的时间),我需要按下另一个按钮。

现在,我通过简单地延迟使其工作:

target.delay(3);

但我希望能够检测下一个 View Controller 何时加载,以便我知道我可以访问刚刚加载的新屏幕上的元素。

有什么建议吗?

最佳答案

有一些方法可以实现:

  1. 调整库

    https://github.com/alexvollmer/tuneup_js

    我真的建议您检查一下。他们有一些有用的包装函数来编写更高级的测试。编写了一些方法来扩展 UIAElement 类。他们有 waitUntilVisible() 方法。

    但也有可能元素本身为零。这不是可见性的问题,而是它还没有出现在屏幕上。

  2. UIATargetInstance.pushTimeout(delay)UIATargetInstance.popTimeout()

    Apple 文档说:

    To provide some flexibility in such cases and to give you finer control over timing, UI Automation provides for a timeout period, a period during which it will repeatedly attempt to perform the specified action before failing. If the action completes during the timeout period, that line of code returns, and your script can proceed. If the action doesn’t complete during the timeout period, an exception is thrown. The default timeout period is five seconds, but your script can change that at any time.

    您也可以使用UIATarget.delay(delay); 函数,但这会延迟下一条语句的执行,而不是等待找到元素。 setTimeout(delay) 也可用于在 UIAutomation 确定找不到元素之前全局设置超时。

    这里有 Apple 的指南,解释了对框架的更多理解。 http://developer.apple.com/library/IOS/#documentation/DeveloperTools/Conceptual/InstrumentsUserGuide/UsingtheAutomationInstrument/UsingtheAutomationInstrument.html

关于iOS UIATarget 检测 UIViewController 在 tap() 之后何时加载?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12432232/

相关文章:

iphone - 将正 CGFloat 反转为负值

ios - 如何防止iOS应用程序中的地理位置双重提示?

ios - XCUIApplication的通用点击功能

ios - UI 自动化命令行配置通用应用程序的模拟器

ios - UIAutomation 如何确定一个 UIAElement.isVisible()

ios - 更改图钉颜色 MKMapView

ios - UIPageViewController with UISlider inside controller - 增加 slider 的命中区域

ios - UITableViewCell : Adding constraints programmatically from a UITextView to Content View?

ios - 无法获取 UIAutomation iOS UILabel 值

xcode - 通过 Instruments 使用 UIAutomation 操作 iphone 时,什么是 UIATargetHasGoneAWOLException。