swift in UI test(测试UITable View中的单元格数)

swift in UI test(test the num of cells in UITable View)

我对 UI 测试很陌生。我的故事板中有一个 UITableView,它包含一些单元格。 更新: 我想断言当应用程序启动时 UITableView 中的单元格数量将大于 0。但我不知道如何编写此 part.Using NSPredicate?还是其他人?

 func testCellsNum()
{
        let app = XCUIApplication()
        let tableCell = app.tableRows.count
    //Then what should I do ?
        XCTAssertGreaterThan(tableCell, 0, "should greater than 0")//this line doesn't work


}

如果你只有一个table:

func testExample() {
    let app = XCUIApplication()
    let tablesQuery = app.tables
    let count = tablesQuery.cells.count
    XCTAssert(count > 0)
}

如果你有多个 tables,使用它来获取第一个或你想要的任何索引

 tablesQuery.elementAtIndex(0).cells