Can KIF trigger UISwipeGestureRecognizers?

1,021 views
Skip to first unread message

Pete Hodgson

unread,
Oct 2, 2011, 11:47:55 AM10/2/11
to KIF iOS Automated Testing Framework
Hi,

I'm testing out KIF's gesture support, and seem to have hit a problem
in simulating swiping gestures such that they're detected by a
UISwipeGestureRecognizer attached to a view. Is there a known issue
with this?

I have a sample app that I've been using to test this. I can clean it
up and push it up to github if someone wants to reproduce this
locally. Meantime, here's the (rough-and-ready) KIF step I'm using to
simulate a swipe:



#define NUM_POINTS_IN_PATH (20)
- (id) stepToSwipeViewWithAccessibilityLabel:label;
{
NSString *description = [NSString stringWithFormat:@"swipe the
view with accessibility label \"%@\"", label];
return [KIFTestStep stepWithDescription:description
executionBlock:^(KIFTestStep *step, NSError **error) {
UIAccessibilityElement *element = [KIFTestStep
_accessibilityElementWithLabel:label accessibilityValue:nil
tappable:NO traits:UIAccessibilityTraitNone error:error];
if (!element) {
return KIFTestStepResultWait;
}

UIView *view = [UIAccessibilityElement
viewContainingAccessibilityElement:element];
KIFTestWaitCondition(view, error, @"Cannot find view with
accessibility label \"%@\"", label);

CGRect elementFrame = [view.window
convertRect:element.accessibilityFrame toView:view];
CGPoint swipeStart = CGPointCenteredInRect(elementFrame);
CGFloat x_delta = 150;
CGFloat y_delta = 5;

CGPoint swipePath[NUM_POINTS_IN_PATH];
for( int i = 0; i < NUM_POINTS_IN_PATH; i++ ){
CGFloat progress = ((CGFloat)i)/NUM_POINTS_IN_PATH;
swipePath[i] = CGPointMake( swipeStart.x +
(x_delta*progress), swipeStart.y+(y_delta*progress));
}

[view dragAlongPathWithPoints:swipePath
count:NUM_POINTS_IN_PATH];

return KIFTestStepResultSuccess;
}];
}


and here's the app code that sets up the gesture recognizer:

- (void)viewDidLoad
{
[super viewDidLoad];
self.title = @"Gestures";

_gestureView.accessibilityLabel = @"gesture here";

UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer
alloc]
initWithTarget:self
action:@selector(handleSingleTap)];
singleTap.numberOfTapsRequired = 1;
singleTap.numberOfTouchesRequired = 1;
[_gestureView addGestureRecognizer:singleTap];
[singleTap release];

UISwipeGestureRecognizer *rightSwipe = [[UISwipeGestureRecognizer
alloc] initWithTarget:self action:@selector(handleRightSwipe)];
rightSwipe.direction = UISwipeGestureRecognizerDirectionRight;
[_gestureView addGestureRecognizer:rightSwipe];
[rightSwipe release];
}

Note that the singleTap gesture recognizer does fire when KIF
simulates a tap.

Cheers,
Pete

Pete Hodgson

unread,
Oct 5, 2011, 12:38:52 PM10/5/11
to KIF iOS Automated Testing Framework
I investigated this a bit more, and have some additional details.

I created a custom gesture recognizer and registered it with the same
view, to try and get more insight into what the simulated touch events
from KIF look like. I do see the gesture recognizer's touchesBegan/
Moved/Ended/Etc methods being called. Once thing I did notice is that
when KIF is simulating a drag it doesn't set
UITouch::_previousLocationInWindow to the previous point in the path.
So I modified [UIView dragAlongPathWithPoints:count:] to set the
previous location but unfortunately the UISwipeGestureRecognizer is
still not recognizing the gesture. I'll continue to investigate.

Has anyone managed to use [UIView dragAlongPathWithPoints:count:]
successfully?

kyleplattner

unread,
Mar 28, 2012, 8:58:13 AM3/28/12
to kif-fr...@googlegroups.com
Has there been no updates on this? I was wanting to do the same thing. 
Reply all
Reply to author
Forward
0 new messages