Search code examples
iosios9xcode-ui-testinguitest

iOS: How to assert a cell is selected in UITest?


I have the following hierarchy: ViewController -> TableView -> TableViewCell -> CollectionView -> CollectionViewCell -> UIImage

On the tableViewCell, inside the collectionView, there are 4 cells. Each cell has a unique label.

When the user taps the collectionViewCell the cell becomes selected and also the UIImageView is highlighted. In this case this means there is a different image there. I have the accessibility on the UIImageView enabled and the traits set to both button and image to try to access those XCUIElementTypes

I have not been able to make any UITest work because it always tells me that there are multiple results for the UIImageView even though the cell that the image view is in has a unique identifier.

How do I assert that the cell has been selected?

Using the record function I get: let whatIsYourFilingStatusCellsQuery = XCUIApplication().tables.cells.containingType(.StaticText, identifier:"Single").childrenMatchingType(.Image).matchingIdentifier("btn_unselected").tap()


Solution

  • I really dont have pretty solution. But I see there is only one way to assert cell is selected. Set some property to the cell at the moment of selecting. E.g accessibilityIdentifier is going to have unique id, and accessibilityValue is going to have any info what you need ("selected=true" or "selected")

    UPD you have access for these properties:

    enter image description here