-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathKIFTestStep+SectionAdditions.m
More file actions
67 lines (46 loc) · 3.06 KB
/
KIFTestStep+SectionAdditions.m
File metadata and controls
67 lines (46 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//
// KIFTestStep+SectionAdditions.m
// NUSurveyor
//
// Created by Mark Yoon on 4/9/2012.
// Copyright (c) 2012 Northwestern University. All rights reserved.
//
#import "KIFTestStep+SectionAdditions.h"
@implementation KIFTestStep (SectionAdditions)
+ (id)stepToReset {
return [KIFTestStep stepWithDescription:@"Reset the application state." executionBlock:^(KIFTestStep *step, NSError **error) {
BOOL successfulReset = YES;
// Do the actual reset for your app. Set successfulReset = NO if it fails.
KIFTestCondition(successfulReset, error, @"Failed to reset the application.");
return KIFTestStepResultSuccess;
}];
}
+ (id)stepToVerifyNumberOfSections:(NSInteger)sections inTableViewWithAccessibilityLabel:(NSString *)tableViewLabel
{
NSString *description = [NSString stringWithFormat:@"Step to verify there are %D sections in tableView with label '%@'", sections, tableViewLabel];
return [KIFTestStep stepWithDescription:description executionBlock:^(KIFTestStep *step, NSError **error) {
UIAccessibilityElement *element = [[UIApplication sharedApplication] accessibilityElementWithLabel:tableViewLabel];
KIFTestCondition(element, error, @"View with label %@ not found", tableViewLabel);
UITableView *tableView = (UITableView*)[UIAccessibilityElement viewContainingAccessibilityElement:element];
KIFTestCondition([tableView isKindOfClass:[UITableView class]], error, @"Specified view is not a UITableView");
KIFTestCondition(tableView, error, @"Table view with label %@ not found", tableViewLabel);
NSInteger numberOfSections = [tableView.dataSource numberOfSectionsInTableView:tableView];
KIFTestWaitCondition(numberOfSections == sections, error, @"Specified table view does not contain %D section%@", sections, sections == 1 ? @"" : @"s");
return KIFTestStepResultSuccess;
}];
}
+ (id)stepToVerifyNumberOfRows:(NSInteger)rows inSection:(NSInteger)section ofTableViewWithAccessibilityLabel:(NSString *)tableViewLabel
{
NSString *description = [NSString stringWithFormat:@"Step to verify number of rows in section %D of tableView is %D", section, rows];
return [KIFTestStep stepWithDescription:description executionBlock:^(KIFTestStep *step, NSError **error) {
UIAccessibilityElement *element = [[UIApplication sharedApplication] accessibilityElementWithLabel:tableViewLabel];
KIFTestCondition(element, error, @"View with label %@ not found", tableViewLabel);
UITableView *tableView = (UITableView*)[UIAccessibilityElement viewContainingAccessibilityElement:element];
KIFTestCondition([tableView isKindOfClass:[UITableView class]], error, @"Specified view is not a UITableView");
KIFTestCondition(tableView, error, @"Table view with label %@ not found", tableViewLabel);
NSInteger numberOfRows = [tableView.dataSource tableView:tableView numberOfRowsInSection:section];
KIFTestWaitCondition(numberOfRows == rows, error, @"Specified section (%D) does not contain %D row%@", section, rows, rows == 1 ? @"" : @"s");
return KIFTestStepResultSuccess;
}];
}
@end