I'm writing UI tests for my almost finished, Objective-C coded app as a newbie at UI tests.
I have a UITableView with custom cells. A cell either has text view or image or progress view. Image or progress view is set dynamically.
For my tests, I need to check whether image was set or not. I tried to use accessibilityIdentifier
property. I set it in the initialization method of that cell as:
self.thumbnailImageView.isAccessibilityElement = YES;
self.thumbnailImageView.accessibilityIdentifier = @"imageLabel"
In my tests, I get the cell and tried to get it's elements depending on identifier like:
XCUIElementQuery *tablesQuery = app.tables;
XCUIElementQuery *cellsQuery = app.tables.cells;
XCUIElement *lastCell = [[tablesQuery childrenMatchingType:XCUIElementTypeCell] elementBoundByIndex:(cellsQuery.count - 1)];
XCUIElement *image = lastCell.otherElements[@"imageLabel"];
I didn't get image from app.otherElements because there are multiple cells created and many of them may have an image view. I want to check last cell and it's image. After this, I set an assert as:
XCTAssertTrue(image.exists, @"Image cell has failed");
It's never passing this test and also enters in an exception breakpoint (?). I check situation of image, it's not nil.
I don't know what to do exactly. For Objective-C, there is almost no document for UI testing. Still Swift documents would be good but they are not enough too.
Any help would be very good. Thank you!