Xcode 7, UI-Testing: working with UITableView
I was having the same exact issue!
At first, I was just tapping on the cell's label, through the .staticTexts
query. Here's another way that worked for me:
In cellForRowAtIndexPath
, where you instantiate the cells, give them each a unique identifier, depending on their titleLabel
or another property.
Example:
cell.accessibilityIdentifier = [NSString stringWithFormat:@"myCellType%@", cell.colorIdentifier];
Then, back in the test class, try this: (A little verbose on purpose, because it helped me understand better)
XCUIApplication *application = [XCUIApplication new];
XCUIElementQuery *tablesQuery = application.tables;
XCUIElementQuery *allCellsQuery = tablesQuery.cells;
XCUIElementQuery *specificCellQuery = [cellQuery matchingIdentifier:@"myCellTypeSaffron"];
XCUIElement *cell = specificCellQuery.element;
[cell tap];
The specific cell resolves when it's interacted with.
Hope that helps!
This worked for me:
XCUIElementQuery *tablesQuery = self.app.tables;
XCUIElementQuery *cellQuery = [tablesQuery.cells containingType:XCUIElementTypeStaticText
identifier:@"Work"];
XCUIElementQuery* cell = [cellQuery childrenMatchingType:XCUIElementTypeStaticText];
XCUIElement* cellElement = cell.element;
[cellElement tap];
For scrolling the table use:
XCUIElementQuery *tablesQuery = self.app.tables;
XCUIElement* table = tablesQuery.element;
[table swipeUp];
I recently came across a similar problem. An option you can try is to look for a specific title for a cell in the table, and tap on that,
for example:-
XCUIApplication().tables.staticTexts["identifier"].tap()
or
XCUIApplication().tables.cells.staticTexts["identifier"].tap()
Where "identifier" is the title of the cell you are trying to tap.
I hope this helps!