Best EarlGrey code snippet using performAction.grey_doubleTap
GestureTest.m
Source:GestureTest.m  
...43      assertWithMatcher:grey_sufficientlyVisible()];44}45- (void)testDoubleTap {46  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Grey Box")]47      performAction:grey_doubleTap()];48  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"double tap")]49      assertWithMatcher:grey_sufficientlyVisible()];50}51- (void)testDoubleTapAtPoint {52  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Grey Box")]53      performAction:grey_doubleTapAtPoint(CGPointMake(50, 50))];54  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"double tap")]55      assertWithMatcher:grey_sufficientlyVisible()];56  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"x:50.0 - y:50.0")]57      assertWithMatcher:grey_sufficientlyVisible()];58  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Grey Box")]59      performAction:grey_doubleTapAtPoint(CGPointMake(125, 10))];60  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"double tap")]61      assertWithMatcher:grey_sufficientlyVisible()];62  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"x:125.0 - y:10.0")]63      assertWithMatcher:grey_sufficientlyVisible()];64}65- (void)testLongPress {66  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Grey Box")]67      performAction:grey_longPress()];68  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"single long press")]69      assertWithMatcher:grey_sufficientlyVisible()];70}71- (void)testLongPressWithDuration {72  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Grey Box")]73      performAction:grey_longPressWithDuration(1.0)];...FTRGestureTest.m
Source:FTRGestureTest.m  
...42      assertWithMatcher:grey_sufficientlyVisible()];43}44- (void)testDoubleTap {45  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Grey Box")]46      performAction:grey_doubleTap()];47  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"double tap")]48      assertWithMatcher:grey_sufficientlyVisible()];49}50- (void)testDoubleTapAtPoint {51  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Grey Box")]52      performAction:grey_doubleTapAtPoint(CGPointMake(50, 50))];53  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"double tap")]54      assertWithMatcher:grey_sufficientlyVisible()];55  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"x:50.0 - y:50.0")]56      assertWithMatcher:grey_sufficientlyVisible()];57  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Grey Box")]58      performAction:grey_doubleTapAtPoint(CGPointMake(125, 10))];59  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"double tap")]60      assertWithMatcher:grey_sufficientlyVisible()];61  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"x:125.0 - y:10.0")]62      assertWithMatcher:grey_sufficientlyVisible()];63}64- (void)testLongPress {65  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Grey Box")]66      performAction:grey_longPressWithDuration(0.5f)];67  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"single long press")]68      assertWithMatcher:grey_sufficientlyVisible()];69}70- (void)testLongPressAtPoint {71  // Find the bounds of the element.72  __block CGRect targetBounds;73  GREYActionBlock *boundsFinder =74      [[GREYActionBlock alloc] initWithName:@"Frame finder"75                                constraints:nil76                               performBlock:^BOOL(UIView *view, NSError *__strong *error) {77    targetBounds = view.bounds;78    return YES;79  }];80  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Grey Box")]81      performAction:boundsFinder];82  // Verify tapping outside the bounds does not cause long press.83  CGFloat midX = CGRectGetMidX(targetBounds);84  CGFloat midY = CGRectGetMidY(targetBounds);85  CGPoint outsidePoints[4] = {86    CGPointMake(CGRectGetMinX(targetBounds) - 1, midY),87    CGPointMake(CGRectGetMaxX(targetBounds) + 1, midY),88    CGPointMake(midX, CGRectGetMinY(targetBounds) - 1),89    CGPointMake(midX, CGRectGetMaxY(targetBounds) + 1)90  };91  for (NSInteger i = 0; i < 4; i++) {92    [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Grey Box")]93        performAction:grey_longPressAtPointWithDuration(outsidePoints[i], 0.5f)];94    [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"single long press")]95        assertWithMatcher:grey_nil()];96  }97  // Verify that tapping inside the bounds causes the long press.98  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Grey Box")]99      performAction:grey_longPressAtPointWithDuration(CGPointMake(midX, midX), 0.5f)];100  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"single long press")]101      assertWithMatcher:grey_sufficientlyVisible()];102}103// Asserts that the given gesture has been recognised regardless of the gesture's start point.104- (void)grey_assertGestureRecognized:(NSString *)gesture {105  MatchesBlock gestureMatcherBlock = ^BOOL (id element) {106    NSString *text = [(UILabel *)element text];107    GREYAssert([text hasPrefix:gesture], @"Gesture prefix '%@' not found in '%@'.", gesture, text);108    return YES;109  };110  DescribeToBlock gestureMatcherDescriptionBlock = ^(id<GREYDescription> description) {111    [description appendText:@"Gesture Matcher"];112  };113  GREYElementMatcherBlock *gestureElementMatcher =114      [[GREYElementMatcherBlock alloc] initWithMatchesBlock:gestureMatcherBlock115                                           descriptionBlock:gestureMatcherDescriptionBlock];116  [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"gesture")]117      assertWithMatcher:gestureElementMatcher];118}119- (void)testSwipeWorksInAllDirectionsInPortraitMode {120  [self assertSwipeWorksInAllDirections];121}122- (void)testSwipeWorksInAllDirectionsInUpsideDownMode {123  [EarlGrey rotateDeviceToOrientation:UIDeviceOrientationPortraitUpsideDown errorOrNil:nil];124  [self assertSwipeWorksInAllDirections];125}126- (void)testSwipeWorksInAllDirectionsInLandscapeLeftMode {127  [EarlGrey rotateDeviceToOrientation:UIDeviceOrientationLandscapeLeft errorOrNil:nil];128  [self assertSwipeWorksInAllDirections];129}130- (void)testSwipeWorksInAllDirectionsInLandscapeRightMode {131  [EarlGrey rotateDeviceToOrientation:UIDeviceOrientationLandscapeRight errorOrNil:nil];132  [self assertSwipeWorksInAllDirections];133}134- (void)testSwipeOnWindow {135  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Window swipes start here")]136      performAction:grey_swipeFastInDirection(kGREYDirectionUp)];137  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"swipe up on window")]138      assertWithMatcher:grey_sufficientlyVisible()];139  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Window swipes start here")]140      performAction:grey_swipeFastInDirection(kGREYDirectionDown)];141  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"swipe down on window")]142      assertWithMatcher:grey_sufficientlyVisible()];143  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Window swipes start here")]144      performAction:grey_swipeFastInDirection(kGREYDirectionLeft)];145  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"swipe left on window")]146      assertWithMatcher:grey_sufficientlyVisible()];147  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Window swipes start here")]148      performAction:grey_swipeFastInDirection(kGREYDirectionRight)];149  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"swipe right on window")]150      assertWithMatcher:grey_sufficientlyVisible()];151}152- (void)testSwipeWithLocationForAllDirections {153  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Grey Box")]154      performAction:grey_swipeFastInDirectionWithStartPoint(kGREYDirectionUp, 0.25, 0.25)];155  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"swipe up startX:70.0 startY:70.0")]156      assertWithMatcher:grey_sufficientlyVisible()];157  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Grey Box")]158      performAction:grey_swipeFastInDirectionWithStartPoint(kGREYDirectionDown, 0.75, 0.75)];159  [[EarlGrey selectElementWithMatcher:160      grey_accessibilityLabel(@"swipe down startX:210.0 startY:210.0")]161      assertWithMatcher:grey_sufficientlyVisible()];162  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Grey Box")]163      performAction:grey_swipeFastInDirectionWithStartPoint(kGREYDirectionLeft, 0.875, 0.5)];164  [[EarlGrey selectElementWithMatcher:165      grey_accessibilityLabel(@"swipe left startX:245.0 startY:140.0")]166      assertWithMatcher:grey_sufficientlyVisible()];167  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Grey Box")]168      performAction:grey_swipeFastInDirectionWithStartPoint(kGREYDirectionRight, 0.125, 0.75)];169  [[EarlGrey selectElementWithMatcher:170      grey_accessibilityLabel(@"swipe right startX:35.0 startY:210.0")]171      assertWithMatcher:grey_sufficientlyVisible()];172}173#pragma mark - Private174- (id<GREYAction>)tapWithAmount:(int)amount {175  if (amount == 1) {176    return grey_tap();177  } else if (amount == 2) {178    return grey_doubleTap();179  } else {180    return grey_multipleTapsWithCount((NSUInteger)amount);181  }182}183// Asserts that Swipe works in all directions by verifying if the swipe gestures are correctly184// recognized.185- (void)assertSwipeWorksInAllDirections {186  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Grey Box")]187      performAction:grey_swipeFastInDirection(kGREYDirectionUp)];188  [self grey_assertGestureRecognized:@"swipe up"];189  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Grey Box")]190      performAction:grey_swipeSlowInDirection(kGREYDirectionDown)];191  [self grey_assertGestureRecognized:@"swipe down"];192  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Grey Box")]...EarlGreyExampleTests.m
Source:EarlGreyExampleTests.m  
...60- (void)testCollectionMatchers {61  id<GREYMatcher> visibleSendButtonMatcher =62      grey_allOf(grey_accessibilityID(@"ClickMe"), grey_sufficientlyVisible(), nil);63  [[EarlGrey selectElementWithMatcher:visibleSendButtonMatcher]64      performAction:grey_doubleTap()];65}66- (void)testWithInRoot {67  // Second way to disambiguate: use inRoot to focus on a specific window or container.68  // There are two buttons with accessibility id "Send", but only one is inside SendMessageView.69  [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Send")]70      inRoot:grey_kindOfClass([SendMessageView class])]71      performAction:grey_doubleTap()];72}73// Define a custom matcher for table cells that contains a date for a Thursday.74- (id<GREYMatcher>)matcherForThursdays {75  MatchesBlock matches = ^BOOL(UIView *cell) {76    if ([cell isKindOfClass:[UITableViewCell class]]) {77      NSDateFormatter *formatter = [[NSDateFormatter alloc] init];78      formatter.dateStyle = NSDateFormatterLongStyle;79      NSDate *date = [formatter dateFromString:[[(UITableViewCell *)cell textLabel] text]];80      if (!date) {81        return NO;82      }83      NSCalendar *calendar = [NSCalendar currentCalendar];84      NSInteger weekday = [calendar component:NSCalendarUnitWeekday fromDate:date];85      return weekday == 5;86    } else {87      return NO;88    }89  };90  DescribeToBlock describe = ^void(id<GREYDescription> description) {91    [description appendText:@"Date for a Thursday"];92  };93  return [[GREYElementMatcherBlock alloc] initWithMatchesBlock:matches94                                              descriptionBlock:describe];95}96- (void)testWithCustomMatcher {97  // Use the custom matcher.98  [[EarlGrey selectElementWithMatcher:[self matcherForThursdays]]99      performAction:grey_doubleTap()];100}101- (void)testTableCellOutOfScreen {102  // Go find one cell out of the screen.103  [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Cell30")]104      usingSearchAction:grey_scrollInDirection(kGREYDirectionDown, 50)105   onElementWithMatcher:grey_accessibilityID(@"table")]106      performAction:grey_doubleTap()];107  // Move back to top of the table.108  [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Cell1")]109      usingSearchAction:grey_scrollInDirection(kGREYDirectionUp, 500)110   onElementWithMatcher:grey_accessibilityID(@"table")]111      performAction:grey_doubleTap()];112}113- (void)testCatchErrorOnFailure {114  // TapMe doesn't exist, but the test doesn't fail because we are getting a pointer to the error.115  NSError *error;116  [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TapMe")]117      performAction:grey_tap() error:&error];118  if (error) {119    NSLog(@"Error: %@", [error localizedDescription]);120  }121}122// Fade in and out an element.123- (void)fadeInAndOut:(UIView *)element {124  [UIView animateWithDuration:1.0125                        delay:0.0...EarlGreyExampleUITests.m
Source:EarlGreyExampleUITests.m  
...62}63- (void)testCollectionMatchers {64  id<GREYMatcher> visibleSendButtonMatcher =65      grey_allOf(grey_accessibilityID(@"ClickMe"), grey_sufficientlyVisible(), nil);66  [[EarlGrey selectElementWithMatcher:visibleSendButtonMatcher] performAction:grey_doubleTap()];67}68- (void)testWithInRoot {69  // Second way to disambiguate: use inRoot to focus on a specific window or container.70  // There are two buttons with accessibility id "Send", but only one is inside SendMessageView.71  [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Send")]72      inRoot:grey_kindOfClassName(@"EarlGreyExampleSwift.SendMessageView")]73      performAction:grey_doubleTap()];74}75// Define a custom matcher for table cells that contains a date for a Thursday.76- (id<GREYMatcher>)matcherForThursdays {77  GREYMatchesBlock matches = ^BOOL(UITableViewCell *cell) {78    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];79    formatter.dateStyle = NSDateFormatterLongStyle;80    NSDate *date = [formatter dateFromString:[[(UITableViewCell *)cell textLabel] text]];81    if (!date) {82      return NO;83    }84    NSCalendar *calendar = [NSCalendar currentCalendar];85    NSInteger weekday = [calendar component:NSCalendarUnitWeekday fromDate:date];86    return weekday == 5;87  };88  GREYDescribeToBlock describe = ^void(id<GREYDescription> description) {89    [description appendText:@"Date for a Thursday"];90  };91  return [[GREYElementMatcherBlock alloc] initWithMatchesBlock:matches descriptionBlock:describe];92}93- (void)testWithCustomMatcher {94  // Use the custom matcher.95  [[EarlGrey selectElementWithMatcher:grey_allOf(grey_kindOfClass([UITableViewCell class]),96                                                 [self matcherForThursdays], nil)]97      performAction:grey_doubleTap()];98}99- (void)testTableCellOutOfScreen {100  // Go find one cell out of the screen.101  [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Cell30")]102         usingSearchAction:grey_scrollInDirection(kGREYDirectionDown, 50)103      onElementWithMatcher:grey_accessibilityID(@"table")] performAction:grey_doubleTap()];104  // Move back to top of the table.105  [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Cell1")]106         usingSearchAction:grey_scrollInDirection(kGREYDirectionUp, 500)107      onElementWithMatcher:grey_accessibilityID(@"table")] performAction:grey_doubleTap()];108}109- (void)testCatchErrorOnFailure {110  // TapMe doesn't exist, but the test doesn't fail because we are getting a pointer to the error.111  NSError *error;112  [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TapMe")] performAction:grey_tap()113                                                                              error:&error];114  if (error) {115    NSLog(@"Error: %@", [error localizedDescription]);116  }117}118// Fade in and out an element.119- (void)fadeInAndOut:(UIView *)element {120  [UIView animateWithDuration:1.0121      delay:0.0...grey_doubleTap
Using AI Code Generation
1[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"text_field_id")]2      performAction:grey_doubleTap()];3[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"text_field_id")]4      performAction:grey_tap()];5[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"text_field_id")]6      performAction:grey_doubleTap()];7[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"text_field_id")]8      performAction:grey_tap()];9+ (id<GREYAction>)grey_doubleTap {10                              positionType:kGREYPositionCenter];11}12+ (id<GREYAction>)grey_tap {13                              positionType:kGREYPositionCenter];14}15- (instancetype)initWithName:(NSString *)name16                       count:(NSUInteger)count17                   duration:(CFTimeInterval)duration18               positionType:(GREYPositionType)positionType;19- (instancetype)initWithName:(NSString *)name20                       count:(NSUInteger)count21                   duration:(CFTimeInterval)duration22               positionType:(GREYPositionType)positionType;23- (instancetype)initWithName:(NSString *)name24                       count:(NSUInteger)count25                   duration:(CFTimeInterval)duration26               positionType:(GREYPositionType)positionType {grey_doubleTap
Using AI Code Generation
1[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"myID")] performAction:grey_doubleTap()];2GREY_EXPORT id<GREYAction> grey_doubleTap();3id<GREYAction> grey_doubleTap() {4  return [GREYActions actionForMultipleTapsWithCount:2];5}6GREY_EXPORT id<GREYAction> grey_actionForMultipleTapsWithCount(NSUInteger tapCount);7id<GREYAction> grey_actionForMultipleTapsWithCount(NSUInteger tapCount) {8  return [GREYActions actionForMultipleTapsWithCount:tapCount duration:0];9}10GREY_EXPORT id<GREYAction> grey_actionForMultipleTapsWithCountAndDuration(NSUInteger tapCount, CFTimeInterval duration);11id<GREYAction> grey_actionForMultipleTapsWithCountAndDuration(NSUInteger tapCount, CFTimeInterval duration) {12  return [GREYActions actionForMultipleTapsWithCount:tapCount duration:duration];13}14GREY_EXPORT id<GREYAction> grey_actionForMultipleTapsWithCountAndDurationAndPosition(NSUInteger tapCount, CFTimeInterval duration, CGPoint position);15id<GREYAction> grey_actionForMultipleTapsWithCountAndDurationAndPosition(NSUInteger tapCount, CFTimeInterval duration, CGPoint position) {16  return [GREYActions actionForMultipleTapsWithCount:tapCount duration:duration position:position];17}grey_doubleTap
Using AI Code Generation
1[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"test-DoubleTap")] performAction:grey_doubleTap()];2[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"test-DoubleTap")] performAction:grey_doubleTap()];3[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"test-DoubleTap")] performAction:grey_doubleTap()];4[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"test-DoubleTap")] performAction:grey_doubleTap()];5[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"test-DoubleTap")] performAction:grey_doubleTap()];6[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"test-DoubleTap")] performAction:grey_doubleTap()];7[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"test-DoubleTap")] performAction:grey_doubleTap()];8[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"test-DoubleTap")] performAction:grey_doubleTap()];9EarlGrey.selectElement(with: grey_accessibilityID("test-DoubleTap")).perform(grey_doubleTap())10EarlGrey.selectElement(with: grey_accessibilityID("test-DoubleTap")).perform(grey_doubleTap())11EarlGrey.selectElement(with: grey_accessibilityID("test-DoubleTap")).perform(grey_doubleTap())12EarlGrey.selectElement(with: grey_accessibilityID("test-DoubleTap")).perform(grey_doubleTap())grey_doubleTap
Using AI Code Generation
1[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"id")] performAction:grey_doubleTap()];2[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"id")] performAction:grey_doubleTapAtPoint(CGPointMake(10, 10))];3[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"id")] performAction:grey_longPress()];4[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"id")] performAction:grey_longPressAtPoint(CGPointMake(10, 10))];5[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"id")] performAction:grey_longPressWithDuration(5)];6[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"id")] performAction:grey_longPressAtPointWithDuration(CGPointMake(10, 10), 5)];7[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"id")] performAction:grey_multiFingerTap(3)];8grey_multiFingerTapAtPoint(NSUInteger numberOfFingers, CGPoint point) is used to perform multi finger tap action at a particularLearn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
