【发布时间】:2018-10-09 16:57:37
【问题描述】:
我目前正在使用 NSPredicate 来等待 XCUITest 元素上的条件,如下:
class func waitForCondition(condition: String, element: XCUIElement) -> Bool {
let predicate = NSPredicate(format: condition)
let expectation = XCTNSPredicateExpectation(predicate: predicate, object: element)
let result = XCTWaiter().wait(for: [expectation], timeout: 5)
return result == .completed
}
它适用于大多数属性,例如“exists == 1”、“isSelected == 1”、“isHittable == 1”等。 但我想要的是一种检查焦点的方法,似乎没有一个条件可以验证这一点。
说实话,即使在 Xcode 的自动完成中,我也找不到检查焦点的方法。我找到了 XCUIElementAttributes 的文档,这是 XCUIElement 类采用的接口: https://developer.apple.com/documentation/xctest/xcuielementattributes 它声明了“hasFocus”布尔值的存在。但它似乎真的不存在于文档世界之外。
为了记录,我使用的是 Xcode 9.4.1。
【问题讨论】: