Best EarlGrey code snippet using performAction.grey_clearText
KeyboardKeysTest.m
Source:KeyboardKeysTest.m  
...78      assertWithMatcher:grey_text(@"TFoohis string is a little too long for this text field!")];79}80- (void)testTypingAfterTappingOnTextField {81  [[[[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]82      performAction:grey_tap()] performAction:grey_typeText(@"foo")] performAction:grey_clearText()]83      assertWithMatcher:grey_text(@"")];84}85- (void)testClearAfterTyping {86  [[[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]87      performAction:grey_typeText(@"Foo")] performAction:grey_clearText()]88      assertWithMatcher:grey_text(@"")];89}90- (void)testClearAfterClearing {91  [[[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]92      performAction:grey_clearText()] performAction:grey_clearText()]93      assertWithMatcher:grey_text(@"")];94}95- (void)testClearAndType_TypeShort {96  [[[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]97      performAction:grey_clearText()] performAction:grey_typeText(@"Foo")]98      assertWithMatcher:grey_text(@"Foo")];99}100- (void)testTypeAfterClearing_ClearThenType {101  [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]102      performAction:grey_typeText(@"f")] assertWithMatcher:grey_text(@"f")];103  [[[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]104      performAction:grey_clearText()] performAction:grey_typeText(@"g")]105      assertWithMatcher:grey_text(@"g")];106}107- (void)testTypeAfterClearing_TypeLong {108  [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]109      performAction:grey_typeText(@"This is a long string")]110      assertWithMatcher:grey_text(@"This is a long string")];111  [[[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]112      performAction:grey_clearText()] performAction:grey_typeText(@"short string")]113      assertWithMatcher:grey_text(@"short string")];114}115- (void)testNonTypistKeyboardInteraction {116  [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]117      performAction:grey_tap()];118  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"a")] performAction:grey_tap()];119  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"b")] performAction:grey_tap()];120  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"c")] performAction:grey_tap()];121  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"return")] performAction:grey_tap()];122}123- (void)testNonTypingTextField {124  [NSThread mainThread].threadDictionary[GREYFailureHandlerKey] = [[FailureHandler alloc] init];125  @try {126    [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"NonTypingTextField")]127        performAction:grey_typeText(@"Should Fail")];128    GREYFail(@"Should throw an exception");129  } @catch (NSException *exception) {130    NSRange exceptionRange =131        [[exception reason] rangeOfString:@"Keyboard did not appear after tapping on an element."];132    GREYAssertTrue(exceptionRange.length > 0,133                   @"Should throw exception indicating keyboard did not appear.");134  }135}136- (void)testTypingWordsThatTriggerAutoCorrect {137  NSString *string = @"hekp";138  [self ftr_typeString:string andVerifyOutput:string];139  [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]140      performAction:grey_clearText()];141  [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextView")]142      performAction:grey_clearText()];143  string = @"helko";144  [self ftr_typeString:string andVerifyOutput:string];145  [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]146      performAction:grey_clearText()];147  [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextView")]148      performAction:grey_clearText()];149  string = @"balk";150  [self ftr_typeString:string andVerifyOutput:string];151  [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]152      performAction:grey_clearText()];153  [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextView")]154      performAction:grey_clearText()];155  string = @"surr";156  [self ftr_typeString:string andVerifyOutput:string];157}158- (void)testNumbersTyping {159  NSString *string = @"1234567890";160  [self ftr_typeString:string andVerifyOutput:string];161}162- (void)testSymbolsTyping {163  NSString *string = @"~!@#$%^&*()_+-={}:;<>?";164  [self ftr_typeString:string andVerifyOutput:string];165}166- (void)testLetterTyping {167  NSString *string = @"aBc";168  [self ftr_typeString:string andVerifyOutput:string];169}170- (void)testEmailTyping {171  NSString *string = @"donec.metus+spam@google.com";172  [self ftr_typeString:string andVerifyOutput:string];173}174- (void)testUpperCaseLettersTyping {175  NSString *string = @"VERYLONGTEXTWITHMANYLETTERS";176  [self ftr_typeString:string andVerifyOutput:string];177}178- (void)testNumbersAndSpacesTyping {179  NSString *string = @"0 1 2 3 4 5 6 7 8 9";180  [self ftr_typeString:string andVerifyOutput:string];181}182- (void)testSymbolsAndSpacesTyping {183  NSString *string = @"[ ] # + = _ < > { }";184  [self ftr_typeString:string andVerifyOutput:string];185}186- (void)testSymbolsAndNumbersWithSpacesTyping {187  NSString *string = @": A $ 1 = a 0 ^ 8 ;";188  [self ftr_typeString:string andVerifyOutput:string];189}190- (void)testSpaceKey {191  NSString *string = @"a b";192  [self ftr_typeString:string andVerifyOutput:string];193}194- (void)testBackspaceKey {195  NSString *string = @"ab\b";196  NSString *verificationString = @"a";197  [self ftr_typeString:string andVerifyOutput:verificationString];198}199- (void)testReturnKey {200  NSString *kbViewClassName = @"UIKeyboardImpl";201  NSString *textFieldString = @"and\n";202  [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]203      performAction:grey_typeText(textFieldString)] assertWithMatcher:grey_text(@"and")];204  [[EarlGrey selectElementWithMatcher:grey_kindOfClassName(kbViewClassName)]205      assertWithMatcher:grey_nil()];206  NSString *string = @"and\nand";207  [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextView")]208      performAction:grey_typeText(string)] assertWithMatcher:grey_text(@"and\nand")];209  [[EarlGrey selectElementWithMatcher:grey_kindOfClassName(kbViewClassName)]210      assertWithMatcher:grey_notNil()];211}212- (void)testAllReturnKeyTypes {213  NSString *kbViewClassName = @"UIKeyboardImpl";214  // There are 11 returnKeyTypes; test all of them.215  for (int i = 0; i < 11; i++) {216    [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]217        performAction:grey_typeText(@"a\n")] assertWithMatcher:grey_text(@"a")];218    [[EarlGrey selectElementWithMatcher:grey_kindOfClassName(kbViewClassName)]219        assertWithMatcher:grey_nil()];220    [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]221        performAction:grey_typeText(@"*\n")] assertWithMatcher:grey_text(@"a*")];222    [[EarlGrey selectElementWithMatcher:grey_kindOfClassName(kbViewClassName)]223        assertWithMatcher:grey_nil()];224    [[EarlGrey selectElementWithMatcher:grey_buttonTitle(@"next returnKeyType")]225        performAction:grey_tap()];226  }227}228- (void)testPanelNavigation {229  NSString *string = @"a1a%a%1%";230  [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]231      performAction:grey_typeText(string)];232}233- (void)testKeyplaneIsDetectedCorrectlyWhenSwitchingTextFields {234  NSString *string = @"$";235  [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]236      performAction:grey_typeText(string)] assertWithMatcher:grey_text(string)];237  [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextView")]238      performAction:grey_typeText(string)] assertWithMatcher:grey_text(string)];239}240- (void)testUIKeyboardTypeDefault {241  [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"KeyboardPicker")]242      performAction:grey_setPickerColumnToValue(0, @"Default")];243  NSString *string = @":$a8. {T<b@CC";244  [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]245      performAction:grey_typeText(string)] assertWithMatcher:grey_text(string)];246}247- (void)testUIKeyboardTypeASCIICapable {248  [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"KeyboardPicker")]249      performAction:grey_setPickerColumnToValue(0, @"ASCIICapable")];250  NSString *string = @":$a8. {T<b@CC";251  [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]252      performAction:grey_typeText(string)] assertWithMatcher:grey_text(string)];253}254- (void)testUIKeyboardTypeNumbersAndPunctuation {255  [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"KeyboardPicker")]256      performAction:grey_setPickerColumnToValue(0, @"NumbersAndPunctuation")];257  NSString *string = @":$a8. {T<b@CC";258  [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]259      performAction:grey_typeText(string)] assertWithMatcher:grey_text(string)];260}261- (void)testUIKeyboardTypeURL {262  [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"KeyboardPicker")]263      performAction:grey_setPickerColumnToValue(0, @"URL")];264  NSString *string = @"http://www.google.com/@*s$&T+t?[]#testLabel%foo;";265  [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]266      performAction:grey_typeText(string)] assertWithMatcher:grey_text(string)];267}268- (void)testUIKeyboardTypeNumberPad {269  [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"KeyboardPicker")]270      performAction:grey_setPickerColumnToValue(0, @"NumberPad")];271  NSString *string = @"\b0123456\b789\b\b";272  NSString *verificationString = @"0123457";273  [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]274      performAction:grey_typeText(string)] assertWithMatcher:grey_text(verificationString)];275}276- (void)testUIKeyboardTypePhonePad {277  [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"KeyboardPicker")]278      performAction:grey_setPickerColumnToValue(0, @"PhonePad")];279  NSString *string = @"01*23\b\b+45#67,89;";280  NSString *verificationString = @"01*+45#67,89;";281  [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]282      performAction:grey_typeText(string)] assertWithMatcher:grey_text(verificationString)];283}284- (void)testUIKeyboardTypeEmailAddress {285  [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"KeyboardPicker")]286      performAction:grey_setPickerColumnToValue(0, @"EmailAddress")];287  NSString *string = @"l0rem.ipsum+42@google.com#$_T*-";288  [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]289      performAction:grey_typeText(string)] assertWithMatcher:grey_text(string)];290}291- (void)testUIKeyboardTypeDecimalPad {292  [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"KeyboardPicker")]293      performAction:grey_setPickerColumnToValue(0, @"DecimalPad")];294  NSString *string = @"\b0123.456\b78..9\b\b";295  NSString *verificationString = @"0123.4578.";296  [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]297      performAction:grey_typeText(string)] assertWithMatcher:grey_text(verificationString)];298}299- (void)testUIKeyboardTypeTwitter {300  [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"KeyboardPicker")]301      performAction:grey_setPickerColumnToValue(0, @"Twitter")];302  NSString *string = @"@earlgrey Your framework is #awesome!!!1$:,eG%g\n";303  NSString *verificationString = @"@earlgrey Your framework is #awesome!!!1$:,eG%g";304  [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]305      performAction:grey_typeText(string)] assertWithMatcher:grey_text(verificationString)];306}307- (void)testUIKeyboardTypeWebSearch {308  [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"KeyboardPicker")]309      performAction:grey_setPickerColumnToValue(0, @"WebSearch")];310  NSString *string = @":$a8. {T<b@CC";311  [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]312      performAction:grey_typeText(string)] assertWithMatcher:grey_text(string)];313}314- (void)testTypingOnLandscapeLeft {315  [EarlGrey rotateDeviceToOrientation:UIDeviceOrientationLandscapeLeft error:nil];316  [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]317      performAction:grey_typeText(@"Cat")] assertWithMatcher:grey_text(@"Cat")];318}319- (void)testTypingOnLandscapeRight {320  [EarlGrey rotateDeviceToOrientation:UIDeviceOrientationLandscapeRight error:nil];321  [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]322      performAction:grey_typeText(@"Cat")] assertWithMatcher:grey_text(@"Cat")];323}324- (void)testSuccessivelyTypingInTheSameTextField {325  [[[[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]326      performAction:grey_typeText(@"This ")] performAction:grey_typeText(@"Is A ")]327      performAction:grey_typeText(@"Test")] assertWithMatcher:grey_text(@"This Is A Test")];328}329- (void)testTypingBlankString {330  NSString *string = @"       ";331  [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]332      performAction:grey_typeText(string)] assertWithMatcher:grey_text(string)];333}334- (void)testClearAfterTypingInCustomTextView {335  [[[[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomTextView")]336      performAction:grey_typeText(@"Foo")] assertWithMatcher:grey_accessibilityLabel(@"Foo")]337      performAction:grey_clearText()] assertWithMatcher:grey_accessibilityLabel(@"")];338}339- (void)testClearAfterClearingInCustomTextView {340  [[[[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomTextView")]341      performAction:grey_clearText()] assertWithMatcher:grey_accessibilityLabel(@"")]342      performAction:grey_clearText()] assertWithMatcher:grey_accessibilityLabel(@"")];343}344- (void)testTypeAfterClearingInCustomTextView {345  [[[[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomTextView")]346      performAction:grey_clearText()] assertWithMatcher:grey_accessibilityLabel(@"")]347      performAction:grey_typeText(@"Foo")] assertWithMatcher:grey_accessibilityLabel(@"Foo")];348}349- (void)testKeyplaneChangeInCustomTextView {350  [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomTextView")]351      performAction:grey_typeText(@"AAAAA")];352  [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomTextView")]353      performAction:grey_typeText(@"\b")];354  // Keyplane should change to uppercase keyplane with backspace.355  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Q")]356      assertWithMatcher:grey_sufficientlyVisible()];357}358- (void)testKeyplaneChangeInTextField {359  [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]360      performAction:grey_typeText(@"AAAAA")];361  // Keyplane should change to lowercase keyplane when capital letter typed.362  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"q")]363      assertWithMatcher:grey_sufficientlyVisible()];364  [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]365      performAction:grey_typeText(@"\b")];366  // Check if backspace changes the keyboard to lowercase keyplane.367  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"q")]368      assertWithMatcher:grey_sufficientlyVisible()];369}370- (void)testTypingOnTextFieldInUIInputAccessory {371  [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Input Button")]372      performAction:grey_tap()];373  [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"InputAccessoryTextField")]374      performAction:grey_typeText(@"Test")] assertWithMatcher:grey_text(@"Test")];375}376- (void)testMatchingFailsWithUIAccessibilityTextFieldElement {377  if (iOS13()) {378    id<GREYMatcher> elementMatcher =379        grey_allOf(grey_accessibilityValue(@"Text Field"),380                   grey_kindOfClassName(kTextFieldAXElementClassName), nil);381    [[EarlGrey selectElementWithMatcher:elementMatcher] assertWithMatcher:grey_notNil()];382    NSError *error;383    [[EarlGrey selectElementWithMatcher:elementMatcher] performAction:grey_clearText()384                                                                error:&error];385    XCTAssertNil(error, @"Typing on a UIAccessibilityElement has an error: %@", error);386    [[EarlGrey selectElementWithMatcher:elementMatcher] performAction:grey_typeText(@"a")];387  }388}389- (void)testClearAndReplaceWorksWithUIAccessibilityTextFieldElement {390  XCTSkipIf(iOS14_OR_ABOVE());391  id<GREYMatcher> elementMatcher =392      grey_allOf(grey_accessibilityValue(@"Text Field"),393                 grey_kindOfClassName(kTextFieldAXElementClassName), nil);394  if (iOS13_OR_ABOVE()) {395    [[EarlGrey selectElementWithMatcher:elementMatcher] assertWithMatcher:grey_notNil()];396    NSError *error;397    [[EarlGrey selectElementWithMatcher:elementMatcher] performAction:grey_clearText()398                                                                error:&error];399    XCTAssertNil(error, @"Typing on a UIAccessibilityElement has an error: %@", error);400    [[EarlGrey selectElementWithMatcher:elementMatcher] performAction:grey_typeText(@"a")];401  } else {402    [[[EarlGrey selectElementWithMatcher:elementMatcher] performAction:grey_clearText()]403        performAction:grey_replaceText(@"foo")];404    // Ensure the element exists by tapping on it. This also removes the cursor.405    [[EarlGrey selectElementWithMatcher:grey_textFieldValue(@"foo")] performAction:grey_tap()];406  }407}408- (void)testTypingAndResigningOfFirstResponder {409  GREYAssertFalse([GREYKeyboard keyboardShownWithError:nil], @"Keyboard shouldn't be shown");410  [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]411      performAction:grey_typeText(@"Foo")] assertWithMatcher:grey_text(@"Foo")];412  GREYAssertTrue([GREYKeyboard keyboardShownWithError:nil], @"Keyboard shouldn't be shown");413  XCTAssertTrue([EarlGrey dismissKeyboardWithError:nil]);414  GREYAssertFalse([GREYKeyboard keyboardShownWithError:nil],415                  @"Keyboard shouldn't be shown as it is resigned");416  [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]417      performAction:grey_typeText(@"Foo")] assertWithMatcher:grey_text(@"FooFoo")];418  GREYAssertTrue([GREYKeyboard keyboardShownWithError:nil], @"Keyboard shouldn't be shown");419}420- (void)testTogglingShiftByChangingCase {421  NSString *multiCaseString = @"aA1a1A1aA1AaAa1A1a";422  for (NSUInteger i = 0; i < multiCaseString.length; i++) {423    NSString *currentCharacter = [multiCaseString substringWithRange:NSMakeRange(i, 1)];424    [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]425        performAction:grey_typeText(currentCharacter)]426        assertWithMatcher:grey_text([multiCaseString substringToIndex:i + 1])];427    id keyboardClass = GREY_REMOTE_CLASS_IN_APP(GREYKeyboard);428    for (NSString *axLabel in [[keyboardClass returnByValue] shiftKeyIdentifyingCharacters]) {429      NSError *error;430      [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(axLabel)] performAction:grey_tap()431                                                                                    error:&error];432    }433  }434  [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]435      assertWithMatcher:grey_text(multiCaseString)];436}437- (void)testIsKeyboardShownWithCustomKeyboardTracker {438  GREYAssertFalse([GREYKeyboard keyboardShownWithError:nil], @"Keyboard shouldn't be shown");439  GREYHostApplicationDistantObject *host = GREYHostApplicationDistantObject.sharedInstance;440  [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomKeyboardTracker")]441      performAction:host.actionForSetFirstResponder];442  GREYAssertFalse([GREYKeyboard keyboardShownWithError:nil], @"Keyboard shouldn't be shown");443}444/**445 *  Verifies error details for dismissing a keyboard when the keyboard is not present.446 */447- (void)testTypingAndResigningWithError {448  GREYAssertFalse([GREYKeyboard keyboardShownWithError:nil], @"Keyboard shouldn't be shown");449  GREYHostApplicationDistantObject *host = GREYHostApplicationDistantObject.sharedInstance;450  NSError *error;451  XCTAssertFalse([EarlGrey dismissKeyboardWithError:&error]);452  NSString *localizedErrorDescription = [error localizedDescription];453  NSString *reason = @"Failed to dismiss keyboard:";454  GREYAssertTrue([localizedErrorDescription containsString:reason],455                 @"Unexpected error message for initial dismiss: %@, Original error: %@",456                 localizedErrorDescription, error);457  [[EarlGrey selectElementWithMatcher:grey_keyWindow()]458      performAction:host.actionForSetFirstResponder459              error:&error];460  XCTAssertFalse([EarlGrey dismissKeyboardWithError:&error]);461  localizedErrorDescription = [error localizedDescription];462  GREYAssertTrue([localizedErrorDescription containsString:reason],463                 @"Unexpected error message for second dismiss: %@, Original error: %@",464                 localizedErrorDescription, error);465}466- (void)testDismissingKeyboardWhenReturnIsNotPresent {467  [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"KeyboardPicker")]468      performAction:grey_setPickerColumnToValue(0, @"PhonePad")];469  [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]470      performAction:grey_tap()];471  XCTAssertTrue([EarlGrey dismissKeyboardWithError:nil]);472}473- (void)testDismissingKeyboardWhenReturnIsPresentButDoesNotDismissTheKeyboard {474  [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomTextView")]475      performAction:grey_tap()];476  NSError *error;477  XCTAssertTrue([EarlGrey dismissKeyboardWithError:&error]);478  XCTAssertNil(error);479  GREYAssertFalse([GREYKeyboard keyboardShownWithError:nil], @"Keyboard shouldn't be shown");480}481- (void)testTextViewDidChangeCalled {482  [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextView")]483      performAction:grey_typeText(@"Check Delegate")]484      assertWithMatcher:grey_text(@"textViewDidChange Called")];485  [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextView")]486      performAction:grey_replaceText(@"Check Delegate")]487      assertWithMatcher:grey_text(@"textViewDidChange Called")];488}489- (void)testReplaceTextTypingForAnEmoji {490  NSString *emoji = @"ð";491  [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]492      performAction:grey_replaceText(emoji)] assertWithMatcher:grey_text(emoji)];493  [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextView")]494      performAction:grey_replaceText(emoji)] assertWithMatcher:grey_text(emoji)];495}496/**497 * Ensures that EarlGrey doesn't wait any longer after a typing action for the keyboard's Caret498 * animation to be be tracked.499 */500- (void)testCaretBlinkingAnimationNotTracked {501  [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]502      performAction:grey_typeText(@"Foo")];503  GREYConfiguration *config = [GREYConfiguration sharedConfiguration];504  [config setValue:@(3) forConfigKey:kGREYConfigKeyInteractionTimeoutDuration];505  NSError *error;506  [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]507      performAction:grey_clearText()508              error:&error];509  XCTAssertFalse([error.description containsString:@"UITextSelectionViewCaretBlinkAnimation"],510                 @"Caret blinking animation should not be present");511}512#pragma mark - Private513- (void)ftr_typeString:(NSString *)string andVerifyOutput:(NSString *)verificationString {514  [[[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]515      performAction:grey_typeText(string)] performAction:grey_typeText(@"\n")]516      assertWithMatcher:grey_text(verificationString)];517  [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextView")]518      performAction:grey_typeText(string)] assertWithMatcher:grey_text(verificationString)];519  [[EarlGrey selectElementWithMatcher:grey_buttonTitle(@"Done")] performAction:grey_tap()];520}521@end...FTRKeyboardKeysTest.m
Source:FTRKeyboardKeysTest.m  
...115- (void)testTypingWordsThatTriggerAutoCorrect {116  NSString *string = @"hekp";117  [self typeString:string andVerifyOutput:string];118  [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]119      performAction:grey_clearText()];120  [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextView")]121      performAction:grey_clearText()];122  string = @"helko";123  [self typeString:string andVerifyOutput:string];124  [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]125      performAction:grey_clearText()];126  [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextView")]127      performAction:grey_clearText()];128  string = @"balk";129  [self typeString:string andVerifyOutput:string];130  [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]131      performAction:grey_clearText()];132  [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextView")]133      performAction:grey_clearText()];134  string = @"surr";135  [self typeString:string andVerifyOutput:string];136}137- (void)testNumbersTyping {138  NSString *string = @"1234567890";139  [self typeString:string andVerifyOutput:string];140}141- (void)testSymbolsTyping {142  NSString *string = @"~!@#$%^&*()_+-={}:;<>?";143  [self typeString:string andVerifyOutput:string];144}145- (void)testLetterTyping {146  NSString *string = @"aBc";147  [self typeString:string andVerifyOutput:string];...FTRLocalUIWebViewTest.m
Source:FTRLocalUIWebViewTest.m  
...69      performAction:grey_tap()];70  id<GREYMatcher> searchButtonMatcher = grey_accessibilityHint(@"Search");71  [self waitForWebElementWithName:@"Search Button" elementMatcher:searchButtonMatcher];72  [[[EarlGrey selectElementWithMatcher:searchButtonMatcher]73      performAction:grey_clearText()]74      performAction:grey_typeText(@"20 + 22\n")];75  [self waitForWebElementWithName:@"Search Button" elementMatcher:grey_accessibilityLabel(@"42")];76  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"42")]77      assertWithMatcher:grey_sufficientlyVisible()];78  // We need to tap because the second time we do typeAfterClearning, it passes firstResponder check79  // and never ends up auto-tapping on search field.80  [[EarlGrey selectElementWithMatcher:searchButtonMatcher]81      performAction:grey_tap()];82  [[[EarlGrey selectElementWithMatcher:searchButtonMatcher]83      performAction:grey_clearText()]84      performAction:grey_typeText(@"Who wrote Star Wars IV - A New Hope?\n")];85  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Google Search")]86      performAction:grey_tap()];87  id<GREYMatcher> resultMatcher = grey_allOf(grey_accessibilityLabel(@"George Lucas"),88                                             grey_accessibilityTrait(UIAccessibilityTraitHeader),89                                             nil);90  [self waitForWebElementWithName:@"Search Result" elementMatcher:resultMatcher];91  [[EarlGrey selectElementWithMatcher:resultMatcher] assertWithMatcher:grey_sufficientlyVisible()];92}93- (void)testJavaScriptExecution {94  [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"loadGoogle")]95      performAction:grey_tap()];96  id<GREYAction> jsAction =97      grey_javaScriptExecution(@"window.location.href='http://images.google.com'", nil);...CreateAccountPage.m
Source:CreateAccountPage.m  
...15static NSString *const password = @"RMBAutomationProfileTextFieldPassword";16static NSString *const createAccountButton = @"RMBAutomationProfileButtonSubmit";17static NSString *const birthDateField = @"RMBAutomationProfileDropdownDateOfBirth";18- (StarRewardsPage *) createAccountForUser: (User *) user {19    [[EarlGrey selectElementWithMatcher:grey_accessibilityID(nameField)] performAction:grey_clearText()];20    [[EarlGrey selectElementWithMatcher:grey_accessibilityID(nameField)] performAction:grey_typeText(user.name)];21    [[EarlGrey selectElementWithMatcher:grey_accessibilityID(surnameField)] performAction:grey_clearText()];22    [[EarlGrey selectElementWithMatcher:grey_accessibilityID(surnameField)] performAction:grey_typeText(user.surname)];23    [[EarlGrey selectElementWithMatcher:grey_accessibilityID(emailField)] performAction:grey_clearText()];24    [[EarlGrey selectElementWithMatcher:grey_accessibilityID(emailField)] performAction:grey_typeText(user.email)];25    [[EarlGrey selectElementWithMatcher:grey_accessibilityID(password)] performAction:grey_clearText()];26    [[EarlGrey selectElementWithMatcher:grey_accessibilityID(password)] performAction:grey_typeText(user.password)];27    [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"RMBAutomationKeyboardControlsDone")] performAction:grey_tap()];28    [[EarlGrey selectElementWithMatcher:grey_accessibilityID(birthDateField)] performAction:grey_tap()];29    30    XCUIApplication *application = [[XCUIApplication alloc] init];31    [[application.pickerWheels elementBoundByIndex:0] adjustToPickerWheelValue:@"March"];32    [[application.pickerWheels elementBoundByIndex:1] adjustToPickerWheelValue:@"4"];33    [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"RMBAutomationKeyboardControlsDone")] performAction:grey_tap()];34    35    [application swipeUp];36    [[EarlGrey selectElementWithMatcher:grey_accessibilityID(createAccountButton)] performAction:grey_tap()];37    return [[StarRewardsPage alloc] init];38}39@end...SignInPage.m
Source:SignInPage.m  
...20    [[EarlGrey selectElementWithMatcher:grey_accessibilityID(createAccountButton)] performAction:grey_tap()];21    return [[CreateAccountPage alloc] init];22}23- (void) logInWithEmail: (NSString *) email password:(NSString *) password {24    [[EarlGrey selectElementWithMatcher:grey_accessibilityID(emailField)] performAction:grey_clearText()];25    [[EarlGrey selectElementWithMatcher:grey_accessibilityID(emailField)] performAction:grey_typeText(email)];26    [[EarlGrey selectElementWithMatcher:grey_accessibilityID(passwordField)] performAction:grey_typeText(password)];27    [self clickOnSignInButton];28}29@end...grey_clearText
Using AI Code Generation
1[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"username")] performAction:grey_clearText()];2[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"username")] performAction:grey_typeText(@"abc")];3GREYPerformActionBlock *grey_clearText = ^BOOL (id element, NSError *__strong *errorOrNil) {4    if ([element isKindOfClass:[UITextField class]]) {5        UITextField *textField = (UITextField *)element;6        textField.text = @"";7        return YES;8    }9    return NO;10};11GREYPerformActionBlock *grey_typeText = ^BOOL (id element, NSError *__strong *errorOrNil) {12    if ([element isKindOfClass:[UITextField class]]) {13        UITextField *textField = (UITextField *)element;14        textField.text = @"abc";15        return YES;16    }17    return NO;18};19GREYPerformActionBlock *grey_clearText = ^BOOL (id element, NSError *__strong *errorOrNil) {20    if ([element isKindOfClass:[UITextField class]]) {21        UITextField *textField = (UITextField *)element;22        textField.text = @"";23        return YES;24    }25    return NO;26};27GREYPerformActionBlock *grey_typeText = ^BOOL (id element, NSError *__strong *errorOrNil) {28    if ([element isKindOfClass:[UITextField class]]) {29        UITextField *textField = (UITextField *)element;30        textField.text = @"abc";31        return YES;32    }33    return NO;34};35@property (strong, nonatomic) IBOutlet UITextField *usernameTextFieldgrey_clearText
Using AI Code Generation
1#import <Foundation/Foundation.h>2#import <XCTest/XCTest.h>3- (void)setUp {4    [super setUp];5    self.continueAfterFailure = NO;6    [[[XCUIApplication alloc] init] launch];7}8- (void)tearDown {9    [super tearDown];10}11- (void)testExample {grey_clearText
Using AI Code Generation
1[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"username")] performAction:grey_clearText()];2[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"username")] performAction:grey_replaceText(@"username")];3[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"username")] performAction:grey_typeText(@"username")];4[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"username")] performAction:grey_scrollInDirection(kGREYDirectionDown, 10)];5[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"username")] performAction:grey_tap()];6[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"username")] performAction:grey_doubleTap()];7[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"username")] performAction:grey_longPress()];8[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"username")] performAction:grey_pinchFastInDirection(kGREYDirectionDown, 10)];9[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"username")] performAction:grey_pinchSlowInDirection(kGREYDirectionDown, 10)];10[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"username")] performAction:grey_rotateDeviceToOrientation(kGREYOrientationLandscapeLeft)];grey_clearText
Using AI Code Generation
1#import "GREYBaseAction.h"2#import "GREYActions.h"3#import "GREYAction.h"4#import "GREYElementInteraction.h"5#import "GREYMatchers.h"6#import "EarlGrey.h"7#import "GREYAllOf.h"8#import "GREYConfiguration.h"9#import "GREYConfiguration.h"10#import "GREYTestHelper.h"11#import "GREYAppleInternals.h"12#import "GREYHostBackgroundDistantObject+GREYApp.h"13#import "GREYHostBackgroundDistantObject+GREYTestHelper.h"14#import "GREYHostBackgroundDistantObject+GREYUI.h"15#import "GREYHostBackgroundDistantObject+Private.h"16#import "GREYHostBackgroundDistantObject.h"17#import "GREYHostBackgroundDistantObject+GREYKeyboard.h"18#import "GREYHostBackgroundDistantObject+GREYVisibilityChecker.h"19#import "GREYHostBackgroundDistantObject+GREYInteraction.h"20#import "GREYHostBackgroundDistantObject+GREYElement.h"21#import "GREYHostBackgroundDistantObject+GREYVisibilityChecker.h"22#import "GREYHostBackgroundDistantObject+GREYKeyboard.h"23#import "GREYHostBackgroundDistantObject+GREYInteraction.h"24#import "GREYHostBackgroundDistantObject+GREYElement.h"25#import "GREYHostBackgroundDistantObject+GREYApp.h"26#import "GREYHostBackgroundDistantObject+GREYTestHelper.h"27#import "GREYHostBackgroundDistantObject+GREYUI.h"28#import "GREYHostBackgroundDistantObject+Private.h"29#import "GREYHostBackgroundDistantObject.h"30#import "GREYHostBackgroundDistantObject+GREYKeyboard.h"31#import "GREYHostBackgroundDistantObject+GREYVisibilityChecker.h"32#import "GREYHostBackgroundDistantObject+GREYInteraction.h"33#import "GREYHostBackgroundDistantObject+GREYElement.h"34#import "GREYHostBackgroundDistantObject+GREYVisibilityChecker.h"35#import "GREYHostBackgroundDistantObject+GREYKeyboard.h"36#import "GREYHostBackgroundDistantObject+GREYInteraction.h"37#import "GREYHostBackgroundDistantObject+GREYElement.h"38#import "GREYHostBackgroundDistantObject+GREYApp.h"39#import "GREYHostBackgroundLearn 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!!
