Reputation: 4780
I am writing a UI test in Swift against an iOS app that contains a UITableView
with a custom UITableViewCell
loaded from a nib. The cell contains a UIImageView
and a UILabel
.
When the table is rendered, there is no XCUIElementQuery
that finds the image element. How can you get access to the ImageView during the UI Test to know the source of the image that was specified in the icon field?
class MyCell: UITableViewCell {
@IBOutlet var name: UILabel!
@IBOutlet var icon: UIImageView!
}
The image does not appear in app.images
, app.tables.cells.images
or app.tables.cells.otherElements
. It seems like the image icons are nowhere to be found in the UI hierarchy.
Upvotes: 1
Views: 2852
Reputation: 41
It's late, but for other users...
I solved it as follows:
self.tableView.accessibilityIdentifier = "ExampleTableView"
cell.icon.isAccessibilityElement = true
let imageName = "example_image"
cell.icon.accessibilityIdentifier = "ExampleTableViewCellIcon"
cell.icon.accessibilityLabel = imageName
cell.icon.image = UIImage(named: imageName)!
XCTAssert(app.tables["ExampleTableView"].cells.element(boundBy: 0).images[ExampleTableViewCellIcon].label == "example_image")
Upvotes: 4
Reputation: 17008
The path of the image is not accessible in UI Testing. The framework sees the app as a user does, why would someone care about the filename of a check mark?
Update: To relate the user interface / accessibility to your different icons, you can set accessibility identifiers when setting the image.
MyCell().icon?.accessibilityIdentifier = "check"
Upvotes: 1