How to access the `detailTextLabel` in a `tableVie

2019-07-29 08:37发布

I wanna check whether there is a tableViewCell.detailTextLabel with a given string in my UITest. The problem is when I search for app.tables.cells.children(matching: .staticText) it will only look for labels that are tableViewCell.textLabel. Any ideas on how to query for the detailTextLabel?

2条回答
成全新的幸福
2楼-- · 2019-07-29 08:47

It sounds like your detail text label isn't accessible.

To see everything that's available to your tests in the view hierarchy, print the debug description of the following query, which may help you to understand whether the element is appearing, what its type is, and what its identifier or label is:

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

Make sure that the containing view (the cell?) is not accessible, and that the detail text label is accessible, and give it an identifier:

let cell = UITableViewCell!
cell.isAccessibilityElement = false
cell.detailTextLabel.isAccessibilityElement = true
cell.detailTextLabel.accessibilityIdentifier = "myDetailTextLabel"
查看更多
兄弟一词,经得起流年.
3楼-- · 2019-07-29 09:03

You can try a more generic query to determine if the text exists at all. If you are trying to assert that a cell contains "123 Main St.", for example, you can use the following:

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

Granted, if that text appears in the textLabel the test will still pass.

查看更多
登录 后发表回答