Skip to content

Commit fe05c6c

Browse files
authored
Merge pull request #1251 from kif-framework/dostrander/tableview-tap-bug
Fix bug with table view elements that are matched but offscreen
2 parents 7542330 + 12ff7f6 commit fe05c6c

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

Sources/KIF/Classes/KIFUITestActor.m

+36
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,13 @@ - (void)tapAccessibilityElement:(UIAccessibilityElement *)element inView:(UIView
323323
KIFTestWaitCondition(view.isUserInteractionActuallyEnabled, error, @"View is not enabled for interaction: %@", view);
324324

325325
CGPoint tappablePointInElement = [self tappablePointInElement:element andView:view];
326+
327+
// If the element isn't immediately tappable, try checking if it is contained within scroll views that can be scrolled to make it tappable.
328+
if (isnan(tappablePointInElement.x)) {
329+
[self _scrollViewToTappablePointIfNeeded:view];
330+
331+
tappablePointInElement = [self tappablePointInElement:element andView:view];
332+
}
326333

327334
// This is mostly redundant of the test in _accessibilityElementWithLabel:
328335
KIFTestWaitCondition(!isnan(tappablePointInElement.x), error, @"View is not tappable: %@", view);
@@ -406,6 +413,12 @@ - (void)longPressAccessibilityElement:(UIAccessibilityElement *)element inView:(
406413
KIFTestWaitCondition(view.isUserInteractionActuallyEnabled, error, @"View is not enabled for interaction: %@", view);
407414

408415
CGPoint tappablePointInElement = [self tappablePointInElement:element andView:view];
416+
// If the element isn't immediately tappable, try checking if it is contained within scroll views that can be scrolled to make it tappable.
417+
if (isnan(tappablePointInElement.x)) {
418+
[self _scrollViewToTappablePointIfNeeded:view];
419+
420+
tappablePointInElement = [self tappablePointInElement:element andView:view];
421+
}
409422

410423
// This is mostly redundant of the test in _accessibilityElementWithLabel:
411424
KIFTestWaitCondition(!isnan(tappablePointInElement.x), error, @"View is not tappable: %@", view);
@@ -1570,6 +1583,13 @@ - (void)tapStepperWithAccessibilityElement:(UIAccessibilityElement *)element inc
15701583
KIFTestWaitCondition(view.isUserInteractionActuallyEnabled, error, @"View is not enabled for interaction: %@", view);
15711584

15721585
CGPoint stepperPointToTap = [self tappablePointInElement:element andView:view];
1586+
1587+
// If the element isn't immediately tappable, try checking if it is contained within scroll views that can be scrolled to make it tappable.
1588+
if (isnan(stepperPointToTap.x)) {
1589+
[self _scrollViewToTappablePointIfNeeded:view];
1590+
1591+
stepperPointToTap = [self tappablePointInElement:element andView:view];
1592+
}
15731593

15741594
switch (stepperDirection)
15751595
{
@@ -1580,6 +1600,7 @@ - (void)tapStepperWithAccessibilityElement:(UIAccessibilityElement *)element inc
15801600
stepperPointToTap.x -= CGRectGetWidth(view.frame) / 4;
15811601
break;
15821602
}
1603+
15831604

15841605
// This is mostly redundant of the test in _accessibilityElementWithLabel:
15851606
KIFTestWaitCondition(!isnan(stepperPointToTap.x), error, @"View is not tappable: %@", view);
@@ -1632,6 +1653,21 @@ - (KIFDisplacement)_displacementForSwipingInDirection:(KIFSwipeDirection)directi
16321653
}
16331654
}
16341655

1656+
- (void)_scrollViewToTappablePointIfNeeded:(UIView *)view
1657+
{
1658+
UIView *container = view;
1659+
1660+
do {
1661+
if ([container isKindOfClass:UIScrollView.class]) {
1662+
UIScrollView *containerScrollView = (UIScrollView *)container;
1663+
CGRect rect = [view convertRect:view.frame toView:containerScrollView];
1664+
[containerScrollView scrollRectToVisible:rect animated:NO];
1665+
}
1666+
1667+
container = container.superview;
1668+
} while (container != nil);
1669+
}
1670+
16351671
+ (BOOL)testActorAnimationsEnabled;
16361672
{
16371673
return KIFUITestActorAnimationsEnabled;

0 commit comments

Comments
 (0)