问题
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