0

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!

anyName
  • 113
  • 1
  • 2
  • 13
  • You can get documentation for the Objective-C APIs by switching the language in the menu bar in the Apple Docs. Here is the brief explanation Apple gives for UI tests: https://developer.apple.com/documentation/xctest/user_interface_tests?language=objc – Oletha Jun 30 '17 at 14:52
  • Thank you, I know that service but this is not enought. – anyName Jul 01 '17 at 13:20

1 Answers1

0

UI Test runs only for visible cells, your last cell is not loaded even when test case executes. So scroll the tableView content programmatically, once you reach the end of tableview content(here again you need to put a expectation that you scrolled to end of the tableview content or not). After that your UI test will get pass.

Sandeep Ahuja
  • 931
  • 6
  • 17
  • But if I use the same lastCell object and check if it has text, it works fine. Then it must be inserted when i execute assertion. – anyName Jun 30 '17 at 13:49
  • That time you have a last cell because you scrolled to content offset. – Sandeep Ahuja Jul 01 '17 at 09:34
  • Everything goes the same. What is the difference? – anyName Jul 03 '17 at 06:18
  • UITableView reuse cells. It creates the cell that is visible to the user. If you scrolls up or down, it make use of existing cells to avoid memory issues. You can execute test on visible cells only. To automate testing of all the cells, you need to scroll with cells through code. – Sandeep Ahuja Jul 06 '17 at 11:21
  • I know these details. I mean that, I add cell and scroll down in any type of content (both in text and image, does not matter). If I can check text, then what is the difference that makes me not able to access to image? – anyName Jul 06 '17 at 13:15