Xcodes UI 测试显示过时的页面信息
Xcodes UI Testing showing out of date page info
目前有以下方法:
func waitForOptionalElement(explicitElement: XCUIElement, timeout: Int) {
var waitedDuration = 0
while waitedDuration < timeout {
if explicitElement.exists {
break
}
waitedDuration++
sleep(1)
}
}
这个方法的目的是等待一个对象出现在屏幕上。我遇到的麻烦是,如果调用方法时 explicityElement
不在屏幕上,那么 explicitElement.exists
总是 returns a false
(即使对象出现时)。就像explicitElement
在页面变化时不刷新,而是一直检查原始视图而不是任何更新的视图。
如果我完整调用 explicitElement
,例如
XCUIApplication().staticTexts["Error message"].exists
然后它会回来 true
。就好像你需要调用 XCUIApplication()...
来获取当前页面的更新视图?
有人知道解决这个问题的巧妙方法吗?
使用expectationForPredicate可能更合适。
expectationForPredicate(NSPredicate(format: "exists == true"), evaluatedWithObject: XCUIApplication().staticTexts["Error message"], handler: nil)
waitForExpectationsWithTimeout(15.0, handler: nil)
目前有以下方法:
func waitForOptionalElement(explicitElement: XCUIElement, timeout: Int) {
var waitedDuration = 0
while waitedDuration < timeout {
if explicitElement.exists {
break
}
waitedDuration++
sleep(1)
}
}
这个方法的目的是等待一个对象出现在屏幕上。我遇到的麻烦是,如果调用方法时 explicityElement
不在屏幕上,那么 explicitElement.exists
总是 returns a false
(即使对象出现时)。就像explicitElement
在页面变化时不刷新,而是一直检查原始视图而不是任何更新的视图。
如果我完整调用 explicitElement
,例如
XCUIApplication().staticTexts["Error message"].exists
然后它会回来 true
。就好像你需要调用 XCUIApplication()...
来获取当前页面的更新视图?
有人知道解决这个问题的巧妙方法吗?
使用expectationForPredicate可能更合适。
expectationForPredicate(NSPredicate(format: "exists == true"), evaluatedWithObject: XCUIApplication().staticTexts["Error message"], handler: nil)
waitForExpectationsWithTimeout(15.0, handler: nil)