【发布时间】:2016-03-29 15:23:57
【问题描述】:
我正在尝试为使用 XCUI 测试的 iOS UI 测试快速编写一个 do-try-catch。我正在阅读错误处理部分:https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/ErrorHandling.html#//apple_ref/doc/uid/TP40014097-CH42-ID508 但是我不确定当找不到元素时应该抛出哪个错误。
func tapElement(string:String) throws {
do{
waitFor(app.staticTexts[string], 5)
try app.staticTexts[string].tap()
}
catch {
NSLog("Element was not found: \(string)")
//how can i check specifically that the element was not found?
}
}
....
func waitFor(element:XCUIElement, seconds waitSeconds:Double) {
NSLog("Waiting for element: \(element)")
let exists = NSPredicate(format: "exists == 1")
expectationForPredicate(exists, evaluatedWithObject: element, handler: nil)
waitForExpectationsWithTimeout(waitSeconds, handler: nil)
}
非常感谢任何帮助!
【问题讨论】:
标签: ios swift xcode-ui-testing