Skip to content

Commit a776837

Browse files
author
Justin Martin
committed
Stabilize the pull to refresh tests
1 parent c3cc4cc commit a776837

6 files changed

+171
-85
lines changed

KIF Tests/AccessibilityIdentifierPullToRefreshTests.m

+14-18
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,27 @@ @interface AccessibilityIdentifierPullToRefreshTests : KIFTestCase
1515

1616
@implementation AccessibilityIdentifierPullToRefreshTests
1717

18-
-(void) testPullToRefreshByAccessibilityIdentifier
18+
- (void)afterEach
1919
{
20-
UITableView *tableView;
21-
[tester waitForAccessibilityElement:NULL view:&tableView withIdentifier:@"Test Suite TableView" tappable:NO];
22-
23-
[tester tapViewWithAccessibilityLabel:@"Reset Refresh Control"];
24-
[tester pullToRefreshViewWithAccessibilityIdentifier:@"Test Suite TableView"];
25-
[tester waitForViewWithAccessibilityLabel:@"Bingo!"];
26-
[tester waitForAbsenceOfViewWithAccessibilityLabel:@"Bingo!"];
20+
// For some reason, the pull to refresh is ending before we call endRefreshing.
21+
// For more context, see the comment in the PullToRefreshTests class.
22+
[tester waitForTimeInterval:3.0];
2723
}
2824

29-
-(void) testPullToRefreshByAccessibilityIdentifierWithDuration
25+
- (void)testPullToRefreshByAccessibilityIdentifier
3026
{
31-
UITableView *tableView;
32-
[tester waitForAccessibilityElement:NULL view:&tableView withIdentifier:@"Test Suite TableView" tappable:NO];
33-
34-
[tester tapViewWithAccessibilityLabel:@"Reset Refresh Control"];
35-
[tester pullToRefreshViewWithAccessibilityIdentifier:@"Test Suite TableView" pullDownDuration:KIFPullToRefreshInAboutThreeSeconds];
36-
[tester waitForViewWithAccessibilityLabel:@"Bingo!"];
37-
[tester waitForAbsenceOfViewWithAccessibilityLabel:@"Bingo!"];
27+
[tester waitForViewWithAccessibilityIdentifier:@"Test Suite TableView"];
28+
[tester pullToRefreshViewWithAccessibilityIdentifier:@"Test Suite TableView"];
29+
[tester waitForViewWithAccessibilityLabel:@"Bingo!"];
30+
[tester waitForAbsenceOfViewWithAccessibilityLabel:@"Bingo!"];
3831
}
3932

40-
- (void)afterEach
33+
- (void)testPullToRefreshByAccessibilityIdentifierWithDuration
4134
{
42-
[tester waitForAnimationsToFinish];
35+
[tester waitForViewWithAccessibilityIdentifier:@"Test Suite TableView"];
36+
[tester pullToRefreshViewWithAccessibilityIdentifier:@"Test Suite TableView" pullDownDuration:KIFPullToRefreshInAboutAHalfSecond];
37+
[tester waitForViewWithAccessibilityLabel:@"Bingo!"];
38+
[tester waitForAbsenceOfViewWithAccessibilityLabel:@"Bingo!"];
4339
}
4440

4541
@end

KIF Tests/PullToRefreshTests.m

+24-11
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,43 @@ @interface PullToRefreshTests : KIFTestCase
1515

1616
@implementation PullToRefreshTests
1717

18-
-(void) testPullToRefreshByAccessibilityLabelWithDuration
18+
- (void)afterEach
1919
{
20-
UITableView *tableView;
21-
[tester waitForAccessibilityElement:NULL view:&tableView withIdentifier:@"Test Suite TableView" tappable:NO];
22-
23-
[tester pullToRefreshViewWithAccessibilityLabel:@"Table View" pullDownDuration:KIFPullToRefreshInAboutThreeSeconds];
24-
[tester waitForViewWithAccessibilityLabel:@"Bingo!"];
25-
[tester waitForAbsenceOfViewWithAccessibilityLabel:@"Bingo!"];
20+
// For some reason, on iOS 16.4 w/ Xcode 14.3.1, the pull to refresh is ending before
21+
// we call endRefreshing from `-[TestSuiteViewController pullToRefreshHandler].
22+
//
23+
// It seems like there is some difference in how we're synthesizing the touch events
24+
// compared to what happens when a user sends the touch events. Set a symbolic breakpoint
25+
// in "-[_UIRefreshControlModernContentView didTransitionFromState:toState:]" to see this
26+
// in action. The register $x2 contains the `fromState` and $x3 contains the `toState`.
27+
//
28+
// KIF: 3 -> 1 (many times), 3 -> 2, 3 -> 3, 3 -> 0
29+
// User: 0 -> 1, 1 -> 1 (many times), 1 -> 2, 2 -> 3, 3 -> 4, 4 -> 0
30+
//
31+
// So it seems like something is going wrong in translating the HID events in the
32+
// `kif_IOHIDEventWithTouches` phases to appropriate UIResfrashControl states.
33+
[tester waitForTimeInterval:3.0];
34+
}
2635

27-
[tester waitForTimeInterval:5.0f]; //make sure the PTR is finished.
36+
- (void)testPullToRefreshByAccessibilityLabelWithDuration
37+
{
38+
[tester waitForViewWithAccessibilityIdentifier:@"Test Suite TableView"];
39+
[tester pullToRefreshViewWithAccessibilityLabel:@"Table View" pullDownDuration:KIFPullToRefreshInAboutAHalfSecond];
40+
[tester waitForViewWithAccessibilityLabel:@"Bingo!"];
41+
[tester waitForAbsenceOfViewWithAccessibilityLabel:@"Bingo!"];
2842
}
2943

30-
-(void) testPullToRefreshWithBigContentSize
44+
- (void)testPullToRefreshWithBigContentSize
3145
{
3246
UITableView *tableView;
3347
[tester waitForAccessibilityElement:NULL view:&tableView withIdentifier:@"Test Suite TableView" tappable:NO];
3448
CGSize originalSize = tableView.contentSize;
3549
tableView.contentSize = CGSizeMake(1000, 10000);
3650

37-
[tester pullToRefreshViewWithAccessibilityLabel:@"Table View" pullDownDuration:KIFPullToRefreshInAboutThreeSeconds];
51+
[tester pullToRefreshViewWithAccessibilityLabel:@"Table View" pullDownDuration:KIFPullToRefreshInAboutAHalfSecond];
3852
[tester waitForViewWithAccessibilityLabel:@"Bingo!"];
3953
[tester waitForAbsenceOfViewWithAccessibilityLabel:@"Bingo!"];
4054

41-
[tester waitForTimeInterval:5.0f]; //make sure the PTR is finished.
4255
tableView.contentSize = originalSize;
4356
}
4457

KIF Tests/PullToRefreshTests_ViewTestActor.m

+11-6
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,31 @@ @interface PullToRefreshTests_ViewTestActor : KIFTestCase
1515

1616
@implementation PullToRefreshTests_ViewTestActor
1717

18-
-(void) testPullToRefreshByAccessibilityLabelWithDuration
18+
- (void)afterEach
19+
{
20+
// For some reason, the pull to refresh is ending before we call endRefreshing.
21+
// For more context, see the comment in the PullToRefreshTests class.
22+
[tester waitForTimeInterval:3.0];
23+
}
24+
25+
- (void)testPullToRefreshByAccessibilityLabelWithDuration
1926
{
2027
[[viewTester usingIdentifier:@"Test Suite TableView"] waitForView];
21-
[[viewTester usingLabel:@"Table View"] pullToRefreshWithDuration:KIFPullToRefreshInAboutOneSecond];
28+
[[viewTester usingLabel:@"Table View"] pullToRefreshWithDuration:KIFPullToRefreshInAboutAHalfSecond];
2229
[[viewTester usingLabel:@"Bingo!"] waitForView];
2330
[[viewTester usingLabel:@"Bingo!"] waitForAbsenceOfView];
24-
[viewTester waitForTimeInterval:1.0f];
2531
}
2632

27-
-(void) testPullToRefreshWithBigContentSize
33+
- (void)testPullToRefreshWithBigContentSize
2834
{
2935

3036
UITableView *tableView = (id)[[viewTester usingIdentifier:@"Test Suite TableView"] waitForView];
3137
CGSize originalSize = tableView.contentSize;
3238
tableView.contentSize = CGSizeMake(1000, 10000);
3339

34-
[[viewTester usingLabel:@"Table View"] pullToRefreshWithDuration:KIFPullToRefreshInAboutOneSecond];
40+
[[viewTester usingLabel:@"Table View"] pullToRefreshWithDuration:KIFPullToRefreshInAboutAHalfSecond];
3541
[[viewTester usingLabel:@"Bingo!"] waitForView];
3642
[[viewTester usingLabel:@"Bingo!"] waitForAbsenceOfView];
37-
[viewTester waitForTimeInterval:1.0f];
3843

3944
tableView.contentSize = originalSize;
4045
}

Sources/KIF/Classes/KIFUITestActor.m

+2-1
Original file line numberDiff line numberDiff line change
@@ -1330,7 +1330,8 @@ - (void)pullToRefreshAccessibilityElement:(UIAccessibilityElement *)element inVi
13301330
// Can handle only the touchable space.
13311331
CGRect elementFrame = [viewToSwipe convertRect:viewToSwipe.bounds toView:[UIApplication sharedApplication].keyWindow.rootViewController.view];
13321332
CGPoint swipeStart = CGPointCenteredInRect(elementFrame);
1333-
CGPoint swipeDisplacement = CGPointMake(CGRectGetMidX(elementFrame), CGRectGetMaxY(elementFrame));
1333+
swipeStart.y = swipeStart.y - CGRectGetMaxY(elementFrame) / 4.0;
1334+
CGPoint swipeDisplacement = CGPointMake(0, CGRectGetMaxY(elementFrame) / 2.0);
13341335

13351336
[viewToSwipe dragFromPoint:swipeStart displacement:swipeDisplacement steps:kNumberOfPointsInSwipePath];
13361337
}

0 commit comments

Comments
 (0)