2016-02-09 132 views
0

當我運行下面的代碼測試:爲什麼NSPredicate accessibilityIdentifier失敗?

let shuffle = app.buttons.elementMatchingPredicate(NSPredicate(format: "accessibilityIdentifier=%@", "shuffle")) 
expectationForPredicate(NSPredicate(format: "hittable=TRUE"), evaluatedWithObject: shuffle, handler: nil) 
waitForExpectationsWithTimeout(2) {_ in} 
shuffle.tap() 

測試失敗。但是,當我使用此代碼:

let shuffle = app.buttons["shuffle"] 
expectationForPredicate(NSPredicate(format: "hittable=TRUE"), evaluatedWithObject: shuffle, handler: nil) 
waitForExpectationsWithTimeout(2) {_ in} 
shuffle.tap() 

http://www.bricepollock.com/difference-xcode-ui-testing-ui-automation-instrument/

這傢伙特別說了巨大的改進,以UIT在UIA是UIT使用了迅速評估每次使用時間的查詢,而不是評估一次並對結果集進行操作。這似乎是一個糟糕的設計原則。任何人都可以解釋第一個查詢有什麼問題嗎?

expectationForPredicate(NSPredicate("ANY accessibilityIdentifier=%@"), evaluatedWithObject: app.buttons) 

似乎也沒有工作。是否有描述哪些函數是查詢和哪些是結果集的文檔?我只能在Apple的網站上找到1個頁面,介紹如何使用這個新的XCUI套件,並且它嚴重限制了示例。

回答

0

我建議你看WWDC視頻: https://developer.apple.com/videos/play/wwdc2015-406/

而且,這個地方看起來對XCUI的文檔對象*您在使用單元測試: http://masilotti.com/xctest-documentation/

我不沒有特定的答案,爲什麼有些事情是失敗的,因爲這部分在於你的用戶界面。看起來你正在設置看起來正確的輔助功能標識符。我會這樣寫這個測試:

let shuffle = app.buttons["shuffle"] 
XCTAssert(shuffle.hittable == true) 
shuffle.tap() 

Xcode UI測試框架通常不需要超時。