如何访问`detailTextLabel`在`tableViewCell`在UITests?(How

2019-09-28 02:26发布

我想检查是否有tableViewCell.detailTextLabel在我UITest给定的字符串。 问题是,当我搜索app.tables.cells.children(matching: .staticText)只会寻找那些标签tableViewCell.textLabel 。 关于如何查询的任何想法detailTextLabel

Answer 1:

你可以尝试一个更通用的查询,以确定是否文本都存在。 如果你正试图断言,一个单元格中包含“123主街”,例如,可以使用以下命令:

let app = XCUIApplication()
XCTAssert(app.staticTexts["123 Main St."]).exists)

当然,如果该文本出现在textLabel测试仍然会通过。



Answer 2:

这听起来像您的详细文本标签是无法访问的。

要看到的一切,这是提供给视图层次的测试,打印以下查询的调试描述,这可以帮助你了解该元素是否会出现,它的类型是什么,以及它的标识或标签是:

let app = XCUIApplication()
print(app.descendants(matching: .any).debugDescription)

确保包含视图(细胞?)是无法访问的,并且详细文本标签可访问的,并给它一个标识符:

let cell = UITableViewCell!
cell.isAccessibilityElement = false
cell.detailTextLabel.isAccessibilityElement = true
cell.detailTextLabel.accessibilityIdentifier = "myDetailTextLabel"


文章来源: How to access the `detailTextLabel` in a `tableViewCell` at UITests?