4

This is pretty open-ended.

Does anyone have an idea as to how to test pull-to-refresh functionality in KIF Tests?

Neeraj
  • 8,408
  • 8
  • 41
  • 69

2 Answers2

3

Simply dragging from the top of the screen down to the bottom of the screen would do that, right? KIF has the following method implemented in the UIView-KIFAdditions category:

- (void)dragFromPoint:(CGPoint)startPoint toPoint:(CGPoint)endPoint;

I went ahead and created the following test step for simple dragging operations:

+ (id)stepToDragFromStartPoint:(CGPoint)startPoint toEndPoint:(CGPoint)endPoint
{
    NSString *description = [NSString stringWithFormat:@"Simulate dragging finger from point %.1f,%.1f to point %.1f,%.1f", startPoint.x, startPoint.y, endPoint.x, endPoint.y];
    return [KIFTestStep stepWithDescription:description executionBlock:^(KIFTestStep *step, NSError **error) {
        UIView *viewToSwipe = [UIApplication sharedApplication].keyWindow.subviews.lastObject;

        [viewToSwipe dragFromPoint:startPoint toPoint:endPoint];

        return KIFTestStepResultSuccess;
    }];
}

Hope that helps!

lottscarson
  • 578
  • 5
  • 14
  • sorry for noob question, how to use this function? I have test class inherited from KIFTestCase, what I must add to use this function? – Kate Geld Dec 07 '14 at 12:27
0

A while after posting this question, KIF has developed built-in "pull to refresh" functionality. See the following methods in KIFUITestActor

- (void)pullToRefreshViewWithAccessibilityLabel:(NSString *)label pullDownDuration:(KIFPullToRefreshTiming) pullDownDuration;
- (void)pullToRefreshViewWithAccessibilityLabel:(NSString *)label value:(NSString *)value;
- (void)pullToRefreshAccessibilityElement:(UIAccessibilityElement *)element inView:(UIView *)viewToSwipe pullDownDuration:(KIFPullToRefreshTiming) pullDownDuration;
Stonz2
  • 6,306
  • 4
  • 44
  • 64