How to access the `detailTextLabel` in a `tableViewCell` at UITests?

只谈情不闲聊 提交于 2019-12-11 08:12:29

问题


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?


回答1:


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.




回答2:


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"


来源:https://stackoverflow.com/questions/41966151/how-to-access-the-detailtextlabel-in-a-tableviewcell-at-uitests

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!