目前有以下方法:
func waitForOptionalElement(explicitElement: XCUIElement, timeout: Int) {
var waitedDuration = 0
while waitedDuration < timeout {
if explicitElement.exists {
break
}
waitedDuration++
sleep(1)
}
}
这个方法的目的是等待一个对象出现在屏幕上。我遇到的问题是,如果调用方法时 explicityElement
不在屏幕上,则 explicitElement.exists
总是返回 false
(即使对象出现)。这就像 explicitElement
在页面更改时不会刷新,而是继续检查原始 View 而不是任何更新的 View 。
如果我完整地调用 explicitElement
,例如
XCUIApplication().staticTexts["错误信息"].exists
然后返回 true
。就好像您需要调用 XCUIApplication()...
来获取当前页面的更新 View ?
有人知道解决这个问题的巧妙方法吗?
最佳答案
用expectationForPredicate可能更合适.
expectationForPredicate(NSPredicate(format: "exists == true"), evaluatedWithObject: XCUIApplication().staticTexts["Error message"], handler: nil)
waitForExpectationsWithTimeout(15.0, handler: nil)
关于ios - Xcodes UI 测试显示过时的页面信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39164276/