Best EarlGrey code snippet using performAction.grey_longPress
BasicInteractionTest.m
Source:BasicInteractionTest.m  
...75 * Performs a long press on an accessibility element in the Basic Views.76 */77- (void)testLongPressOnAccessibilityElement {78  [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];79  [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] performAction:grey_longPress()];80  [[EarlGrey selectElementWithMatcher:grey_buttonTitle(@"EarlGrey TestApp")]81      performAction:grey_tap()];82}83/**84 * Verify that matching time is not part of the interaction timeout time. Interaction timeout time85 * should be the time until the application is becomes idle.86 */87- (void)testMatcherThatTakesALongTime {88  GREYConfiguration *config = [GREYConfiguration sharedConfiguration];89  NSNumber *originalTimeout = [config valueForConfigKey:kGREYConfigKeyInteractionTimeoutDuration];90  [config setValue:@(5) forConfigKey:kGREYConfigKeyInteractionTimeoutDuration];91  [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];92  // This matcher should at least 10(s) to match.93  id<GREYMatcher> matcher =94      [[GREYHostApplicationDistantObject sharedInstance] matcherThatTakesTime:10];95  NSError *error;96  [[EarlGrey selectElementWithMatcher:grey_allOf(grey_keyWindow(), matcher, NULL)]97      assertWithMatcher:grey_notNil()98                  error:&error];99  XCTAssertNil(error, @"Interaction should finish successfully although matching takes longer than "100                      @"interaction time out time which is 5(s).");101  [config setValue:originalTimeout forConfigKey:kGREYConfigKeyInteractionTimeoutDuration];102}103/**104 * Checks if hierarchy printing can work using different distant object mechanisms.105 */106- (void)testHierarchyPrinting {107  [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] assertWithMatcher:grey_notNil()];108  NSString *hierarchyFromTheTest = [GREYElementHierarchy hierarchyString];109  NSString *hierarchyFromRemoteClass =110      [GREY_REMOTE_CLASS_IN_APP(GREYElementHierarchy) hierarchyString];111  NSString *hierarchyFromMainDistantObject =112      [[GREYHostApplicationDistantObject sharedInstance] elementHierarchyString];113  NSString *hierarchyFromBackgroundDistantObject =114      [[GREYHostBackgroundDistantObject sharedInstance] elementHierarchyString];115  XCTAssertEqualObjects(hierarchyFromTheTest, hierarchyFromRemoteClass);116  XCTAssertEqualObjects(hierarchyFromMainDistantObject, hierarchyFromRemoteClass);117  XCTAssertEqualObjects(hierarchyFromMainDistantObject, hierarchyFromBackgroundDistantObject);118}119/**120 * Check zooming outward from a scroll view.121 */122- (void)testZoomingOutwardFromScrollView {123  [self openTestViewNamed:@"Zooming Scroll View"];124  [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"ZoomingScrollView")]125      performAction:grey_pinchSlowInDirectionAndAngle(kGREYPinchDirectionOutward,126                                                      kGREYPinchAngleDefault)];127  [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"ZoomingScrollView")]128      performAction:grey_tap()];129  [[EarlGrey selectElementWithMatcher:grey_buttonTitle(@"EarlGrey TestApp")]130      performAction:grey_tap()];131}132/**133 * Check zooming into a scroll view.134 */135- (void)testZoomingIntoScrollView {136  [self openTestViewNamed:@"Zooming Scroll View"];137  [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"ZoomingScrollView")]138      performAction:grey_pinchSlowInDirectionAndAngle(kGREYPinchDirectionInward,139                                                      kGREYPinchAngleDefault)];140  [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"ZoomingScrollView")]141      performAction:grey_tap()];142  [[EarlGrey selectElementWithMatcher:grey_buttonTitle(@"EarlGrey TestApp")]143      performAction:grey_tap()];144}145/**146 * Tap on a button five times and ensure that it went through by checking a label that is changed147 * on a button press.148 */149- (void)testTappingOnSimpleTapView {150  [self openTestViewNamed:@"Simple Tap View"];151  for (int i = 0; i < 20; i++) {152    NSString *text = [NSString stringWithFormat:@"Num Clicks: %d", i];153    [[EarlGrey selectElementWithMatcher:grey_text(text)]154        assertWithMatcher:grey_sufficientlyVisible()];155    [[EarlGrey selectElementWithMatcher:grey_text(@"Button")] performAction:grey_tap()];156  }157}158/**159 * Ensure that any assertion on an unmatched element throws an exception.160 */161- (void)testNotNilCallOnUnmatchedElementThrowsException {162  XCTAssertThrows([[[EarlGrey selectElementWithMatcher:grey_kindOfClassName(@"GarbageValue")]163      atIndex:0] assertWithMatcher:grey_notNil()]);164}165/**166 * Ensure that a not-nil assertion on a matched element does not throw an exception.167 */168- (void)testNotNilCheckOnMatchedElementDoesNotThrowException {169  GREYElementInteraction *interaction =170      [[EarlGrey selectElementWithMatcher:grey_kindOfClass([UITableViewCell class])] atIndex:0];171  [interaction assertWithMatcher:grey_notNil()];172}173/**174 * Checks for error handling using EarlGrey's Error API.175 */176- (void)testErrorHandling {177  NSError *error;178  [[EarlGrey selectElementWithMatcher:grey_text(@"GarbageValue")] performAction:grey_tap()179                                                                          error:&error];180  XCTAssertEqualObjects(error.domain, kGREYInteractionErrorDomain,181                        @"Interaction Error not thrown for tapping on an invalid element.");182  error = nil;183  [[EarlGrey selectElementWithMatcher:grey_text(@"GarbageValue")] assertWithMatcher:grey_notNil()184                                                                              error:&error];185  XCTAssertEqualObjects(error.domain, kGREYInteractionErrorDomain,186                        @"Interaction Error not thrown for not-nil assert on an invalid element.");187  error = nil;188  [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()189                                                                         error:&error];190  XCTAssertNil(error, @"Error not nil for tapping on a valid element");191  error = nil;192  [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] assertWithMatcher:grey_notNil()193                                                                       error:&error];194  XCTAssertNil(error, @"Error not nil for asserting not-nil on a valid element");195}196/**197 * Perform typing in a text field and assert the typed value.198 */199- (void)testTypingRandomValueInTextFields {200  [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];201  [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] performAction:grey_tap()];202  [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"foo")]203      performAction:grey_typeText(@"hi")];204  [[EarlGrey selectElementWithMatcher:grey_text(@"hi")]205      assertWithMatcher:grey_sufficientlyVisible()];206  [[EarlGrey selectElementWithMatcher:grey_buttonTitle(@"EarlGrey TestApp")]207      performAction:grey_tap()];208}209/**210 * Perform typing a longer string with spaces and capital text in a text field and assert the211 * typed value.212 */213- (void)testTypingLongStringInTextField {214  [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];215  [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] performAction:grey_tap()];216  [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"foo")]217      performAction:grey_typeText(@"Sam01le SWiFt TeSt")];218  [[EarlGrey selectElementWithMatcher:grey_text(@"Sam01le SWiFt TeSt")]219      assertWithMatcher:grey_sufficientlyVisible()];220  [[EarlGrey selectElementWithMatcher:grey_buttonTitle(@"EarlGrey TestApp")]221      performAction:grey_tap()];222}223/**224 * Perform replace-text in a text field and assert the typed value.225 */226- (void)testReplaceTextInTextField {227  [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];228  [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] performAction:grey_tap()];229  [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"foo")]230      performAction:grey_replaceText(@"donec.metus+spam@google.com")];231  [[EarlGrey selectElementWithMatcher:grey_allOf(grey_text(@"donec.metus+spam@google.com"),232                                                 grey_kindOfClass([UITextField class]), nil)]233      assertWithMatcher:grey_sufficientlyVisible()];234  [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"foo")]235      performAction:grey_replaceText(@"aA1a1A1aA1AaAa1A1a")];236  [[EarlGrey selectElementWithMatcher:grey_allOf(grey_text(@"aA1a1A1aA1AaAa1A1a"),237                                                 grey_kindOfClass([UITextField class]), nil)]238      assertWithMatcher:grey_sufficientlyVisible()];239}240/**241 * Check notifications are fired on the main thread for the replace text action in a UITextField.242 */243- (void)testReplaceTextFiredNotifications {244  [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];245  [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] performAction:grey_tap()];246  [[GREYHostApplicationDistantObject sharedInstance] setUpObserverForReplaceText];247  [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"foo")]248      performAction:grey_replaceText(@"donec.metus+spam@google.com")];249  BOOL notificationReceived = [[GREYHostApplicationDistantObject sharedInstance]250      textFieldTextDidBeginEditingNotificationFiredOnMainThread];251  XCTAssertTrue(notificationReceived);252}253/**254 * Check for basic visibility checking in the Basic Views.255 */256- (void)testAssertionsInBasicViews {257  [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];258  [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")]259      assertWithMatcher:grey_sufficientlyVisible()];260  [[EarlGrey selectElementWithMatcher:grey_buttonTitle(@"EarlGrey TestApp")]261      performAction:grey_tap()];262}263/**264 * Use a GREYCondition to check if an element is visible on the screen. Toggle a Switch for the265 * element to be visible.266 */267- (void)testEarlGreyInvocationInsideConditionUsingWaitWithTimeout {268  [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];269  [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] performAction:grey_tap()];270  __block id<GREYAction> action =271      [[GREYHostApplicationDistantObject sharedInstance] actionForGettingTextFromMatchedElement];272  // Setup a condition to wait until a specific label says specific text.273  GREYCondition *waitCondition = [GREYCondition274      conditionWithName:@"WaitForLabelText"275                  block:^BOOL() {276                    NSError *error;277                    [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"sampleLabel")]278                        performAction:action279                                error:&error];280                    return error == nil;281                  }];282  // Switch text and wait.283  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Switch")]284      performAction:grey_turnSwitchOn(NO)];285  XCTAssertTrue([waitCondition waitWithTimeout:10.0],286                @"Switch not manipulated within the allotted time for a Condition.");287}288/**289 * Use a GREYCondition to check if an element is visible on the screen. Change a stepper value for290 * the element to be visible.291 */292- (void)testEarlGreyInvocationInsideConditionUsingWaitWithLargeTimeout {293  [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];294  GREYCondition *waitCondition = [GREYCondition295      conditionWithName:@"conditionWithAction"296                  block:^BOOL {297                    static double stepperValue = 51;298                    [[EarlGrey selectElementWithMatcher:grey_kindOfClass([UIStepper class])]299                        performAction:grey_setStepperValue(++stepperValue)];300                    return stepperValue == 55;301                  }];302  XCTAssertTrue([waitCondition waitWithTimeout:15.0],303                @"Stepper Change not completed within the allotted time for the Condition.");304  [[EarlGrey selectElementWithMatcher:grey_kindOfClass([UIStepper class])]305      assertWithMatcher:grey_stepperValue(55)];306}307/**308 * Ensure basic interaction with a stepper.309 */310- (void)testBasicInteractionWithStepper {311  [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];312  [[EarlGrey selectElementWithMatcher:grey_kindOfClass([UIStepper class])]313      performAction:grey_setStepperValue(87)];314  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Value Label")]315      assertWithMatcher:grey_text(@"Value: 87%")];316  [[[EarlGrey selectElementWithMatcher:grey_kindOfClass([UIStepper class])]317      performAction:grey_setStepperValue(16)] assertWithMatcher:grey_stepperValue(16)];318}319/**320 * Ensure basic interaction with a switch.321 */322- (void)testInteractionWithSwitch {323  [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];324  [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] performAction:grey_tap()];325  [[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Switch")]326      performAction:grey_turnSwitchOn(NO)] assertWithMatcher:grey_switchWithOnState(NO)];327  [[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Switch")]328      performAction:grey_turnSwitchOn(YES)] assertWithMatcher:grey_switchWithOnState(YES)];329  [[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Switch")]330      performAction:grey_turnSwitchOn(YES)] assertWithMatcher:grey_switchWithOnState(YES)];331  [[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Switch")]332      performAction:grey_turnSwitchOn(NO)] assertWithMatcher:grey_switchWithOnState(NO)];333}334/**335 * Ensure basic interaction with a switch using a short tap.336 */337- (void)testInteractionWithSwitchWithShortTap {338  [self openTestViewNamed:@"Switch Views"];339  [[EarlGrey selectElementWithMatcher:grey_allOf(grey_accessibilityID(@"switch1"),340                                                 grey_interactable(), nil)]341      performAction:grey_turnSwitchOnWithShortTap(NO)];342  [[EarlGrey selectElementWithMatcher:grey_allOf(grey_accessibilityID(@"switch1"),343                                                 grey_interactable(), nil)]344      performAction:grey_turnSwitchOnWithShortTap(YES)];345  [[EarlGrey selectElementWithMatcher:grey_allOf(grey_accessibilityID(@"switch1"),346                                                 grey_interactable(), nil)]347      performAction:grey_turnSwitchOnWithShortTap(YES)];348  [[EarlGrey selectElementWithMatcher:grey_allOf(grey_accessibilityID(@"switch1"),349                                                 grey_interactable(), nil)]350      performAction:grey_turnSwitchOnWithShortTap(NO)];351}352/**353 * Ensure basic interaction with a hidden label.354 */355- (void)testInteractionWithHiddenLabel {356  [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];357  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Hidden Label")]358      assertWithMatcher:grey_text(@"Hidden Label")];359}360/**361 * Ensure basic interaction with a view who's parent has alpha set to zero.362 */363- (void)testInteractionWithLabelWithParentWithAlphaZero {364  [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];365  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Long Press")]366      assertWithMatcher:grey_not(grey_sufficientlyVisible())];367}368/**369 * Ensure basic interaction using a remote matcher.370 */371- (void)testEarlGreyRemoteMatcher {372  id<GREYMatcher> matcher =373      [[GREYHostApplicationDistantObject sharedInstance] matcherForFirstElement];374  [[EarlGrey selectElementWithMatcher:grey_allOf(grey_kindOfClass([UITableViewCell class]), matcher,375                                                 nil)] performAction:grey_tap()];376  NSError *error;377  [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] assertWithMatcher:grey_notNil()378                                                                             error:&error];379  XCTAssertEqual(error.code, kGREYInteractionElementNotFoundErrorCode,380                 @"No table view cell from the main Table can be visible.");381}382/**383 * Ensure basic interaction using a remote action.384 */385- (void)testEarlGreyRemoteAction {386  [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];387  [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] performAction:grey_tap()];388  id<GREYAction> action =389      [[GREYHostApplicationDistantObject sharedInstance] actionForTapOnAccessibleElement];390  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Switch")] performAction:action];391}392/**393 * Ensure basic interaction using a remote assertion.394 */395- (void)testEarlGreyRemoteAssertion {396  id<GREYAssertion> assertion =397      [[GREYHostApplicationDistantObject sharedInstance] assertionThatAlphaIsGreaterThanZero];398  [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] assert:assertion];399}400/**401 * Disabled UIControl should still be tapped if requested.402 */403- (void)testTappingOnADisabledButton {404  [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];405  NSError *error;406  [[EarlGrey selectElementWithMatcher:grey_buttonTitle(@"Disabled")] performAction:grey_tap()407                                                                             error:&error];408  XCTAssertNil(error);409}410/**411 * Checks the working of a condition with a large timeout.412 */413- (void)testEarlGreyInvocationInsideGREYConditionUsingWaitWithLargeTimeout {414  [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];415  GREYCondition *condition = [GREYCondition416      conditionWithName:@"conditionWithAction"417                  block:^BOOL {418                    static double stepperValue = 51;419                    [[EarlGrey selectElementWithMatcher:grey_kindOfClass([UIStepper class])]420                        performAction:grey_setStepperValue(++stepperValue)];421                    return stepperValue == 55;422                  }];423  XCTAssertTrue([condition waitWithTimeout:10.0]);424  [[EarlGrey selectElementWithMatcher:grey_kindOfClass([UIStepper class])]425      assertWithMatcher:grey_stepperValue(55)];426}427/**428 * Checks the working of a condition with a normal timeout.429 */430- (void)testEarlGreyInvocationInsideGREYConditionUsingWaitWithTimeout {431  [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];432  [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] performAction:grey_tap()];433  id<GREYAction> action = [[GREYHostApplicationDistantObject sharedInstance] actionToGetLabelText];434  // Setup a condition to wait until a specific label says specific text.435  GREYCondition *waitCondition = [GREYCondition436      conditionWithName:@"WaitForLabelText"437                  block:^BOOL() {438                    [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"sampleLabel")]439                        performAction:action];440                    NSString *text = [[GREYHostApplicationDistantObject sharedInstance] labelText];441                    return [text isEqualToString:@"OFF"];442                  }];443  // Switch text and wait.444  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Switch")]445      performAction:grey_turnSwitchOn(NO)];446  XCTAssertTrue([waitCondition waitWithTimeout:10.0]);447}448/**449 * Check tapping on a new custom window that covers the whole screen.450 */451- (void)testTapOnWindow {452  [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];453  [[EarlGrey selectElementWithMatcher:grey_keyWindow()] performAction:grey_tap()];454  UIWindow *window = [[GREYHostApplicationDistantObject sharedInstance] setupGestureRecognizer];455  XCTAssertNotNil(window);456  // Tap on topmost window.457  [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TopMostWindow")]458      performAction:grey_tap()];459  [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TopMostWindow")]460      assertWithMatcher:grey_notVisible()];461}462/**463 * Check setting of the root view controller multiple times in the main window.464 */465- (void)testRootViewControllerSetMultipleTimesOnMainWindow {466  [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];467  UIViewController *originalVC =468      [[GREYHostApplicationDistantObject sharedInstance] originalVCAfterSettingNewVCAsRoot];469  [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] assertWithMatcher:grey_nil()];470  [[GREYHostApplicationDistantObject sharedInstance] setRootViewController:nil];471  [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] assertWithMatcher:grey_nil()];472  [[GREYHostApplicationDistantObject sharedInstance] setRootViewController:originalVC];473  [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] assertWithMatcher:grey_notNil()];474}475/**476 * Check setting of the root view controller in different windows.477 */478- (void)testRootViewControllerSetOnMultipleWindows {479  [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];480  UIWindow *window = nil;481  UIViewController *originalVC = [[GREYHostApplicationDistantObject sharedInstance]482      originalVCAfterSettingRootVCInAnotherWindow:window];483  [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] assertWithMatcher:grey_nil()];484  [[GREYHostApplicationDistantObject sharedInstance] setRootViewController:nil inWindow:window];485  [[GREYHostApplicationDistantObject sharedInstance] setRootViewController:originalVC];486  [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] assertWithMatcher:grey_notNil()];487}488/**489 * Ensures basic interactions with views.490 */491- (void)testBasicInteractionWithViews {492  [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];493  [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] performAction:grey_tap()];494  GREYElementInteraction *typeHere =495      [EarlGrey selectElementWithMatcher:grey_allOf(grey_accessibilityLabel(@"Type Something Here"),496                                                    grey_kindOfClass([UITextField class]), nil)];497  [[typeHere performAction:grey_replaceText(@"Hello 2")] assertWithMatcher:grey_text(@"Hello 2")];498  [typeHere performAction:grey_clearText()];499  [[typeHere performAction:grey_tapAtPoint(CGPointMake(0, 0))]500      performAction:grey_replaceText(@"Hello!")];501  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"return")] performAction:grey_tap()];502  [[EarlGrey selectElementWithMatcher:grey_buttonTitle(@"Send")]503      performAction:grey_tapAtPoint(CGPointMake(5, 5))];504  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Simple Label")]505      assertWithMatcher:grey_text(@"Hello!")];506  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Switch")]507      performAction:grey_turnSwitchOn(NO)];508  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Simple Label")]509      assertWithMatcher:grey_text(@"OFF")];510  [[[EarlGrey selectElementWithMatcher:grey_text(@"Long Press")]511      performAction:grey_longPressWithDuration(1.1f)] assertWithMatcher:grey_notVisible()];512  [[[EarlGrey selectElementWithMatcher:grey_text(@"Double Tap")] performAction:grey_doubleTap()]513      assertWithMatcher:grey_notVisible()];514}515/**516 * Checks a custom action.517 */518- (void)testEarlGreyInvocationInsideCustomAction {519  [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];520  id<GREYAction> action =521      [[GREYHostApplicationDistantObject sharedInstance] actionForCheckingIfElementHidden];522  NSError *error;523  [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] performAction:action error:&error];524  if (!error) {525    [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] performAction:grey_tap()];526    [[[EarlGrey selectElementWithMatcher:grey_text(@"Long Press")]527        performAction:grey_longPressWithDuration(1.1f)] assertWithMatcher:grey_hidden(YES)];528  } else {529    GREYFail(@"Element should exist. We should not be here.");530  }531}532/**533 * Checks a custom assertion.534 */535- (void)testEarlGreyInvocationInsideCustomAssertion {536  [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];537  id<GREYAssertion> assertion =538      [[GREYHostApplicationDistantObject sharedInstance] assertionForCheckingIfElementPresent];539  NSError *error;540  [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] assert:assertion error:&error];541  if (!error) {542    [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] performAction:grey_tap()];543    [[[EarlGrey selectElementWithMatcher:grey_text(@"Long Press")]544        performAction:grey_longPressWithDuration(1.1f)] assertWithMatcher:grey_hidden(YES)];545  } else {546    GREYFail(@"Element should exist. We should not be here.");547  }548}549/**550 * Verifies a long press at a point.551 */552- (void)testLongPressAtPointOnAccessibilityElement {553  [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];554  [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] performAction:grey_tap()];555  [[[EarlGrey selectElementWithMatcher:grey_text(@"Long Press")]556      performAction:grey_longPressAtPointWithDuration(CGPointMake(10, 10), 1.1f)]557      assertWithMatcher:grey_hidden(YES)];558}559/**560 * Checks long press on a text field.561 */562- (void)testLongPressOnTextField {563  [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];564  [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] performAction:grey_tap()];565  [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"foo")]566      performAction:grey_longPressWithDuration(1.0f)];567  [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] assertWithMatcher:grey_notNil()];568}569/**570 * Check long pressing followed by selecting a menu option.571 */572- (void)testLongPressFollowedBySelectingMenuOption {573  [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];574  [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] performAction:grey_tap()];575  [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"foo")]576      performAction:grey_typeText(@"Hello")];577  // For iOS 14, on doing a long press, the caret goes into a selection mode. To bring up the menu578  // a tap is required at the point of selection.579  if (iOS14_OR_ABOVE()) {580    [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"foo")]581        performAction:grey_tapAtPoint(CGPointMake(1, 1))];582  }583  [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"foo")]584      performAction:grey_longPressAtPointWithDuration(CGPointMake(1, 1), 1.0f)];585  [[EarlGrey selectElementWithMatcher:grey_text(@"Select")] performAction:grey_tap()];586  [[EarlGrey selectElementWithMatcher:grey_text(@"Cut")] performAction:grey_tap()];587  [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"foo")]588      performAction:grey_typeText(@"FromEarlGrey")];589  // For iOS 14, on doing a long press, the caret goes into a selection mode. To bring up the menu590  // a tap is required at the point of selection.591  if (iOS14_OR_ABOVE()) {592    [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"foo")]593        performAction:grey_tapAtPoint(CGPointMake(1, 1))];594  }595  [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"foo")]596      performAction:grey_longPressAtPointWithDuration(CGPointMake(1, 1), 1.0f)];597  [[EarlGrey selectElementWithMatcher:grey_text(@"Paste")] performAction:grey_tap()];598  // Smart Inserts in Xcode 9 cause a space to appear by default after a paste. With iOS 13,599  // the text is selected entirely on doing a long press, so the above paste will remove any600  // existing text in the textfield.601  if (iOS13()) {602    [[EarlGrey selectElementWithMatcher:grey_text(@"Hello")]603        assertWithMatcher:grey_sufficientlyVisible()];604  } else {605    [[EarlGrey selectElementWithMatcher:grey_text(@"Hello FromEarlGrey")]606        assertWithMatcher:grey_sufficientlyVisible()];607  }608}609/**610 * Check interaction with a view that has its parent view hidden and unhidden.611 */612- (void)testInteractionWithLabelWithParentHiddenAndUnhidden {613  [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];614  id<GREYAction> hideAction =615      [[GREYHostApplicationDistantObject sharedInstance] actionToHideOrUnhideBlock:YES];616  id<GREYAction> unhideAction =617      [[GREYHostApplicationDistantObject sharedInstance] actionToHideOrUnhideBlock:NO];618  [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] performAction:grey_tap()];619  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"tab2Container")]620      performAction:hideAction];621  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Long Press")]622      assertWithMatcher:grey_not(grey_sufficientlyVisible())];623  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"tab2Container")]624      performAction:unhideAction];625  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Long Press")]626      assertWithMatcher:grey_sufficientlyVisible()];627}628/**629 * Check interaction with a view that has its parent view opaque and translucent.630 */631- (void)testInteractionWithLabelWithParentTranslucentAndOpaque {632  [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];633  id<GREYAction> makeOpaqueAction =634      [[GREYHostApplicationDistantObject sharedInstance] actionToMakeOpaque:YES];635  id<GREYAction> makeTransparentAction =636      [[GREYHostApplicationDistantObject sharedInstance] actionToMakeOpaque:NO];637  [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] performAction:grey_tap()];638  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"tab2Container")]639      performAction:makeTransparentAction];640  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Long Press")]641      assertWithMatcher:grey_not(grey_sufficientlyVisible())];642  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"tab2Container")]643      performAction:makeOpaqueAction];644  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Long Press")]645      assertWithMatcher:grey_sufficientlyVisible()];646}647/**648 * Check interaction with a view that has its window opaque and translucent.649 *650 * @remark No test is provided for the key window since changing its hidden value will651 *         cause other tests to fail since the keyWindow is modified.652 */653- (void)testInteractionWithLabelWithWindowTranslucentAndOpaque {654  [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];655  id<GREYAction> makeOpaqueAction =656      [[GREYHostApplicationDistantObject sharedInstance] actionToMakeWindowOpaque:YES];657  id<GREYAction> makeTransparentAction =658      [[GREYHostApplicationDistantObject sharedInstance] actionToMakeWindowOpaque:NO];659  [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] performAction:grey_tap()];660  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"tab2Container")]661      performAction:makeTransparentAction];662  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Long Press")]663      assertWithMatcher:grey_not(grey_sufficientlyVisible())];664  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"tab2Container")]665      performAction:makeOpaqueAction];666  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Long Press")]667      assertWithMatcher:grey_sufficientlyVisible()];668}669/**670 * Checks the state of a UIButton.671 */672- (void)testButtonSelectedState {673  [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];674  [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] performAction:grey_tap()];675  id<GREYMatcher> buttonMatcher = grey_buttonTitle(@"Send");676  [[EarlGrey selectElementWithMatcher:buttonMatcher] assertWithMatcher:grey_not(grey_selected())];677  [[EarlGrey selectElementWithMatcher:buttonMatcher] performAction:grey_tap()];678  [[EarlGrey selectElementWithMatcher:buttonMatcher] assertWithMatcher:grey_selected()];679}680/**681 * Checks the removal and addition of the status bar.682 */683- (void)testStatusBarRemoval {684  // By default, the status bar should not be included.685  NSError *error;686  NSString *statusBarClassName = iOS13_OR_ABOVE() ? @"UIStatusBar_Modern" : @"UIStatusBarWindow";687  GREYElementInteraction *interaction =688      [EarlGrey selectElementWithMatcher:grey_kindOfClassName(statusBarClassName)];689  [interaction assertWithMatcher:grey_notNil() error:&error];690  XCTAssertNotNil(error, @"Error is nil.");691  error = nil;692  // By setting the includeStatusBar variable, the Status Bar should be found.693  [interaction includeStatusBar];694  [interaction assertWithMatcher:grey_notNil() error:&error];695  XCTAssertNil(error, @"Error: %@ is not nil.", error);696}697/**698 * Checks an interaction with shorthand matchers created in the app side.699 */700- (void)testActionAndMatcherShorthandCreatedInTheApp {701  id<GREYAction> tapAction =702      [[GREYHostApplicationDistantObject sharedInstance] sampleShorthandAction];703  id<GREYMatcher> keyWindowMatcher =704      [[GREYHostApplicationDistantObject sharedInstance] sampleShorthandMatcher];705  [[EarlGrey selectElementWithMatcher:keyWindowMatcher] performAction:tapAction];706}707/**708 * Checks that using the EarlGrey Wait function synchronizes correctly.709 */710- (void)testAssertionForAppIdling {711  [self openTestViewNamed:@"Animations"];712  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"AnimationControl")]713      performAction:grey_tap()];714  GREYWaitForAppToIdle(@"Wait for Animations");715  [[GREYConfiguration sharedConfiguration] setValue:@(NO)716                                       forConfigKey:kGREYConfigKeySynchronizationEnabled];717  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"AnimationStatus")]718      assertWithMatcher:grey_text(@"Paused")];719  [[GREYConfiguration sharedConfiguration] setValue:@(YES)720                                       forConfigKey:kGREYConfigKeySynchronizationEnabled];721}722/**723 * Checks that using the EarlGrey Wait function with a sufficient timeout synchronizes correctly.724 */725- (void)testAssertionForAppIdlingWithTimeout {726  [self openTestViewNamed:@"Animations"];727  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"AnimationControl")]728      performAction:grey_tap()];729  GREYWaitForAppToIdleWithTimeout(5.0, @"Wait for Animations");730  [[GREYConfiguration sharedConfiguration] setValue:@(NO)731                                       forConfigKey:kGREYConfigKeySynchronizationEnabled];732  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"AnimationStatus")]733      assertWithMatcher:grey_text(@"Paused")];734  [[GREYConfiguration sharedConfiguration] setValue:@(YES)735                                       forConfigKey:kGREYConfigKeySynchronizationEnabled];736}737/**738 * Checks that using the wait and assert-block API synchronizes correctly.739 */740- (void)testWaitAndAssertBlock {741  [self openTestViewNamed:@"Animations"];742  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"AnimationControl")]743      performAction:grey_tap()];744  GREYWaitAndAssertBlock(@"Confirm Animations finished", ^void(void) {745    [[GREYConfiguration sharedConfiguration] setValue:@(NO)746                                         forConfigKey:kGREYConfigKeySynchronizationEnabled];747    [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"AnimationStatus")]748        assertWithMatcher:grey_text(@"Paused")];749  });750  [[GREYConfiguration sharedConfiguration] setValue:@(YES)751                                       forConfigKey:kGREYConfigKeySynchronizationEnabled];752}753/**754 * Checks basic interactions on a context menu with top-level and child-actions obtained from755 * long-pressing a button.756 */757- (void)testInteractionWithContextMenu {758  if (@available(iOS 13.0, *)) {759    [self openTestViewNamed:@"Basic Views"];760    [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"ContextMenuButton")]761        performAction:grey_longPress()];762    XCTAssertTrue([self waitForVisibilityForText:@"Top-level Action"]);763    [[EarlGrey selectElementWithMatcher:grey_text(@"Top-level Action")] performAction:grey_tap()];764    XCTAssertTrue([self waitForVisibilityForText:@"Top-level Action Tapped"]);765    [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"ContextMenuButton")]766        performAction:grey_longPress()];767    XCTAssertTrue([self waitForVisibilityForText:@"Child Actions"]);768    [[EarlGrey selectElementWithMatcher:grey_text(@"Child Actions")] performAction:grey_tap()];769    XCTAssertTrue([self waitForVisibilityForText:@"Child Action 0"]);770    [[EarlGrey selectElementWithMatcher:grey_text(@"Child Action 0")] performAction:grey_tap()];771    XCTAssertTrue([self waitForVisibilityForText:@"Child Action 0 Tapped"]);772    [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"ContextMenuButton")]773        performAction:grey_longPress()];774    XCTAssertTrue([self waitForVisibilityForText:@"Child Actions"]);775    [[EarlGrey selectElementWithMatcher:grey_text(@"Child Actions")] performAction:grey_tap()];776    XCTAssertTrue([self waitForVisibilityForText:@"Child Action 1"]);777    [[EarlGrey selectElementWithMatcher:grey_text(@"Child Action 1")] performAction:grey_tap()];778    XCTAssertTrue([self waitForVisibilityForText:@"Child Action 1 Tapped"]);779  }780}781/**782 * Perform typing in a text field and assert the typed value.783 */784- (void)testSettingAndResettingRootWindow {785  [[GREY_REMOTE_CLASS_IN_APP(UIApplication) sharedApplication] keyWindow].accessibilityIdentifier =786      @"Main Window";787  [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];...FTRUIWebViewTest.m
Source:FTRUIWebViewTest.m  
...141  // Wait for the local page to load.142  [self ftr_waitForElementWithAccessibilityLabelToAppear:@"Row 1"];143  // Long press on the next test link.144  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Link to Next Test")]145      performAction:grey_longPress()];146  // Click on 'Open' button to validate the popup147  id<GREYMatcher> openLabelMatcher = grey_allOf(grey_accessibilityTrait(UIAccessibilityTraitButton),148                                                grey_accessibilityLabel(@"Open"), nil);149  [[EarlGrey selectElementWithMatcher:openLabelMatcher] performAction:grey_tap()];150}151#pragma mark - Private152// All the following private functions starting with "ftr_" are being used by153// disabled tests.154- (void)ftr_waitForElementWithAccessibilityLabelToAppear:(NSString *)axLabel {155  NSString *conditionName = [NSString stringWithFormat:@"WaitFor%@", axLabel];156  GREYCondition *conditionForElement = [GREYCondition157      conditionWithName:conditionName158                  block:^BOOL {159                    NSError *error;...UIWebViewTest.m
Source:UIWebViewTest.m  
...141  // Wait for the local page to load.142  [self ftr_waitForElementWithAccessibilityLabelToAppear:@"Row 1"];143  // Long press on the next test link.144  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Link to Next Test")]145      performAction:grey_longPress()];146  // Click on 'Open' button to validate the popup147  id<GREYMatcher> openLabelMatcher = grey_allOf(grey_accessibilityTrait(UIAccessibilityTraitButton),148                                                grey_accessibilityLabel(@"Open"), nil);149  [[EarlGrey selectElementWithMatcher:openLabelMatcher] performAction:grey_tap()];150}151#pragma mark - Private152// All the following private functions starting with "ftr_" are being used by153// disabled tests.154- (void)ftr_waitForElementWithAccessibilityLabelToAppear:(NSString *)axLabel {155  NSString *conditionName = [NSString stringWithFormat:@"WaitFor%@", axLabel];156  GREYCondition *conditionForElement = [GREYCondition157      conditionWithName:conditionName158                  block:^BOOL {159                    NSError *error;...FTRGestureTest.m
Source:FTRGestureTest.m  
...62      assertWithMatcher:grey_sufficientlyVisible()];63}64- (void)testLongPress {65  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Grey Box")]66      performAction:grey_longPress()];67  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"single long press")]68      assertWithMatcher:grey_sufficientlyVisible()];69}70- (void)testLongPressWithDuration {71  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Grey Box")]72      performAction:grey_longPressWithDuration(1.0)];73  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"single long press")]74      assertWithMatcher:grey_sufficientlyVisible()];75}76- (void)testLongPressWithDurationAtPoint {77  // Find the bounds of the element.78  __block CGRect targetBounds;79  GREYActionBlock *boundsFinder =80      [[GREYActionBlock alloc] initWithName:@"Frame finder"81                                constraints:nil82                               performBlock:^BOOL(UIView *view, NSError *__strong *error) {83    targetBounds = view.bounds;84    return YES;85  }];86  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Grey Box")]87      performAction:boundsFinder];88  // Verify tapping outside the bounds does not cause long press.89  CGFloat midX = CGRectGetMidX(targetBounds);90  CGFloat midY = CGRectGetMidY(targetBounds);91  CGPoint outsidePoints[4] = {92    CGPointMake(CGRectGetMinX(targetBounds) - 1, midY),93    CGPointMake(CGRectGetMaxX(targetBounds) + 1, midY),94    CGPointMake(midX, CGRectGetMinY(targetBounds) - 1),95    CGPointMake(midX, CGRectGetMaxY(targetBounds) + 1)96  };97  for (NSInteger i = 0; i < 4; i++) {98    [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Grey Box")]99        performAction:grey_longPressAtPointWithDuration(outsidePoints[i], 1.0)];100    [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"single long press")]101        assertWithMatcher:grey_nil()];102  }103  // Verify that tapping inside the bounds causes the long press.104  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Grey Box")]105      performAction:grey_longPressAtPointWithDuration(CGPointMake(midX, midX), 1.0)];106  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"single long press")]107      assertWithMatcher:grey_sufficientlyVisible()];108}109- (void)testSwipeWorksInAllDirectionsInPortraitMode {110  [self ftr_assertSwipeWorksInAllDirections];111}112- (void)testSwipeWorksInAllDirectionsInUpsideDownMode {113  [EarlGrey rotateDeviceToOrientation:UIDeviceOrientationPortraitUpsideDown errorOrNil:nil];114  [self ftr_assertSwipeWorksInAllDirections];115}116- (void)testSwipeWorksInAllDirectionsInLandscapeLeftMode {117  [EarlGrey rotateDeviceToOrientation:UIDeviceOrientationLandscapeLeft errorOrNil:nil];118  [self ftr_assertSwipeWorksInAllDirections];119}...GestureTest.m
Source:GestureTest.m  
...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)];74  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"single long press")]75      assertWithMatcher:grey_sufficientlyVisible()];76}77- (void)testLongPressWithDurationAtPoint {78  EDORemoteVariable<NSValue *> *remoteBounds = [[EDORemoteVariable alloc] init];79  id<GREYAction> boundsFinder =80      [GREYHostApplicationDistantObject.sharedInstance actionForFindingElementBounds:remoteBounds];81  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Grey Box")]82      performAction:boundsFinder];83  CGRect targetBounds = remoteBounds.object.CGRectValue;84  // Verify tapping outside the bounds does not cause long press.85  CGFloat midX = CGRectGetMidX(targetBounds);86  CGFloat midY = CGRectGetMidY(targetBounds);87  CGPoint outsidePoints[4] = {CGPointMake(CGRectGetMinX(targetBounds) - 1, midY),88                              CGPointMake(CGRectGetMaxX(targetBounds) + 1, midY),89                              CGPointMake(midX, CGRectGetMinY(targetBounds) - 1),90                              CGPointMake(midX, CGRectGetMaxY(targetBounds) + 1)};91  for (NSInteger i = 0; i < 4; i++) {92    [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Grey Box")]93        performAction:grey_longPressAtPointWithDuration(outsidePoints[i], 1.0)];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), 1.0)];100  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"single long press")]101      assertWithMatcher:grey_sufficientlyVisible()];102}103- (void)testSwipeWorksInAllDirectionsInPortraitMode {104  [self ftr_assertSwipeWorksInAllDirections];105}106- (void)testSwipeWorksInAllDirectionsInUpsideDownMode {107  [EarlGrey rotateDeviceToOrientation:UIDeviceOrientationPortraitUpsideDown error:nil];108  [self ftr_assertSwipeWorksInAllDirections];109}110- (void)testSwipeWorksInAllDirectionsInLandscapeLeftMode {111  [EarlGrey rotateDeviceToOrientation:UIDeviceOrientationLandscapeLeft error:nil];112  [self ftr_assertSwipeWorksInAllDirections];113}...UITableViewTest.m
Source:UITableViewTest.m  
...26}27- (void)testContextMenuInteractionsWithATableView {28  // TODO(b/169197992): Add a drag action test with press and drag action.29  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Row 5")]30      performAction:grey_longPress()];31  XCTAssertTrue([self waitForVisibilityForText:@"Some"]);32  [[EarlGrey selectElementWithMatcher:grey_text(@"Some")] performAction:grey_tap()];33  XCTAssertTrue([self waitForVisibilityForText:@"Row 6"]);34  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Row 6")]35      performAction:grey_longPress()];36  XCTAssertTrue([self waitForVisibilityForText:@"Some"]);37  [[EarlGrey selectElementWithMatcher:grey_text(@"Some")] performAction:grey_tap()];38  XCTAssertTrue([self waitForVisibilityForText:@"Row 7"]);39  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Row 7")]40      assertWithMatcher:grey_not(grey_selected())];41}42- (void)testRemoveRow {43  id<GREYMatcher> deleteRowMatcher =44      grey_allOf(grey_accessibilityLabel(@"Delete"), grey_kindOfClass([UIButton class]), nil);45  for (int i = 0; i < 5; i++) {46    NSString *labelForRowToDelete = [NSString stringWithFormat:@"Row %d", i];47    [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(labelForRowToDelete)]48        performAction:grey_swipeSlowInDirection(kGREYDirectionLeft)];49    [[EarlGrey selectElementWithMatcher:deleteRowMatcher] performAction:grey_tap()];...GSCXTouchActivitySourceTests.m
Source:GSCXTouchActivitySourceTests.m  
...96/**97 * Performs a touch on the application's key window.98 */99- (void)gscxtest_performTouchOnApp {100  [[EarlGrey selectElementWithMatcher:grey_keyWindow()] performAction:grey_longPress()];101}102/**103 * Performs a touch on the application's key window for a given duration.104 *105 * @param duration The number of seconds the touch should last.106 */107- (void)gscxtest_performTouchOnAppWithDuration:(CFTimeInterval)duration {108  [[EarlGrey selectElementWithMatcher:grey_keyWindow()]109      performAction:grey_longPressWithDuration(duration)];110}111@end...grey_longPress
Using AI Code Generation
1[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"buttonID")]2    .usingSearchAction(grey_scrollInDirection(kGREYDirectionDown, 100), grey_tap())3    .atIndex(0)4    .performAction(grey_longPressWithDuration(1.0));5+ (id<GREYAction>)grey_longPressWithDuration:(CFTimeInterval)duration;6+ (id<GREYAction>)grey_longPressWithDuration:(CFTimeInterval)duration {7  return [[GREYLongPressAction alloc] initWithDuration:duration];8}9- (instancetype)initWithDuration:(CFTimeInterval)duration NS_DESIGNATED_INITIALIZER;10@implementation GREYLongPressAction {11  CFTimeInterval _duration;12}13- (instancetype)initWithDuration:(CFTimeInterval)duration {14  NSString *name = [NSString stringWithFormat:@"Long Press for %g seconds", duration];15                 constraints:grey_not(grey_systemAlertViewShown())];16  if (self) {17    _duration = duration;18  }19  return self;20}21- (BOOL)perform:(id)element error:(__strong NSError **)error {22  if (![element isKindOfClass:[UIView class]]) {23    NSString *reason = [NSString stringWithFormat:@"Cannot long press on a non-view element"];24    GREYPopulateErrorNotedOrLog(error, kGREYInteractionErrorDomain, kGREYInteractionElementNotVisibleErrorCode, reason);25    return NO;26  }27  UIView *view = (UIView *)element;28  CGPoint center = [view grey_centerOfVisibleArea];29                                       error:error];30}31+ (BOOL)longPressAtPoint:(CGPoint)point32                 forTime:(CFTimeInterval)duration33                   error:(__strong NSError **)errorgrey_longPress
Using AI Code Generation
1[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Test")];2[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Test")] performAction:grey_longPress()];3[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Test")] performAction:grey_longPressAtPoint(CGPointMake(0.5, 0.5))];4[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Test")] performAction:grey_longPressWithDuration(3.0)];5[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Test")] performAction:grey_longPressWithDuration(3.0) atPoint:CGPointMake(0.5, 0.5)];6[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Test")];7[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Test")] performAction:grey_longPress()];8[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Test")] performAction:grey_longPressAtPoint(CGPointMake(0.5, 0.5))];9[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Test")] performAction:grey_longPressWithDuration(3.0)];10[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Test")] performAction:grey_longPressWithDuration(3.0) atPoint:CGPointMake(0.5, 0.5)];11[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Test")];12[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Test")] performAction:grey_longPress()];13[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Test")] performAction:grey_longPressAtPoint(CGPointMake(0.5, 0.5))];14[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Test")] performAction:grey_longPressWithDuration(3.0)];15[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Test")] performAction:grey_longPress
Using AI Code Generation
1[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"text_field")]2        performAction:grey_longPressWithDuration(4.0)];3[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"text_field")]4        performAction:grey_longPress()];5[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"text_field")]6        performAction:grey_longPressWithDuration(4.0)];7[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"text_field")]8        performAction:grey_longPress()];9[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"text_field")]10        performAction:grey_longPressWithDuration(4.0)];11[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"text_field")]12        performAction:grey_longPress()];13[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"text_field")]14        performAction:grey_longPressWithDuration(4.0)];15[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"text_field")]16        performAction:grey_longPress()];17[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"text_field")]18        performAction:grey_longPressWithDuration(4.0)];19[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"text_field")]20        performAction:grey_longPress()];21[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"text_field")]22        performAction:grey_longPressWithDuration(4.0)];23[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"text_field")]24        performAction:grey_longPress()];grey_longPress
Using AI Code Generation
1#import "GREYActions.h"2[[EarlGrey selectElementWithMatcher:grey_keyWindow()]3    performAction:grey_longPressWithDuration(1.0)];4+ (id<GREYAction>)grey_longPressWithDuration:(CFTimeInterval)duration;5+ (id<GREYAction>)grey_longPressWithDuration:(CFTimeInterval)duration;6+ (id<GREYAction>)grey_longPressWithDuration:(CFTimeInterval)duration;7+ (id<GREYAction>)grey_longPressWithDuration:(CFTimeInterval)duration;8+ (id<GREYAction>)grey_longPressWithDuration:(CFTimeInterval)duration;9+ (id<GREYAction>)grey_longPressWithDuration:(CFTimeInterval)duration;10+ (id<GREYAction>)grey_longPressWithDuration:(CFTimeInterval)duration;11+ (id<GREYAction>)grey_longPressWithDuration:(CFTimeInterval)duration;12+ (id<GREYAction>)grey_longPressWithDuration:(CFTimeInterval)duration;13+ (id<GREYAction>)grey_longPressWithDuration:(CFTimeInterval)duration;14+ (id<GREYAction>)grey_longPressWithDuration:(CFTimeInterval)duration;15+ (idLearn 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!!
