Skip to content

Commit

Permalink
Merge pull request #1251 from kif-framework/dostrander/tableview-tap-bug
Browse files Browse the repository at this point in the history
Fix bug with table view elements that are matched but offscreen
  • Loading branch information
dostrander authored Dec 8, 2021
2 parents 7542330 + 12ff7f6 commit fe05c6c
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions Sources/KIF/Classes/KIFUITestActor.m
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,13 @@ - (void)tapAccessibilityElement:(UIAccessibilityElement *)element inView:(UIView
KIFTestWaitCondition(view.isUserInteractionActuallyEnabled, error, @"View is not enabled for interaction: %@", view);

CGPoint tappablePointInElement = [self tappablePointInElement:element andView:view];

// If the element isn't immediately tappable, try checking if it is contained within scroll views that can be scrolled to make it tappable.
if (isnan(tappablePointInElement.x)) {
[self _scrollViewToTappablePointIfNeeded:view];

tappablePointInElement = [self tappablePointInElement:element andView:view];
}

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

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

tappablePointInElement = [self tappablePointInElement:element andView:view];
}

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

CGPoint stepperPointToTap = [self tappablePointInElement:element andView:view];

// If the element isn't immediately tappable, try checking if it is contained within scroll views that can be scrolled to make it tappable.
if (isnan(stepperPointToTap.x)) {
[self _scrollViewToTappablePointIfNeeded:view];

stepperPointToTap = [self tappablePointInElement:element andView:view];
}

switch (stepperDirection)
{
Expand All @@ -1580,6 +1600,7 @@ - (void)tapStepperWithAccessibilityElement:(UIAccessibilityElement *)element inc
stepperPointToTap.x -= CGRectGetWidth(view.frame) / 4;
break;
}


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

- (void)_scrollViewToTappablePointIfNeeded:(UIView *)view
{
UIView *container = view;

do {
if ([container isKindOfClass:UIScrollView.class]) {
UIScrollView *containerScrollView = (UIScrollView *)container;
CGRect rect = [view convertRect:view.frame toView:containerScrollView];
[containerScrollView scrollRectToVisible:rect animated:NO];
}

container = container.superview;
} while (container != nil);
}

+ (BOOL)testActorAnimationsEnabled;
{
return KIFUITestActorAnimationsEnabled;
Expand Down

0 comments on commit fe05c6c

Please sign in to comment.