Created
December 12, 2013 16:11
-
-
Save rcdilorenzo/7930541 to your computer and use it in GitHub Desktop.
A KIF extension to allow tapping a cell based on its name
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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