2017-05-02 28 views
1

XCUITestでiOSをテストしていますが、検索テストのケースでは、すべての検索候補がユーザーが入力した文字で始まることを確認したいと思います。 「P」を入力し、検索の提案は「PS4」を持っている必要があり、「電話」、「PS3」などiOS UIテスト:要素のリストを取得する方法

を周りに見ることによって、私はほとんどの要素のクエリメソッドのように感じる単一の要素を返すようにしようと、 例えば: let predicate = NSPredicate(format: "label BEGINSWITH[cd] 'p'") app.buttons.elementMatchingPredicate(predicate)

同じ条件に一致する要素のリストも重要な場合がありますが、これを達成する方法はありますか?

+1

これは、あなたの質問に答えていませんが、私は、これはユニットテストではなく、UIテストされるべきだと思います。ここで機能をテストしています(文字 "p"を検索し、リストを取得します)。 UIテストでは、「検索」ボタンをクリックした後にラベル(またはリスト)が表示されることを確認するだけです。その内容にあまり関心を持ってはならない。 – Hodson

+0

@ Hodson私はあなたに同意します、私はいつもUIテストがどのくらい詳細に検証されるべきかについて苦労します – nieschumi

答えて

0

@nieschumiまずこのタスクのように見えるのは、ui用ではありません。

/*! Returns a new query that applies the specified attributes or predicate to the receiver. The predicate will be evaluated against objects of type id<XCUIElementAttributes>. */ 
open func matching(_ predicate: NSPredicate) -> XCUIElementQuery 

open func matching(_ elementType: XCUIElementType, identifier: String?) -> XCUIElementQuery 

open func matching(identifier: String) -> XCUIElementQuery 


/*! Returns a new query for finding elements that contain a descendant matching the specification. The predicate will be evaluated against objects of type id<XCUIElementAttributes>. */ 
open func containing(_ predicate: NSPredicate) -> XCUIElementQuery 

open func containing(_ elementType: XCUIElementType, identifier: String?) -> XCUIElementQuery 

: ので、なぜuが関数のいずれかを使用することはできませんか? uは

例が必要な場合や、クエリのチェック回数より:

app.buttons.matching(NSPredicate(format: "label == [cd] %@", myVar)).count>1 ? doSmthWithQuery(): doSmthWithElement() 
関連する問題