Skip to content

Instantly share code, notes, and snippets.

@rcdilorenzo
Created December 12, 2013 16:11
Show Gist options
  • Save rcdilorenzo/7930541 to your computer and use it in GitHub Desktop.
Save rcdilorenzo/7930541 to your computer and use it in GitHub Desktop.
A KIF extension to allow tapping a cell based on its name
- (void)tapCellWithName:(NSString *)name inTableViewWithAccessibilityLabel:(NSString *)accessibilityLabel {
[tester runBlock:^KIFTestStepResult(NSError *__autoreleasing *error) {
UITableView *tableView = (UITableView *)[tester waitForViewWithAccessibilityLabel:accessibilityLabel];
NSIndexPath *foundIndexPath = nil;
for (int section = 0; section < tableView.numberOfSections; section++) {
for (int row = 0; row < [tableView numberOfRowsInSection:section]; row++) {
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:section];
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if ([cell.textLabel.text isEqualToString:name]) {
foundIndexPath = indexPath;
break;
}
}
}
if (foundIndexPath) {
[tester tapRowInTableViewWithAccessibilityLabel:accessibilityLabel atIndexPath:foundIndexPath];
[tester waitForTimeInterval:0.2];
return KIFTestStepResultSuccess;
} else {
[NSError KIFErrorWithFormat:@"No cell found on tableView '%@' with name '%@'", accessibilityLabel, name];
return KIFTestStepResultFailure;
}
}];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment