2017-08-10 37 views
0

我一直使用XCUITest來執行一些UI自動化。 我有一個頁面上的細胞的集合,並希望返回包含標籤使用NSPredicate在XCUITest中的單元格內進行搜索

設置斷點和打字的人在

po app.cells 

回報

Output: { 
     Cell 0x6080003603c0: traits: 8589934592, {{162.9, 184.6}, {916.5, 83.6}}, label: 'reminder same title, description, 4.38 pm' 
     Cell 0x618000179380: traits: 8589934592, {{162.9, 268.2}, {916.5, 10.9}} 
     Cell 0x608000360300: traits: 8589934592, {{162.9, 279.1}, {916.5, 83.6}}, label: 'reminder same title, description different, 11.37 am' 
     Cell 0x618000179440: traits: 8589934592, {{162.9, 362.7}, {916.5, 10.9}} 
     Cell 0x600000363a80: traits: 8589934592, {{162.9, 373.6}, {916.5, 83.6}}, label: 'reminder same title, other description, 11.03 am' 
     Cell 0x608000360180: traits: 8589934592, {{162.9, 457.2}, {916.5, 10.9}} 
     Cell 0x618000179500: traits: 8589934592, {{162.9, 468.0}, {916.5, 83.6}}, label: 'name A, second, 11.00 am' 
     Cell 0x618000179740: traits: 8589934592, {{162.9, 551.7}, {916.5, 10.9}} 
     Cell 0x610000177580: traits: 8589934592, {{162.9, 562.5}, {916.5, 83.6}}, label: 'name A, first, 11.00 am' 
     Cell 0x600000363000: traits: 8589934592, {{162.9, 646.1}, {916.5, 10.9}} 
     Cell 0x618000179d40: traits: 8589934592, {{409.4, 362.2}, {293.2, 27.1}} 
     Cell 0x600000364800: traits: 8589934592, {{409.4, 389.3}, {293.2, 27.1}} 

我明白了更簡單的方法是將可訪問標識符與具有標籤的單元格相關聯,但Im不確定如何構造NSPredicate查詢以便探測Cells集合並僅返回包含標籤的單元格。

回答

0

這應該給你其標籤的所有單元格不是零

let predicate = NSPredicate(format: "label != nil") 
let cells = XCUIApplication().cells.matching(predicate)