如何从XCUIElementQuery UITesting获取可见单元格数

时间:2017-03-20 13:31:48

标签: ios swift xcode-ui-testing

我正在考虑从XCUIApplication CollectionViews

获取可见单元格的数量

这将返回collectionView

中的项目数

let count = XCUIApplication().collectionViews.cells.count

1 个答案:

答案 0 :(得分:0)

我解决了一个问题,只是做了XCUIApplciation extension来计算可见细胞:

  

Swift 3.x

extension XCUIApplication {

 func getVisibleCellsCount()-> Int {
     var visibleCount = 0
     var isInitialCellVisible = true

     for i in 0...cells.count {
         let cell = cells.element(boundBy: UInt(i))
         if cell.exists, !cell.isHittable {
             if i == 0 || !isInitialCellVisible {
                 isInitialCellVisible = false
             } else {
                 return visibleCount
             }
         } else {
             isInitialCellVisible = true
             visibleCount += 1
         }
     }
     return visibleCount
 }
}