Created
October 6, 2013 05:50
-
-
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.
This file contains 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
@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