Skip to content

Instantly share code, notes, and snippets.

@bnickel
Created October 6, 2013 05:50
Show Gist options
  • Save bnickel/6850053 to your computer and use it in GitHub Desktop.
Save bnickel/6850053 to your computer and use it in GitHub Desktop.
[tester removeAllItemsFromTableView] will remove all items from a UITableView managed by a UITableViewController where the "Edit" button is exposed.
@implementation KIFUITestActor (TableView)
- (BOOL)deleteAnyVisibleTableViewCell
{
UIAccessibilityElement *element = [[UIApplication sharedApplication] accessibilityElementMatchingBlock:^BOOL(UIAccessibilityElement *element) {
return [element.accessibilityLabel hasPrefix:@"Delete "];
}];
if (!element) {
return NO;
}
UIView *view = [UIAccessibilityElement viewContainingAccessibilityElement:element tappable:YES error:NULL];
if (!view) {
[tester failWithError:[NSError KIFErrorWithFormat:@"Found an accessibility element named \"%@\" but it was not tappable.", element.accessibilityLabel] stopTest:YES];
}
[tester tapAccessibilityElement:element inView:view];
__block UIAccessibilityElement *confirmElement;
__block UIView *confirmView;
NSArray *labels = @[@"Delete, ", @"Confirm Deletion for"];
[self runBlock:^KIFTestStepResult(NSError **error) {
confirmElement = [[UIApplication sharedApplication] accessibilityElementMatchingBlock:^BOOL(UIAccessibilityElement *element) {
for (NSString *label in labels) {
if ([element.accessibilityLabel hasPrefix:label]) {
return YES;
}
}
return NO;
}];
KIFTestWaitCondition(confirmElement, error, @"Could not find confirmation button.");
confirmView = [UIAccessibilityElement viewContainingAccessibilityElement:confirmElement tappable:YES error:error];
KIFTestWaitCondition(confirmView, error, @"Could not find confirmation button.");
return KIFTestStepResultSuccess;
}];
[tester tapAccessibilityElement:confirmElement inView:confirmView];
[tester waitForAbsenceOfViewWithAccessibilityLabel:confirmElement.accessibilityLabel];
return YES;
}
- (void)removeAllItemsFromTableView
{
[tester tapViewWithAccessibilityLabel:@"Edit"];
while ([tester deleteAnyVisibleTableViewCell]);
[tester tapViewWithAccessibilityLabel:@"Done"];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment