Best EarlGrey code snippet using performAction
KeyboardKeysTest.m
Source:KeyboardKeysTest.m
...44 [super tearDown];45}46- (void)testTypingAtBeginning {47 [[[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]48 performAction:grey_typeText(@"Foo")] performAction:[GREYActions actionForTypeText:@"Bar"49 atPosition:0]]50 assertWithMatcher:grey_text(@"BarFoo")];51}52- (void)testKeyboardIsShown {53 XCTAssertFalse([EarlGrey isKeyboardShownWithError:nil],54 @"Keyboard is not shown when there is no first responder");55 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]56 performAction:grey_tap()];57 XCTAssertTrue([EarlGrey isKeyboardShownWithError:nil],58 @"Keyboard is shown when there is a first responder");59}60- (void)testTypingAtEnd {61 [[[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]62 performAction:grey_typeText(@"Foo")] performAction:[GREYActions actionForTypeText:@"Bar"63 atPosition:-1]]64 assertWithMatcher:grey_text(@"FooBar")];65}66- (void)testTypingInMiddle {67 [[[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]68 performAction:grey_typeText(@"Foo")] performAction:[GREYActions actionForTypeText:@"Bar"69 atPosition:2]]70 assertWithMatcher:grey_text(@"FoBaro")];71}72- (void)testTypingInMiddleOfBigString {73 id<GREYAction> typeLongTextAction =74 grey_typeText(@"This string is a little too long for this text field!");75 [[[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]76 performAction:typeLongTextAction] performAction:[GREYActions actionForTypeText:@"Foo"77 atPosition:1]]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
...26 [self openTestViewNamed:@"Typing Views"];27}28- (void)testTypingAtBeginning {29 [[[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]30 performAction:[GREYActions actionForTypeText:@"Foo"]]31 performAction:[self ftr_actionForTypingText:@"Bar" atPosition:0]]32 assertWithMatcher:grey_text(@"BarFoo")];33}34- (void)testTypingAtEnd {35 [[[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]36 performAction:[GREYActions actionForTypeText:@"Foo"]]37 performAction:[self ftr_actionForTypingText:@"Bar" atPosition:-1]]38 assertWithMatcher:grey_text(@"FooBar")];39}40- (void)testTypingInMiddle {41 [[[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]42 performAction:[GREYActions actionForTypeText:@"Foo"]]43 performAction:[self ftr_actionForTypingText:@"Bar" atPosition:2]]44 assertWithMatcher:grey_text(@"FoBaro")];45}46- (void)testTypingInMiddleOfBigString {47 [[[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]48 performAction:49 [GREYActions actionForTypeText:@"This string is a little too long for this text field!"]]50 performAction:[self ftr_actionForTypingText:@"Foo" atPosition:1]]51 assertWithMatcher:grey_text(@"TFoohis string is a little too long for this text field!")];52}53- (void)testTypingAfterTappingOnTextField {54 [[[[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]55 performAction:[GREYActions actionForTap]]56 performAction:[GREYActions actionForTypeText:@"foo"]]57 performAction:[GREYActions actionForClearText]]58 assertWithMatcher:grey_text(@"")];59}60- (void)testClearAfterTyping {61 [[[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]62 performAction:[GREYActions actionForTypeText:@"Foo"]]63 performAction:[GREYActions actionForClearText]]64 assertWithMatcher:grey_text(@"")];65}66- (void)testClearAfterClearing {67 [[[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]68 performAction:[GREYActions actionForClearText]]69 performAction:[GREYActions actionForClearText]]70 assertWithMatcher:grey_text(@"")];71}72- (void)testClearAndType_TypeShort {73 [[[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]74 performAction:[GREYActions actionForClearText]]75 performAction:[GREYActions actionForTypeText:@"Foo"]]76 assertWithMatcher:grey_text(@"Foo")];77}78- (void)testTypeAfterClearing_ClearThenType {79 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]80 performAction:[GREYActions actionForTypeText:@"f"]]81 assertWithMatcher:grey_text(@"f")];82 [[[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]83 performAction:[GREYActions actionForClearText]]84 performAction:[GREYActions actionForTypeText:@"g"]]85 assertWithMatcher:grey_text(@"g")];86}87- (void)testTypeAfterClearing_TypeLong {88 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]89 performAction:[GREYActions actionForTypeText:@"This is a long string"]]90 assertWithMatcher:grey_text(@"This is a long string")];91 [[[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]92 performAction:[GREYActions actionForClearText]]93 performAction:[GREYActions actionForTypeText:@"short string"]]94 assertWithMatcher:grey_text(@"short string")];95}96- (void)testNonTypistKeyboardInteraction {97 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]98 performAction:[GREYActions actionForTap]];99 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"a")]100 performAction:[GREYActions actionForTap]];101 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"b")]102 performAction:[GREYActions actionForTap]];103 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"c")]104 performAction:[GREYActions actionForTap]];105 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"return")]106 performAction:[GREYActions actionForTap]];107}108- (void)testNonTypingTextField {109 [EarlGrey setFailureHandler:[[FTRFailureHandler alloc] init]];110 @try {111 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"NonTypingTextField")]112 performAction:[GREYActions actionForTypeText:@"Should Fail"]];113 GREYFail(@"Should throw an exception");114 } @catch (NSException *exception) {115 NSRange exceptionRange =116 [[exception reason] rangeOfString:@"\"Action Name\": \"Type 'Should Fail'\""];117 GREYAssertTrue(exceptionRange.length > 0, @"Should throw exception indicating action failure.");118 }119}120- (void)testTypingWordsThatTriggerAutoCorrect {121 NSString *string = @"hekp";122 [self ftr_typeString:string andVerifyOutput:string];123 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]124 performAction:grey_clearText()];125 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextView")]126 performAction:grey_clearText()];127 string = @"helko";128 [self ftr_typeString:string andVerifyOutput:string];129 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]130 performAction:grey_clearText()];131 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextView")]132 performAction:grey_clearText()];133 string = @"balk";134 [self ftr_typeString:string andVerifyOutput:string];135 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]136 performAction:grey_clearText()];137 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextView")]138 performAction:grey_clearText()];139 string = @"surr";140 [self ftr_typeString:string andVerifyOutput:string];141}142- (void)testNumbersTyping {143 NSString *string = @"1234567890";144 [self ftr_typeString:string andVerifyOutput:string];145}146- (void)testSymbolsTyping {147 NSString *string = @"~!@#$%^&*()_+-={}:;<>?";148 [self ftr_typeString:string andVerifyOutput:string];149}150- (void)testLetterTyping {151 NSString *string = @"aBc";152 [self ftr_typeString:string andVerifyOutput:string];153}154- (void)testEmailTyping {155 NSString *string = @"donec.metus+spam@google.com";156 [self ftr_typeString:string andVerifyOutput:string];157}158- (void)testUpperCaseLettersTyping {159 NSString *string = @"VERYLONGTEXTWITHMANYLETTERS";160 [self ftr_typeString:string andVerifyOutput:string];161}162- (void)testNumbersAndSpacesTyping {163 NSString *string = @"0 1 2 3 4 5 6 7 8 9";164 [self ftr_typeString:string andVerifyOutput:string];165}166- (void)testSymbolsAndSpacesTyping {167 NSString *string = @"[ ] # + = _ < > { }";168 [self ftr_typeString:string andVerifyOutput:string];169}170- (void)testSpaceKey {171 NSString *string = @"a b";172 [self ftr_typeString:string andVerifyOutput:string];173}174- (void)testBackspaceKey {175 NSString *string = @"ab\b";176 NSString *verificationString = @"a";177 [self ftr_typeString:string andVerifyOutput:verificationString];178}179- (void)testReturnKey {180 Class kbViewClass = NSClassFromString(@"UIKeyboardImpl");181 NSString *textFieldString = @"and\n";182 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]183 performAction:grey_typeText(textFieldString)]184 assertWithMatcher:grey_text(@"and")];185 [[EarlGrey selectElementWithMatcher:grey_kindOfClass(kbViewClass)] assertWithMatcher:grey_nil()];186 NSString *string = @"and\nand";187 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextView")]188 performAction:grey_typeText(string)]189 assertWithMatcher:grey_text(@"and\nand")];190 [[EarlGrey selectElementWithMatcher:grey_kindOfClass(kbViewClass)]191 assertWithMatcher:grey_notNil()];192}193- (void)testAllReturnKeyTypes {194 Class kbViewClass = NSClassFromString(@"UIKeyboardImpl");195 // There are 11 returnKeyTypes; test all of them.196 for (int i = 0; i < 11; i++) {197 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]198 performAction:grey_typeText(@"a\n")]199 assertWithMatcher:grey_text(@"a")];200 [[EarlGrey selectElementWithMatcher:grey_kindOfClass(kbViewClass)]201 assertWithMatcher:grey_nil()];202 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]203 performAction:grey_typeText(@"*\n")]204 assertWithMatcher:grey_text(@"a*")];205 [[EarlGrey selectElementWithMatcher:grey_kindOfClass(kbViewClass)]206 assertWithMatcher:grey_nil()];207 [[EarlGrey selectElementWithMatcher:grey_buttonTitle(@"next returnKeyType")]208 performAction:grey_tap()];209 }210}211- (void)testPanelNavigation {212 NSString *string = @"a1a%a%1%";213 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]214 performAction:grey_typeText(string)];215}216- (void)testKeyplaneIsDetectedCorrectlyWhenSwitchingTextFields {217 NSString *string = @"$";218 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]219 performAction:grey_typeText(string)]220 assertWithMatcher:grey_text(string)];221 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextView")]222 performAction:grey_typeText(string)]223 assertWithMatcher:grey_text(string)];224}225- (void)testUIKeyboardTypeDefault {226 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"KeyboardPicker")]227 performAction:[GREYActions actionForSetPickerColumn:0 toValue:@"Default"]];228 NSString *string = @":$a8. {T<b@CC";229 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]230 performAction:grey_typeText(string)]231 assertWithMatcher:grey_text(string)];232}233- (void)testUIKeyboardTypeASCIICapable {234 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"KeyboardPicker")]235 performAction:[GREYActions actionForSetPickerColumn:0 toValue:@"ASCIICapable"]];236 NSString *string = @":$a8. {T<b@CC";237 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]238 performAction:grey_typeText(string)]239 assertWithMatcher:grey_text(string)];240}241- (void)testUIKeyboardTypeNumbersAndPunctuation {242 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"KeyboardPicker")]243 performAction:[GREYActions actionForSetPickerColumn:0 toValue:@"NumbersAndPunctuation"]];244 NSString *string = @":$a8. {T<b@CC";245 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]246 performAction:grey_typeText(string)]247 assertWithMatcher:grey_text(string)];248}249- (void)testUIKeyboardTypeURL {250 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"KeyboardPicker")]251 performAction:[GREYActions actionForSetPickerColumn:0 toValue:@"URL"]];252 NSString *string = @"http://www.google.com/@*s$&T+t?[]#testLabel%foo;";253 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]254 performAction:grey_typeText(string)]255 assertWithMatcher:grey_text(string)];256}257- (void)testUIKeyboardTypeNumberPad {258 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"KeyboardPicker")]259 performAction:[GREYActions actionForSetPickerColumn:0 toValue:@"NumberPad"]];260 NSString *string = @"\b0123456\b789\b\b";261 NSString *verificationString = @"0123457";262 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]263 performAction:grey_typeText(string)]264 assertWithMatcher:grey_text(verificationString)];265}266- (void)testUIKeyboardTypePhonePad {267 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"KeyboardPicker")]268 performAction:[GREYActions actionForSetPickerColumn:0 toValue:@"PhonePad"]];269 NSString *string = @"01*23\b\b+45#67,89;";270 NSString *verificationString = @"01*+45#67,89;";271 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]272 performAction:grey_typeText(string)]273 assertWithMatcher:grey_text(verificationString)];274}275- (void)testUIKeyboardTypeEmailAddress {276 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"KeyboardPicker")]277 performAction:[GREYActions actionForSetPickerColumn:0 toValue:@"EmailAddress"]];278 NSString *string = @"l0rem.ipsum+42@google.com#$_T*-";279 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]280 performAction:grey_typeText(string)]281 assertWithMatcher:grey_text(string)];282}283- (void)testUIKeyboardTypeDecimalPad {284 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"KeyboardPicker")]285 performAction:[GREYActions actionForSetPickerColumn:0 toValue:@"DecimalPad"]];286 NSString *string = @"\b0123.456\b78..9\b\b";287 NSString *verificationString = @"0123.4578.";288 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]289 performAction:grey_typeText(string)]290 assertWithMatcher:grey_text(verificationString)];291}292- (void)testUIKeyboardTypeTwitter {293 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"KeyboardPicker")]294 performAction:[GREYActions actionForSetPickerColumn:0 toValue:@"Twitter"]];295 NSString *string = @"@earlgrey Your framework is #awesome!!!1$:,eG%g\n";296 NSString *verificationString = @"@earlgrey Your framework is #awesome!!!1$:,eG%g";297 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]298 performAction:grey_typeText(string)]299 assertWithMatcher:grey_text(verificationString)];300}301- (void)testUIKeyboardTypeWebSearch {302 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"KeyboardPicker")]303 performAction:[GREYActions actionForSetPickerColumn:0 toValue:@"WebSearch"]];304 NSString *string = @":$a8. {T<b@CC";305 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]306 performAction:grey_typeText(string)]307 assertWithMatcher:grey_text(string)];308}309- (void)testTypingOnLandscapeLeft {310 [EarlGrey rotateDeviceToOrientation:UIDeviceOrientationLandscapeLeft errorOrNil:nil];311 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]312 performAction:grey_typeText(@"Cat")]313 assertWithMatcher:grey_text(@"Cat")];314}315- (void)testTypingOnLandscapeRight {316 [EarlGrey rotateDeviceToOrientation:UIDeviceOrientationLandscapeRight errorOrNil:nil];317 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]318 performAction:grey_typeText(@"Cat")]319 assertWithMatcher:grey_text(@"Cat")];320}321- (void)testTogglingShiftByChangingCase {322 NSString *multiCaseString = @"aA1a1A1aA1AaAa1A1a";323 id<GREYAction> action =324 [GREYActionBlock actionWithName:@"ToggleShift"325 performBlock:^(id element, __strong NSError **errorOrNil) {326 NSArray *shiftAXLabels =327 @[ @"shift", @"Shift", @"SHIFT", @"more, symbols", @"more, numbers", @"more", @"MORE" ];328 for (NSString *axLabel in shiftAXLabels) {329 NSError *error;330 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(axLabel)]331 performAction:grey_tap()332 error:&error];333 }334 return YES;335 }];336 for (NSUInteger i = 0; i < multiCaseString.length; i++) {337 NSString *currentCharacter = [multiCaseString substringWithRange:NSMakeRange(i, 1)];338 [[[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]339 performAction:grey_typeText(currentCharacter)]340 performAction:action]341 assertWithMatcher:grey_text([multiCaseString substringToIndex:i + 1])];342 }343 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]344 assertWithMatcher:grey_text(multiCaseString)];345}346- (void)testSuccessivelyTypingInTheSameTextField {347 [[[[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]348 performAction:grey_typeText(@"This ")]349 performAction:grey_typeText(@"Is A ")]350 performAction:grey_typeText(@"Test")]351 assertWithMatcher:grey_text(@"This Is A Test")];352}353- (void)testTypingBlankString {354 NSString *string = @" ";355 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]356 performAction:grey_typeText(string)]357 assertWithMatcher:grey_text(string)];358}359- (void)testClearAfterTypingInCustomTextView {360 [[[[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomTextView")]361 performAction:[GREYActions actionForTypeText:@"Foo"]]362 assertWithMatcher:grey_accessibilityLabel(@"Foo")]363 performAction:[GREYActions actionForClearText]]364 assertWithMatcher:grey_accessibilityLabel(@"")];365}366- (void)testClearAfterClearingInCustomTextView {367 [[[[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomTextView")]368 performAction:[GREYActions actionForClearText]]369 assertWithMatcher:grey_accessibilityLabel(@"")]370 performAction:[GREYActions actionForClearText]]371 assertWithMatcher:grey_accessibilityLabel(@"")];372}373- (void)testTypeAfterClearingInCustomTextView {374 [[[[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomTextView")]375 performAction:[GREYActions actionForClearText]]376 assertWithMatcher:grey_accessibilityLabel(@"")]377 performAction:[GREYActions actionForTypeText:@"Foo"]]378 assertWithMatcher:grey_accessibilityLabel(@"Foo")];379}380- (void)testTypingOnTextFieldInUIInputAccessory {381 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Input Button")]382 performAction:grey_tap()];383 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"InputAccessoryTextField")]384 performAction:grey_typeText(@"Test")] assertWithMatcher:grey_text(@"Test")];385}386- (void)testClearAndReplaceWorksWithUIAccessibilityTextFieldElement {387 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Input Button")]388 performAction:grey_tap()];389 Class accessibilityTextFieldElemClass = NSClassFromString(@"UIAccessibilityTextFieldElement");390 id<GREYMatcher> elementMatcher = grey_allOf(grey_accessibilityValue(@"Text Field"),391 grey_kindOfClass(accessibilityTextFieldElemClass),392 nil);393 [[[EarlGrey selectElementWithMatcher:elementMatcher]394 performAction:grey_clearText()]395 performAction:grey_replaceText(@"foo")];396 [[EarlGrey selectElementWithMatcher:grey_textFieldValue(@"foo")]397 assertWithMatcher:grey_text(@"foo")];398}399- (void)testIsKeyboardShownWithCustomKeyboardTracker {400 GREYActionBlock *setResponderBlock =401 [GREYActionBlock actionWithName:@"Set First Responder"402 performBlock:^BOOL(id element, NSError *__strong *errorOrNil) {403 return [element becomeFirstResponder];404 }];405 GREYAssertFalse([GREYKeyboard isKeyboardShown], @"Keyboard Shouldn't be Shown");406 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomKeyboardTracker")]407 performAction:setResponderBlock];408 GREYAssertFalse([GREYKeyboard isKeyboardShown], @"Keyboard Shouldn't be Shown");409}410- (void)testTypingAndResigningOfFirstResponder {411 GREYAssertFalse([GREYKeyboard isKeyboardShown], @"Keyboard Shouldn't be Shown");412 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]413 performAction:[GREYActions actionForTypeText:@"Foo"]]414 assertWithMatcher:grey_text(@"Foo")];415 GREYAssertTrue([GREYKeyboard isKeyboardShown], @"Keyboard Shouldn't be Shown");416 [EarlGrey dismissKeyboardWithError:nil];417 GREYAssertFalse([GREYKeyboard isKeyboardShown], @"Keyboard Shouldn't be Shown as it is resigned");418 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]419 performAction:[GREYActions actionForTypeText:@"Foo"]]420 assertWithMatcher:grey_text(@"FooFoo")];421 GREYAssertTrue([GREYKeyboard isKeyboardShown], @"Keyboard Shouldn't be Shown");422}423- (void)testTypingAndResigningWithError {424 GREYAssertFalse([GREYKeyboard isKeyboardShown], @"Keyboard Shouldn't be Shown");425 GREYActionBlock *setResponderBlock =426 [GREYActionBlock actionWithName:@"Set First Responder"427 performBlock:^BOOL(id element, NSError *__strong *errorOrNil) {428 [element becomeFirstResponder];429 return YES;430 }];431 NSError *error;432 [EarlGrey dismissKeyboardWithError:&error];433 NSString *localizedErrorDescription = [error localizedDescription];434 GREYAssertEqualObjects(localizedErrorDescription,435 @"Failed to dismiss keyboard since it was not showing.",436 @"Unexpected error message for initial dismiss: %@, original error: %@",437 localizedErrorDescription, error);438 [[EarlGrey selectElementWithMatcher:grey_keyWindow()] performAction:setResponderBlock];439 [EarlGrey dismissKeyboardWithError:&error];440 localizedErrorDescription = [error localizedDescription];441 GREYAssertEqualObjects(localizedErrorDescription,442 @"Failed to dismiss keyboard since it was not showing.",443 @"Unexpected error message for second dismiss: %@, original error: %@",444 localizedErrorDescription, error);445}446#pragma mark - Private447- (void)ftr_typeString:(NSString *)string andVerifyOutput:(NSString *)verificationString {448 [[[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]449 performAction:grey_typeText(string)]450 performAction:grey_typeText(@"\n")]451 assertWithMatcher:grey_text(verificationString)];452 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextView")]453 performAction:grey_typeText(string)]454 assertWithMatcher:grey_text(verificationString)];455 [[EarlGrey selectElementWithMatcher:grey_buttonTitle(@"Done")]456 performAction:grey_tap()];457}458// Helper action that converts numeric position to UITextPosition.459- (id<GREYAction>)ftr_actionForTypingText:(NSString *)text atPosition:(NSInteger)position {460 NSString *actionName =461 [NSString stringWithFormat:@"Test type \"%@\" at position %ld", text, (long)position];462 return [GREYActionBlock actionWithName:actionName463 constraints:grey_conformsToProtocol(@protocol(UITextInput))464 performBlock:^BOOL (id element, __strong NSError **errorOrNil) {465 UITextPosition *textPosition;466 if (position >= 0) {467 textPosition = [element positionFromPosition:[element beginningOfDocument] offset:position];468 if (!textPosition) {469 // Text position will be nil if the computed text position is greater than the length470 // of the backing string or less than zero. Since position is positive, the computed value...
FTRBasicInteractionTest.m
Source:FTRBasicInteractionTest.m
...25- (void)testEarlGreyInvocationInsideGREYConditionUsingWaitWithLargeTimeout {26 GREYCondition *condition = [GREYCondition conditionWithName:@"conditionWithAction" block:^BOOL {27 static double stepperValue = 51;28 [[EarlGrey selectElementWithMatcher:grey_kindOfClass([UIStepper class])]29 performAction:[GREYActions actionForSetStepperValue:++stepperValue]];30 return stepperValue == 55;31 }];32 [condition waitWithTimeout:10.0];33 [[EarlGrey selectElementWithMatcher:grey_kindOfClass([UIStepper class])]34 assertWithMatcher:grey_stepperValue(55)];35}36- (void)testEarlGreyInvocationInsideGREYConditionUsingWaitWithTimeout {37 [[EarlGrey selectElementWithMatcher:[GREYMatchers matcherForText:@"Tab 2"]]38 performAction:[GREYActions actionForTap]];39 // Setup an action that grabs a label and returns its text40 __block NSString *text;41 id actionBlock = ^(UILabel *element, __strong NSError **errorOrNil) {42 text = element.text;43 return YES;44 };45 id<GREYAction> action = [GREYActionBlock actionWithName:@"GetSampleLabelText"46 performBlock:actionBlock];47 // Setup a condition to wait until a specific label says specific text.48 GREYCondition *waitCondition = [GREYCondition conditionWithName:@"WaitForLabelText"49 block:^BOOL() {50 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"sampleLabel")] performAction:action];51 return [text isEqualToString:@"OFF"];52 }];53 // Switch text and wait.54 [[EarlGrey selectElementWithMatcher:[GREYMatchers matcherForAccessibilityLabel:@"Switch"]]55 performAction:[GREYActions actionForTurnSwitchOn:NO]];56 [waitCondition waitWithTimeout:10.0];57}58- (void)testTapOnWindow {59 [[EarlGrey selectElementWithMatcher:grey_keyWindow()] performAction:[GREYActions actionForTap]];60 UITapGestureRecognizer *tapGestureRecognizer =61 [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(ftr_dismissWindow:)];62 tapGestureRecognizer.numberOfTapsRequired = 1;63 // Create a custom window that dismisses itself when tapped.64 UIWindow *topMostWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];65 [topMostWindow addGestureRecognizer:tapGestureRecognizer];66 topMostWindow.accessibilityIdentifier = @"TopMostWindow";67 topMostWindow.isAccessibilityElement = YES;68 [topMostWindow makeKeyAndVisible];69 // Tap on topmost window.70 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TopMostWindow")]71 performAction:grey_tap()];72 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TopMostWindow")]73 assertWithMatcher:grey_notVisible()];74}75- (void)testRootViewControllerSetMultipleTimesOnMainWindow {76 UIWindow *currentWindow = [[UIApplication sharedApplication].delegate window];77 UIViewController *originalVC = currentWindow.rootViewController;78 UIViewController *vc1 = [[UIViewController alloc] init];79 [currentWindow setRootViewController:vc1];80 [[EarlGrey selectElementWithMatcher:[GREYMatchers matcherForText:@"Tab 2"]]81 assertWithMatcher:grey_nil()];82 [currentWindow setRootViewController:nil];83 [[EarlGrey selectElementWithMatcher:[GREYMatchers matcherForText:@"Tab 2"]]84 assertWithMatcher:grey_nil()];85 [currentWindow setRootViewController:originalVC];86 [[EarlGrey selectElementWithMatcher:[GREYMatchers matcherForText:@"Tab 2"]]87 assertWithMatcher:grey_notNil()];88}89- (void)testRootViewControllerSetOnMultipleWindows {90 UIWindow *currentWindow = [[UIApplication sharedApplication].delegate window];91 UIViewController *originalVC = currentWindow.rootViewController;92 UIWindow *otherWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];93 [otherWindow setRootViewController:originalVC];94 [currentWindow setRootViewController:nil];95 [[EarlGrey selectElementWithMatcher:[GREYMatchers matcherForText:@"Tab 2"]]96 assertWithMatcher:grey_nil()];97 [otherWindow setRootViewController:nil];98 [currentWindow setRootViewController:originalVC];99 [[EarlGrey selectElementWithMatcher:[GREYMatchers matcherForText:@"Tab 2"]]100 assertWithMatcher:grey_notNil()];101}102- (void)testBasicInteractionWithViews {103 [[EarlGrey selectElementWithMatcher:[GREYMatchers matcherForText:@"Tab 2"]]104 performAction:[GREYActions actionForTap]];105 GREYElementInteraction *typeHere =106 [EarlGrey selectElementWithMatcher:grey_allOf(grey_accessibilityLabel(@"Type Something Here"),107 grey_kindOfClass([UITextField class]),108 nil)];109 [[typeHere performAction:[GREYActions actionForReplaceText:@"Hello 2"]]110 assertWithMatcher:grey_text(@"Hello 2")];111 [typeHere performAction:[GREYActions actionForClearText]];112 [[typeHere performAction:grey_tapAtPoint(CGPointMake(0, 0))]113 performAction:[GREYActions actionForTypeText:@"Hello!"]];114 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"return")]115 performAction:[GREYActions actionForTap]];116 [[EarlGrey selectElementWithMatcher:[GREYMatchers matcherForAccessibilityLabel:@"Send"]]117 performAction:grey_tapAtPoint(CGPointMake(5, 5))];118 [[EarlGrey selectElementWithMatcher:[GREYMatchers matcherForAccessibilityLabel:@"Simple Label"]]119 assertWithMatcher:grey_text(@"Hello!")];120 [[EarlGrey selectElementWithMatcher:[GREYMatchers matcherForAccessibilityLabel:@"Switch"]]121 performAction:[GREYActions actionForTurnSwitchOn:NO]];122 [[EarlGrey selectElementWithMatcher:[GREYMatchers matcherForAccessibilityLabel:@"Simple Label"]]123 assertWithMatcher:grey_text(@"OFF")];124 [[[EarlGrey selectElementWithMatcher:grey_text(@"Long Press")]125 performAction:[GREYActions actionForLongPressWithDuration:1.1f]]126 assertWithMatcher:[GREYMatchers matcherForNotVisible]];127 [[[EarlGrey selectElementWithMatcher:grey_text(@"Double Tap")]128 performAction:grey_doubleTap()]129 assertWithMatcher:[GREYMatchers matcherForNotVisible]];130}131- (void)testEarlGreyInvocationInsideCustomAction {132 [[EarlGrey selectElementWithMatcher:[GREYMatchers matcherForText:@"Tab 2"]]133 performAction:[GREYActionBlock actionWithName:@"PerformIfVisibleElseFail"134 performBlock:^(id element,135 __strong NSError **errorOrNil) {136 if (![element isHidden]) {137 [[EarlGrey selectElementWithMatcher:[GREYMatchers matcherForText:@"Tab 2"]]138 performAction:[GREYActions actionForTap]];139 [[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Long Press")]140 performAction:[GREYActions actionForLongPressWithDuration:1.1f]]141 assertWithMatcher:grey_nil()];142 } else {143 GREYFail(@"Element should exist. We should not be here.");144 return NO;145 }146 return YES;147 }]];148}149- (void)testEarlGreyInvocationInsideCustomAssertion {150 [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")]151 assert:[GREYAssertionBlock assertionWithName:@"ConditionalTapIfElementExists"152 assertionBlockWithError:^BOOL(id element,153 NSError *__strong *errorOrNil) {154 if (element) {155 [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] performAction:grey_tap()];156 [[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Long Press")]157 performAction:[GREYActions actionForLongPressWithDuration:1.1f]]158 assertWithMatcher:grey_nil()];159 } else {160 GREYFail(@"Element should exist. We should not be here.");161 }162 return YES;163 }]];164}165- (void)testLongPressOnAccessibilityElement {166 [[EarlGrey selectElementWithMatcher:[GREYMatchers matcherForText:@"Tab 2"]]167 performAction:[GREYActions actionForTap]];168 [[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Long Press")]169 performAction:[GREYActions actionForLongPressWithDuration:1.1f]]170 assertWithMatcher:grey_nil()];171}172- (void)testLongPressAtPointOnAccessibilityElement {173 [[EarlGrey selectElementWithMatcher:[GREYMatchers matcherForText:@"Tab 2"]]174 performAction:[GREYActions actionForTap]];175 [[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Long Press")]176 performAction:[GREYActions actionForLongPressAtPoint:CGPointMake(10, 10) duration:1.1f]]177 assertWithMatcher:grey_nil()];178}179- (void)DISABLED_testLongPressOnTextField {180 [[EarlGrey selectElementWithMatcher:[GREYMatchers matcherForText:@"Tab 2"]]181 performAction:[GREYActions actionForTap]];182 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"foo")]183 performAction:[GREYActions actionForLongPressWithDuration:1.0f]];184 [[EarlGrey selectElementWithMatcher:[GREYMatchers matcherForText:@"Tab 2"]]185 assertWithMatcher:grey_notNil()];186}187- (void)testLongPressFollowedBySelectingMenuOption {188 [[EarlGrey selectElementWithMatcher:[GREYMatchers matcherForText:@"Tab 2"]]189 performAction:[GREYActions actionForTap]];190 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"foo")]191 performAction:[GREYActions actionForTypeText:@"Hello"]];192 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"foo")]193 performAction:[GREYActions actionForLongPressAtPoint:CGPointMake(1, 1) duration:1.0]];194 [[EarlGrey selectElementWithMatcher:grey_text(@"Select")]195 performAction:[GREYActions actionForTap]];196 [[EarlGrey selectElementWithMatcher:grey_text(@"Cut")]197 performAction:[GREYActions actionForTap]];198 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"foo")]199 performAction:[GREYActions actionForTypeText:@"FromEarlGrey"]];200 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"foo")]201 performAction:[GREYActions actionForLongPressAtPoint:CGPointMake(1, 1) duration:1.0]];202 [[EarlGrey selectElementWithMatcher:grey_text(@"Paste")]203 performAction:[GREYActions actionForTap]];204 // Smart Inserts in Xcode 9 cause a space to appear by default after a paste. This attribute205 // is not available on Xcode 7 and therefore cannot be used to fix the test. Therefore, we206 // are changing the value based on the Xcode version.207 if (iOS11_OR_ABOVE()) {208 [[EarlGrey selectElementWithMatcher:grey_text(@"Hello FromEarlGrey")]209 assertWithMatcher:grey_sufficientlyVisible()];210 } else {211 [[EarlGrey selectElementWithMatcher:grey_text(@"HelloFromEarlGrey")]212 assertWithMatcher:grey_sufficientlyVisible()];213 }214}215- (void)testBasicInteractionWithStepper {216 [[EarlGrey selectElementWithMatcher:grey_kindOfClass([UIStepper class])]217 performAction:[GREYActions actionForSetStepperValue:87]];218 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Value Label")]219 assertWithMatcher:grey_text(@"Value: 87%")];220 [[[EarlGrey selectElementWithMatcher:grey_kindOfClass([UIStepper class])]221 performAction:[GREYActions actionForSetStepperValue:16]]222 assertWithMatcher:grey_stepperValue(16)];223}224- (void)testInteractionWithUISwitch {225 [[EarlGrey selectElementWithMatcher:[GREYMatchers matcherForText:@"Tab 2"]]226 performAction:[GREYActions actionForTap]];227 [[[EarlGrey selectElementWithMatcher:[GREYMatchers matcherForAccessibilityLabel:@"Switch"]]228 performAction:[GREYActions actionForTurnSwitchOn:NO]]229 assertWithMatcher:grey_switchWithOnState(NO)];230 [[[EarlGrey selectElementWithMatcher:[GREYMatchers matcherForAccessibilityLabel:@"Switch"]]231 performAction:[GREYActions actionForTurnSwitchOn:YES]]232 assertWithMatcher:grey_switchWithOnState(YES)];233 [[[EarlGrey selectElementWithMatcher:[GREYMatchers matcherForAccessibilityLabel:@"Switch"]]234 performAction:[GREYActions actionForTurnSwitchOn:YES]]235 assertWithMatcher:grey_switchWithOnState(YES)];236 [[[EarlGrey selectElementWithMatcher:[GREYMatchers matcherForAccessibilityLabel:@"Switch"]]237 performAction:[GREYActions actionForTurnSwitchOn:NO]]238 assertWithMatcher:grey_switchWithOnState(NO)];239}240- (void)testInteractionWithHiddenLabel {241 [[EarlGrey selectElementWithMatcher:[GREYMatchers matcherForAccessibilityLabel:@"Hidden Label"]]242 assertWithMatcher:grey_text(@"Hidden Label")];243}244- (void)testInteractionWithLabelWithParentWithAlphaZero {245 [[EarlGrey selectElementWithMatcher:[GREYMatchers matcherForAccessibilityLabel:@"Long Press"]]246 assertWithMatcher:grey_not(grey_sufficientlyVisible())];247}248- (void)testInteractionWithLabelWithParentHiddenAndUnhidden {249 GREYActionBlock *hideTab2Block =250 [GREYActionBlock actionWithName:@"hideTab2"251 performBlock:^BOOL(id element, NSError *__strong *error) {252 UIView *superView = element;253 superView.hidden = YES;254 return YES;255 }];256 GREYActionBlock *unhideTab2Block =257 [GREYActionBlock actionWithName:@"unhideTab2"258 performBlock:^BOOL(id element, NSError *__strong *error) {259 UIView *superView = element;260 superView.hidden = NO;261 return YES;262 }];263 [[EarlGrey selectElementWithMatcher:[GREYMatchers matcherForText:@"Tab 2"]]264 performAction:[GREYActions actionForTap]];265 [[EarlGrey selectElementWithMatcher:[GREYMatchers matcherForAccessibilityLabel:@"tab2Container"]]266 performAction:hideTab2Block];267 [[EarlGrey selectElementWithMatcher:[GREYMatchers matcherForAccessibilityLabel:@"Long Press"]]268 assertWithMatcher:grey_not(grey_sufficientlyVisible())];269 [[EarlGrey selectElementWithMatcher:[GREYMatchers matcherForAccessibilityLabel:@"tab2Container"]]270 performAction:unhideTab2Block];271 [[EarlGrey selectElementWithMatcher:[GREYMatchers matcherForAccessibilityLabel:@"Long Press"]]272 assertWithMatcher:grey_sufficientlyVisible()];273}274- (void)testInteractionWithLabelWithParentTranslucentAndOpaque {275 GREYActionBlock *makeTab2OpaqueBlock =276 [GREYActionBlock actionWithName:@"makeTab2Opaque"277 performBlock:^BOOL(id element, NSError *__strong *error) {278 UIView *superView = element;279 superView.alpha = 1;280 return YES;281 }];282 GREYActionBlock *makeTab2TranslucentBlock =283 [GREYActionBlock actionWithName:@"makeTab2Translucent"284 performBlock:^BOOL(id element, NSError *__strong *error) {285 UIView *superView = element;286 superView.alpha = 0;287 return YES;288 }];289 [[EarlGrey selectElementWithMatcher:[GREYMatchers matcherForText:@"Tab 2"]]290 performAction:[GREYActions actionForTap]];291 [[EarlGrey selectElementWithMatcher:[GREYMatchers matcherForAccessibilityLabel:@"tab2Container"]]292 performAction:makeTab2TranslucentBlock];293 [[EarlGrey selectElementWithMatcher:[GREYMatchers matcherForAccessibilityLabel:@"Long Press"]]294 assertWithMatcher:grey_not(grey_sufficientlyVisible())];295 [[EarlGrey selectElementWithMatcher:[GREYMatchers matcherForAccessibilityLabel:@"tab2Container"]]296 performAction:makeTab2OpaqueBlock];297 [[EarlGrey selectElementWithMatcher:[GREYMatchers matcherForAccessibilityLabel:@"Long Press"]]298 assertWithMatcher:grey_sufficientlyVisible()];299}300/**301 * No test is provided for the key window since changing its hidden value will302 * cause other tests to fail since the keyWindow is modified.303 */304- (void)testInteractionWithLabelWithWindowTranslucentAndOpaque {305 GREYActionBlock *makeWindowOpaqueBlock =306 [GREYActionBlock actionWithName:@"unhideTab2"307 performBlock:^BOOL(id element, NSError *__strong *error) {308 UIView *view = element;309 UIWindow *window = view.window;310 window.alpha = 1;311 return YES;312 }];313 GREYActionBlock *makeWindowTranslucentBlock =314 [GREYActionBlock actionWithName:@"hideTab2"315 performBlock:^BOOL(id element, NSError *__strong *error) {316 UIView *view = element;317 UIWindow *window = view.window;318 window.alpha = 0;319 return YES;320 }];321 [[EarlGrey selectElementWithMatcher:[GREYMatchers matcherForText:@"Tab 2"]]322 performAction:[GREYActions actionForTap]];323 [[EarlGrey selectElementWithMatcher:[GREYMatchers matcherForAccessibilityLabel:@"tab2Container"]]324 performAction:makeWindowTranslucentBlock];325 [[EarlGrey selectElementWithMatcher:[GREYMatchers matcherForAccessibilityLabel:@"Long Press"]]326 assertWithMatcher:grey_not(grey_sufficientlyVisible())];327 [[EarlGrey selectElementWithMatcher:[GREYMatchers matcherForAccessibilityLabel:@"tab2Container"]]328 performAction:makeWindowOpaqueBlock];329 [[EarlGrey selectElementWithMatcher:[GREYMatchers matcherForAccessibilityLabel:@"Long Press"]]330 assertWithMatcher:grey_sufficientlyVisible()];331}332- (void)testButtonSelectedState {333 [[EarlGrey selectElementWithMatcher:[GREYMatchers matcherForText:@"Tab 2"]]334 performAction:[GREYActions actionForTap]];335 id<GREYMatcher> buttonMatcher = grey_allOf(grey_kindOfClass([UIButton class]),336 grey_descendant(grey_accessibilityLabel(@"Send")),337 nil);338 [[EarlGrey selectElementWithMatcher:buttonMatcher] assertWithMatcher:grey_not(grey_selected())];339 [[EarlGrey selectElementWithMatcher:buttonMatcher] performAction:grey_tap()];340 [[EarlGrey selectElementWithMatcher:buttonMatcher] assertWithMatcher:grey_selected()];341}342- (void)testTappingOnADisabledButton {343 NSError *error;344 [[EarlGrey selectElementWithMatcher:grey_buttonTitle(@"Disabled")]345 performAction:grey_tap()346 error:&error];347 XCTAssertEqualObjects(error.domain, kGREYInteractionErrorDomain);348 XCTAssertEqual(error.code, kGREYInteractionConstraintsFailedErrorCode);349}350#pragma mark - Private351- (void)ftr_dismissWindow:(UITapGestureRecognizer *)sender {352 [sender.view setHidden:YES];353}354@end...
FTRPickerViewInteractionTest.m
Source:FTRPickerViewInteractionTest.m
...22 [super setUp];23 [self openTestViewNamed:@"Picker Views"];24}25- (void)testInteractionIsImpossibleIfInteractionDisabled {26 [[EarlGrey selectElementWithMatcher:grey_text(@"Disabled")] performAction:grey_tap()];27 NSError *error;28 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"InteractionDisabledPickerId")]29 performAction:[GREYActions actionForSetPickerColumn:0 toValue:@"Green"]30 error:&error];31 GREYAssertTrue(error.domain == kGREYInteractionErrorDomain, @"Error domain should match");32 GREYAssertTrue(error.code == kGREYInteractionConstraintsFailedErrorCode,33 @"Error code should match");34 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"InteractionDisabledPickerId")]35 assertWithMatcher:grey_pickerColumnSetToValue(0, @"Red")];36}37- (void)testDateOnlyPicker {38 NSString *dateString = @"1986/12/26";39 NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];40 dateFormatter.dateFormat = @"YYYY/MM/dd";41 NSDate *desiredDate = [dateFormatter dateFromString:dateString];42 [[EarlGrey selectElementWithMatcher:grey_text(@"Date")] performAction:grey_tap()];43 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"DatePickerId")]44 performAction:[GREYActions actionForSetDate:desiredDate]];45 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"DatePickerId")]46 assertWithMatcher:grey_datePickerValue(desiredDate)];47 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"DateLabelId")]48 assertWithMatcher:grey_text(dateString)];49}50- (void)testDateUpdateCallbackIsNotInvokedIfDateDoesNotChange {51 NSString *dateString = @"1986/12/26";52 NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];53 dateFormatter.dateFormat = @"YYYY/MM/dd";54 NSDate *desiredDate = [dateFormatter dateFromString:dateString];55 [[EarlGrey selectElementWithMatcher:grey_text(@"Date")] performAction:grey_tap()];56 // Changing the date must change the label.57 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"DatePickerId")]58 performAction:[GREYActions actionForSetDate:desiredDate]];59 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"DatePickerId")]60 assertWithMatcher:grey_datePickerValue(desiredDate)];61 // Clearing the label to revert the changes.62 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"ClearDateLabelButtonId")]63 performAction:grey_tap()];64 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"DateLabelId")]65 assertWithMatcher:grey_text(@"")];66 // Executing the change date action with the same value should not change the value, thus not67 // invoking the update callback.68 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"DatePickerId")]69 performAction:[GREYActions actionForSetDate:desiredDate]];70 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"DateLabelId")]71 assertWithMatcher:grey_text(@"")];72}73- (void)testTimeOnlyPicker {74 NSString *timeString = @"19:30:00";75 NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];76 dateFormatter.dateFormat = @"HH:mm:ss";77 NSDate *desiredTime = [dateFormatter dateFromString:timeString];78 [[EarlGrey selectElementWithMatcher:grey_text(@"Time")] performAction:grey_tap()];79 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"DatePickerId")]80 performAction:grey_setDate(desiredTime)];81 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"DatePickerId")]82 assertWithMatcher:grey_datePickerValue(desiredTime)];83}84- (void)testDateTimePicker {85 NSString *dateTimeString = @"1986/12/26 19:30:00";86 NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];87 dateFormatter.dateFormat = @"YYYY/MM/dd HH:mm:ss";88 NSDate *desiredDateTime = [dateFormatter dateFromString:dateTimeString];89 [[EarlGrey selectElementWithMatcher:grey_text(@"DateTime")] performAction:grey_tap()];90 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"DatePickerId")]91 performAction:grey_setDate(desiredDateTime)];92 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"DatePickerId")]93 assertWithMatcher:grey_datePickerValue(desiredDateTime)];94}95- (void)testCountdownTimePicker {96 NSString *timerString = @"12:30:00";97 NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];98 dateFormatter.dateFormat = @"HH:mm:ss";99 NSDate *desiredTimer = [dateFormatter dateFromString:timerString];100 [[EarlGrey selectElementWithMatcher:grey_text(@"Counter")] performAction:grey_tap()];101 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"DatePickerId")]102 performAction:grey_setDate(desiredTimer)];103 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"DatePickerId")]104 assertWithMatcher:grey_datePickerValue(desiredTimer)];105}106- (void)testCustomPicker {107 [[EarlGrey selectElementWithMatcher:grey_text(@"Custom")] performAction:grey_tap()];108 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]109 performAction:[GREYActions actionForSetPickerColumn:0 toValue:@"Blue"]];110 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]111 performAction:[GREYActions actionForSetPickerColumn:1 toValue:@"5"]];112 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]113 assertWithMatcher:grey_pickerColumnSetToValue(0, @"Blue")];114 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]115 assertWithMatcher:grey_pickerColumnSetToValue(1, @"5")];116}117- (void)testPickerViewDidSelectRowInComponentIsCalled {118 [[EarlGrey selectElementWithMatcher:grey_text(@"Custom")] performAction:grey_tap()];119 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]120 performAction:[GREYActions actionForSetPickerColumn:0 toValue:@"Hidden"]]121 assertWithMatcher:grey_notVisible()];122}123- (void)testNoPickerViewComponentDelegateMethodsAreDefined {124 [[EarlGrey selectElementWithMatcher:grey_text(@"Custom")] performAction:grey_tap()];125 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"noDelegateMethodDefinedSwitch")]126 performAction:grey_turnSwitchOn(YES)];127 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]128 assertWithMatcher:grey_pickerColumnSetToValue(0, nil)];129 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]130 assertWithMatcher:grey_pickerColumnSetToValue(1, nil)];131}132- (void)testViewForRowDefined {133 [[EarlGrey selectElementWithMatcher:grey_text(@"Custom")] performAction:grey_tap()];134 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"viewForRowDelegateSwitch")]135 performAction:grey_turnSwitchOn(YES)];136 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]137 performAction:grey_setPickerColumnToValue(0, @"Green")];138 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]139 performAction:grey_setPickerColumnToValue(1, @"4")];140 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]141 assertWithMatcher:grey_pickerColumnSetToValue(0, @"Green")];142 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]143 assertWithMatcher:grey_pickerColumnSetToValue(1, @"4")];144}145- (void)testAttributedTitleForRowDefined {146 [[EarlGrey selectElementWithMatcher:grey_text(@"Custom")] performAction:grey_tap()];147 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"attributedTitleForRowDelegateSwitch")]148 performAction:grey_turnSwitchOn(YES)];149 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]150 performAction:grey_setPickerColumnToValue(0, @"Green")];151 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]152 performAction:grey_setPickerColumnToValue(1, @"4")];153 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]154 assertWithMatcher:grey_pickerColumnSetToValue(0, @"Green")];155 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]156 assertWithMatcher:grey_pickerColumnSetToValue(1, @"4")];157}158- (void)testTitleForRowDefined {159 [[EarlGrey selectElementWithMatcher:grey_text(@"Custom")] performAction:grey_tap()];160 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"titleForRowDelegateSwitch")]161 performAction:grey_turnSwitchOn(YES)];162 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]163 performAction:grey_setPickerColumnToValue(0, @"Green")];164 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]165 performAction:grey_setPickerColumnToValue(1, @"4")];166 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]167 assertWithMatcher:grey_pickerColumnSetToValue(0, @"Green")];168 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]169 assertWithMatcher:grey_pickerColumnSetToValue(1, @"4")];170}171@end...
FTRLocalUIWebViewTest.m
Source:FTRLocalUIWebViewTest.m
...30 if (iOS11_OR_ABOVE()) {31 return;32 }33 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"loadGoogle")]34 performAction:grey_tap()];35 [self ftr_waitForWebElementWithName:@"NEWS" elementMatcher:grey_accessibilityLabel(@"NEWS")];36 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"NEWS")]37 performAction:grey_tap()];38 NSError *error;39 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"IMAGES")]40 performAction:grey_tap() error:&error];41 if (error) {42 // On some form factors, label is set to "Images" instead of "IMAGES".43 [[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Images")] atIndex:1]44 performAction:grey_tap()];45 }46 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"VIDEOS")]47 performAction:grey_tap()];48 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"ALL")]49 performAction:grey_tap()];50}51// Test disabled on Xcode 9 beta. http://www.openradar.me/3338317452- (void)testAJAXLoad {53 if (iOS11_OR_ABOVE()) {54 return;55 }56 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"loadGoogle")]57 performAction:grey_tap()];58 [self ftr_waitForWebElementWithName:@"ALL" elementMatcher:grey_accessibilityLabel(@"ALL")];59 // Clicking on "Next page" triggers AJAX loading.60 id<GREYMatcher> nextPageMatcher =61 grey_allOf(grey_accessibilityLabel(@"Next page"), grey_interactable(), nil);62 NSError *error;63 [[[EarlGrey selectElementWithMatcher:nextPageMatcher]64 usingSearchAction:grey_scrollInDirection(kGREYDirectionDown, 200)65 onElementWithMatcher:grey_kindOfClass([UIWebView class])]66 performAction:grey_tap() error:&error];67 if (error) {68 // On some form factors, label is set to "Next" instead of "Next page".69 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Next")]70 performAction:grey_tap()];71 }72 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"IMAGES")]73 assertWithMatcher:grey_sufficientlyVisible()];74}75// Test disabled on Xcode 9 beta. http://www.openradar.me/3338317476- (void)testTextFieldInteraction {77 if (iOS11_OR_ABOVE()) {78 return;79 }80 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"loadGoogle")]81 performAction:grey_tap()];82 id<GREYMatcher> searchButtonMatcher = grey_accessibilityHint(@"Search");83 [self ftr_waitForWebElementWithName:@"Search" elementMatcher:searchButtonMatcher];84 [[[EarlGrey selectElementWithMatcher:searchButtonMatcher]85 performAction:grey_clearText()]86 performAction:grey_typeText(@"20 + 22\n")];87 [self ftr_waitForWebElementWithName:@"42"88 elementMatcher:grey_accessibilityLabel(@"42")];89 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"42")]90 assertWithMatcher:grey_sufficientlyVisible()];91 // We need to tap because the second time we do typeAfterClearing, it passes firstResponder92 // check and never ends up auto-tapping on search field.93 [[EarlGrey selectElementWithMatcher:searchButtonMatcher]94 performAction:grey_tap()];95 [[[EarlGrey selectElementWithMatcher:searchButtonMatcher]96 performAction:grey_clearText()]97 performAction:grey_typeText(@"Who wrote Star Wars IV - A New Hope?\n")];98 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Google Search")]99 performAction:grey_tap()];100 id<GREYMatcher> resultMatcher = grey_allOf(grey_accessibilityLabel(@"George Lucas"),101 grey_accessibilityTrait(UIAccessibilityTraitHeader),102 nil);103 [self ftr_waitForWebElementWithName:@"Search Result" elementMatcher:resultMatcher];104 [[EarlGrey selectElementWithMatcher:resultMatcher]105 assertWithMatcher:grey_sufficientlyVisible()];106}107// Test disabled on Xcode 9 beta. http://www.openradar.me/33383174108- (void)testJavaScriptExecution {109 if (iOS11_OR_ABOVE()) {110 return;111 }112 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"loadGoogle")]113 performAction:grey_tap()];114 id<GREYAction> jsAction =115 grey_javaScriptExecution(@"window.location.href='http://images.google.com'", nil);116 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"FTRTestWebView")]117 performAction:jsAction];118 NSError *error;119 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"IMAGES")]120 assertWithMatcher:grey_sufficientlyVisible() error:&error];121 if (error) {122 // On some form factors, label is set to "Images" instead of "IMAGES".123 [[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Images")] atIndex:1]124 assertWithMatcher:grey_sufficientlyVisible()];125 }126 NSString *executionString = @"window.location.href='http://translate.google.com'";127 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"FTRTestWebView")]128 performAction:grey_javaScriptExecution(executionString, nil)];129 id<GREYAction> executeJavascript =130 grey_javaScriptExecution(@"window.location.href='http://play.google.com'", nil);131 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"FTRTestWebView")]132 performAction:executeJavascript];133 NSString *jsResult;134 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"FTRTestWebView")]135 performAction:grey_javaScriptExecution(@"2 + 2", &jsResult)];136 GREYAssertTrue([jsResult isEqualToString:@"4"], @"Expected: 4, Actual: %@", jsResult);137}138#pragma mark - Private139/**140 * Waits for the element matching @c matcher to become visible or 3 seconds whichever happens141 * first.142 *143 * @param name Name of the element to wait for.144 * @param matcher Matcher that uniquely matches the element to wait for.145 */146- (void)ftr_waitForWebElementWithName:(NSString *)name elementMatcher:(id<GREYMatcher>)matcher {147 // TODO: Improve EarlGrey webview synchronization so that it automatically waits for the page to148 // load removing the need for conditions such as this.149 [[GREYCondition conditionWithName:[@"Wait For Element With Name: " stringByAppendingString:name]...
IndexedObjCMethod.m
Source:IndexedObjCMethod.m
1@interface Test2- (int)performAction:(int)action with:(int)value; // CHECK: rename [[@LINE]]:8 -> [[@LINE]]:21, [[@LINE]]:34 -> [[@LINE]]:383@end4@implementation Test5- (int)performAction:(int)action6 with:(int)value { // CHECK: rename [[@LINE-1]]:8 -> [[@LINE-1]]:21, [[@LINE]]:8 -> [[@LINE]]:127 return action + value;8}9+ (void)foo:(Test*)t {10 [t performAction: 2 with: 4]; // CHECK: rename [[@LINE]]:8 -> [[@LINE]]:21, [[@LINE]]:25 -> [[@LINE]]:2911 SEL s1 = @selector(performAction:12 with:); // CHECK-NOT: selector [[@LINE-1]]:24 -> [[@LINE-1]]:37, [[@LINE]]:24 -> [[@LINE]]:2813 SEL s2 = @selector(performAction:); // CHECK-NOT: selector [[@LINE]]14 SEL s3 = @selector(performAction); // CHECK-NOT: selector [[@LINE]]15 // Not indexed16 [t performAction: 1 with: 2]; // CHECK-NOT: rename [[@LINE]]17}18@end19// RUN: clang-refactor-test rename-indexed-file -no-textual-matches -name=performAction:with -new-name=foo:bar -indexed-file=%s -indexed-at=3:8 -indexed-at=9:8 -indexed-at=objc-message:15:8 -indexed-symbol-kind=objc-im %s | FileCheck %s20@interface SemicolonIsExcluded21-(void)/*A_propA4_set_decl*/setPropA4X:(int)value;22@end23// CHECK2: rename [[@LINE-2]]:29 -> [[@LINE-2]]:3924// RUN: clang-refactor-test rename-indexed-file -no-textual-matches -name=setPropA4X: -new-name=foo -indexed-file=%s -indexed-at=29:29 -indexed-symbol-kind=objc-im %s -x objective-c | FileCheck --check-prefix=CHECK2 %s25// It should be possible to have the filename as one of the compilation arguments26// RUN: clang-refactor-test rename-indexed-file -no-textual-matches -ignore-filename-for-initiation-tu -name=performAction:with: -new-name=foo:bar: -indexed-file=%s -indexed-at=3:8 -indexed-at=9:8 -indexed-at=objc-message:15:8 -indexed-symbol-kind=objc-cm %s -c %s -Wall | FileCheck %s27// RUN: clang-refactor-test rename-indexed-file -no-textual-matches -ignore-filename-for-initiation-tu -name=performAction:with: -new-name=foo:bar: -indexed-file=%s -indexed-at=3:8 -indexed-at=9:8 -indexed-at=objc-message:15:8 -indexed-symbol-kind=objc-cm %s %s -fsyntax-only | FileCheck %s28// -gmodules should be stripped to avoid -fmodule-format=obj in CC1 arguments:29// RUN: clang-refactor-test rename-indexed-file -no-textual-matches -name=performAction:with: -new-name=foo:bar: -indexed-file=%s -indexed-at=3:8 -indexed-at=9:8 -indexed-at=objc-message:15:8 -indexed-symbol-kind=objc-cm %s -fmodules -gmodules | FileCheck %s30// These texual matches should be reported as comment or selector occurrences:31// CHECK3: rename [[@LINE-40]]:8 -> [[@LINE-40]]:21, [[@LINE-40]]:34 -> [[@LINE-40]]:3832// performAction33/* performAction: with: 2 performAction */34/*! performAction+135// performAction with36!*/37/// Hello performAction with World38/// \c performAction.39// CHECK3: comment [[@LINE-8]]:4 -> [[@LINE-8]]:1740// CHECK3-NEXT: comment [[@LINE-8]]:4 -> [[@LINE-8]]:1741// CHECK3-NEXT: comment [[@LINE-9]]:27 -> [[@LINE-9]]:4042// CHECK3-NEXT: documentation [[@LINE-9]]:5 -> [[@LINE-9]]:1843// CHECK3-NEXT: documentation [[@LINE-9]]:4 -> [[@LINE-9]]:1744// CHECK3-NEXT: documentation [[@LINE-8]]:11 -> [[@LINE-8]]:2445// CHECK3-NEXT: documentation [[@LINE-8]]:8 -> [[@LINE-8]]:2146// "performAction:with:"47// 'performAction:'with:48// CHECK3-NEXT: comment [[@LINE-2]]:5 -> [[@LINE-2]]:1849// CHECK3-NEXT: comment [[@LINE-2]]:5 -> [[@LINE-2]]:1850// CHECK3-NEXT: selector [[@LINE+1]]:11 -> [[@LINE+1]]:24, [[@LINE+1]]:25 -> [[@LINE+1]]:2951@selector(performAction:with:);52// CHECK3-NEXT: selector [[@LINE+1]]:11 -> [[@LINE+1]]:24, [[@LINE+1]]:28 -> [[@LINE+1]]:3253@selector(performAction : with );54// CHECK3-NEXT: selector [[@LINE+2]]:19 -> [[@LINE+2]]:32, [[@LINE+2]]:46 -> [[@LINE+2]]:5055SEL s = @selector(//comment56 performAction: /*comment*/ with57 );58// CHECK3-NEXT: selector [[@LINE+1]]:33 -> [[@LINE+1]]:46, [[@LINE+2]]:33 -> [[@LINE+2]]:3759void call = @selector(@selector(performAction:60 with: ));61// CHECK3-NEXT: comment [[@LINE+1]]:5562// RUN: clang-refactor-test rename-indexed-file -name=performAction:with: -new-name=foo:bar -indexed-file=%s -indexed-at=objc-cm:3:8 %s | FileCheck --check-prefix=CHECK3 %s63// These ones shouldn't:64// performAction2 PERFORMACTION performActionWith65const char *test = "performAction:with:";66@selector(performAction: with ::)67@selector(performAction:)68@selector(performAction)69@selector(performAction with)70@selector(performAction:without:)71@selector(performAction:with:somethingElse:)72@selector(performAction:with "")73@selector("performAction:with:")74@selector(with: performAction:)75selector(performAction:with)76(performAction:with:)77// CHECK3-NOT: comment78// CHECK3-NOT: documentation79// CHECK3-NOT: selector80// CHECK3-NOT: string-literal81// It should be possible to find a selector in a file without any indexed occurrences:82// CHECK4: selector [[@LINE+1]]:1183@selector(nonIndexedSelector)84// CHECK4-NEXT: comment85// CHECK4-NOT: selector86// RUN: clang-refactor-test rename-indexed-file -indexed-symbol-kind=objc-im -name=nonIndexedSelector -new-name=test -indexed-file=%s %s | FileCheck --check-prefix=CHECK4 %s87// RUN: clang-refactor-test rename-indexed-file -indexed-symbol-kind=objc-cm -name=nonIndexedSelector -new-name=test -indexed-file=%s %s | FileCheck --check-prefix=CHECK4 %s88#define MACRO doStuff89#define MACRO2(x, y) doStuff:(x) with: (y)90@interface I...
FTRActionSheetTest.m
Source:FTRActionSheetTest.m
...23 [self openTestViewNamed:@"Action Sheets"];24}25- (void)testSimpleActionSheet {26 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"simpleActionSheetButton")]27 performAction:grey_tap()];28 [[EarlGrey selectElementWithMatcher:grey_text(@"Action Sheet")]29 assertWithMatcher:grey_sufficientlyVisible()];30 [[EarlGrey selectElementWithMatcher:grey_text(@"Simple Button")]31 performAction:grey_tap()];32 [[EarlGrey selectElementWithMatcher:grey_text(@"Action Sheet Button Pressed")]33 assertWithMatcher:grey_sufficientlyVisible()];34 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"simpleActionSheetButton")]35 performAction:grey_tap()];36 [[EarlGrey selectElementWithMatcher:grey_text(@"Action Sheet")]37 assertWithMatcher:grey_sufficientlyVisible()];38 if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {39 [[EarlGrey selectElementWithMatcher:grey_text(@"Cancel")]40 performAction:grey_tap()];41 } else {42 [[EarlGrey selectElementWithMatcher:grey_keyWindow()]43 performAction:grey_tapAtPoint(CGPointMake(50, 50))];44 }45 [[EarlGrey selectElementWithMatcher:grey_text(@"Actions Verified Here")]46 assertWithMatcher:grey_sufficientlyVisible()];47}48- (void)testMultipleActionSheet {49 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"multipleActionSheetButton")]50 performAction:grey_tap()];51 [[EarlGrey selectElementWithMatcher:grey_text(@"Action Sheet")]52 assertWithMatcher:grey_sufficientlyVisible()];53 [[EarlGrey selectElementWithMatcher:grey_text(@"Simple Button")]54 performAction:grey_tap()];55 [[EarlGrey selectElementWithMatcher:grey_text(@"Action Sheet Button Pressed")]56 assertWithMatcher:grey_sufficientlyVisible()];57 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"multipleActionSheetButton")]58 performAction:grey_tap()];59 [[EarlGrey selectElementWithMatcher:grey_text(@"Action Sheet")]60 assertWithMatcher:grey_sufficientlyVisible()];61 if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {62 [[EarlGrey selectElementWithMatcher:grey_text(@"Cancel")]63 performAction:grey_tap()];64 } else {65 [[EarlGrey selectElementWithMatcher:grey_keyWindow()]66 performAction:grey_tapAtPoint(CGPointMake(50, 50))];67 }68 [[EarlGrey selectElementWithMatcher:grey_text(@"Actions Verified Here")]69 assertWithMatcher:grey_sufficientlyVisible()];70 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"multipleActionSheetButton")]71 performAction:grey_tap()];72 [[EarlGrey selectElementWithMatcher:grey_text(@"Action Sheet")]73 assertWithMatcher:grey_sufficientlyVisible()];74 [[EarlGrey selectElementWithMatcher:grey_text(@"Hide Button")]75 performAction:grey_tap()];76 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"multipleActionSheetButton")]77 assertWithMatcher:grey_notVisible()];78}79@end...
FTRAlertViewTest.m
Source:FTRAlertViewTest.m
...23 [self openTestViewNamed:@"Alert Views"];24}25- (void)testSimpleAlertView {26 [[EarlGrey selectElementWithMatcher:grey_text(@"Simple Alert")]27 performAction:[GREYActions actionForTap]];28 [[EarlGrey selectElementWithMatcher:grey_text(@"Flee")] performAction:[GREYActions actionForTap]];29}30- (void)testMultiOptionAlertView {31 [[EarlGrey selectElementWithMatcher:grey_text(@"Multi-Option Alert")]32 performAction:[GREYActions actionForTap]];33 [[EarlGrey selectElementWithMatcher:grey_text(@"Use Slingshot")]34 performAction:[GREYActions actionForTap]];35 [[EarlGrey selectElementWithMatcher:grey_text(@"Multi-Option Alert")]36 performAction:[GREYActions actionForTap]];37 [[EarlGrey selectElementWithMatcher:grey_text(@"Use Phaser")]38 performAction:[GREYActions actionForTap]];39 [[EarlGrey selectElementWithMatcher:grey_text(@"Roger")]40 performAction:[GREYActions actionForTap]];41 [[EarlGrey selectElementWithMatcher:grey_text(@"Multi-Option Alert")]42 assertWithMatcher:grey_sufficientlyVisible()];43}44- (void)testAlertViewChain {45 [[EarlGrey selectElementWithMatcher:grey_text(@"Multi-Option Alert")]46 performAction:[GREYActions actionForTap]];47 [[EarlGrey selectElementWithMatcher:grey_text(@"Use Phaser")]48 performAction:[GREYActions actionForTap]];49 [[EarlGrey selectElementWithMatcher:grey_text(@"Roger")]50 performAction:[GREYActions actionForTap]];51 [[EarlGrey selectElementWithMatcher:grey_text(@"Multi-Option Alert")]52 assertWithMatcher:grey_sufficientlyVisible()];53}54- (void)testStyledAlertView {55 [[EarlGrey selectElementWithMatcher:grey_text(@"Styled Alert")]56 performAction:[GREYActions actionForTap]];57 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Login")]58 performAction:grey_typeText(@"test_user")];59 [[EarlGrey selectElementWithMatcher:grey_text(@"test_user")] assertWithMatcher:grey_notNil()];60 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Password")]61 performAction:grey_typeText(@"test_pwd")];62 [[EarlGrey selectElementWithMatcher:grey_text(@"test_pwd")] assertWithMatcher:grey_notNil()];63 [[EarlGrey selectElementWithMatcher:grey_text(@"Leave")]64 performAction:[GREYActions actionForTap]];65}66@end...
performAction
Using AI Code Generation
1#import <Foundation/Foundation.h>2#import <XCTest/XCTest.h>3#import <EarlGrey/EarlGrey.h>4- (void)setUp {5 [super setUp];6}7- (void)tearDown {8 [super tearDown];9}10- (void)testExample {11 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"testView")] performAction:grey_tap()];12}13#import <XCTest/XCTest.h>14#import "EarlGreyTest-Swift.h"15- (void)setUp {16 [super setUp];17 self.continueAfterFailure = NO;18 [[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"testView")] performAction:grey_tap()] assertWithMatcher:grey_sufficientlyVisible()];19}20- (void)tearDown {21 [super tearDown];22}23- (void)testExample {24}25#import <XCTest/XCTest.h>26#import "EarlGreyTest-Swift.h"27- (void)setUp {28 [super setUp];29 self.continueAfterFailure = NO;30 [[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"testView")] performAction:grey_tap()] assertWithMatcher:grey_sufficientlyVisible()];31}32- (
performAction
Using AI Code Generation
1#import <Foundation/Foundation.h>2#import <EarlGrey/EarlGrey.h>3+ (void)performAction:(GREYActionBlock)action onElement:(id<GREYMatcher>)element;4#import "EarlGreyHelper.h"5+ (void)performAction:(GREYActionBlock)action onElement:(id<GREYMatcher>)element {6 withBlock:^BOOL{7 NSError *error;8 grey_elementVisible(element, &error);9 return error == nil;10 }];11 BOOL success = [condition waitWithTimeout:10];12 GREYAssertTrue(success, @"Element is not visible");13 onView(element).performAction(action);14}15#import <XCTest/XCTest.h>16#import <EarlGrey/EarlGrey.h>17#import "EarlGreyHelper.h"18- (void)setUp {19 [super setUp];20 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"test")] performAction:grey_tap()];21}22- (void)testExample {23 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"test")] assertWithMatcher:grey_sufficientlyVisible()];24}25- (void)testEarlGreyHelper {26 [EarlGreyHelper performAction:grey_tap() onElement:grey_accessibilityID(@"test")];27 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"test")] assertWithMatcher:grey_sufficientlyVisible()];28}
performAction
Using AI Code Generation
1#import <EarlGrey/EarlGrey.h>2+ (void)selectElementWithMatcher:(id <GREYMatcher>)matcher;3+ (void)selectElementWithMatcher:(id <GREYMatcher>)matcher atIndexPath:(NSIndexPath *)indexPath;4+ (void)selectElementWithMatcher:(id <GREYMatcher>)matcher atIndexPath:(NSIndexPath *)indexPath inSection:(NSInteger)section;5+ (void)selectElementWithMatcher:(id <GREYMatcher>)matcher atIndexPath:(NSIndexPath *)indexPath inSection:(NSInteger)section atCellIndex:(NSInteger)cellIndex;6+ (void)selectElementWithMatcher:(id <GREYMatcher>)matcher atIndexPath:(NSIndexPath *)indexPath inSection:(NSInteger)section atCellIndex:(NSInteger)cellIndex inCollectionView:(id <GREYMatcher>)collectionViewMatcher;7+ (void)selectElementWithMatcher:(id <GREYMatcher>)matcher atIndexPath:(NSIndexPath *)indexPath inSection:(NSInteger)section atCellIndex:(NSInteger)cellIndex inTableView:(id <GREYMatcher>)tableViewMatcher;8+ (void)selectElementWithMatcher:(id <GREYMatcher>)matcher atIndexPath:(NSIndexPath *)indexPath inSection:(NSInteger)section atCellIndex:(NSInteger)cellIndex inTableView:(id <GREYMatcher>)tableViewMatcher inCollectionView:(id <GREYMatcher>)collectionViewMatcher;9+ (void)selectElementWithMatcher:(id <GREYMatcher>)matcher atIndexPath:(NSIndexPath *)indexPath inSection:(NSInteger)section atCellIndex:(NSInteger)cellIndex inTableView:(id <GREYMatcher>)tableViewMatcher inCollectionView:(id <GREYMatcher>)collectionViewMatcher atRowIndex:(NSInteger)rowIndex;10#import "EarlGreyHelper.h"11+ (void)selectElementWithMatcher:(id <GREYMatcher>)matcher {12 [[EarlGrey selectElementWithMatcher:matcher] performAction:grey_tap()];13}14+ (void)selectElementWithMatcher:(id <GREYMatcher>)matcher atIndexPath:(NSIndexPath *)indexPath {15 [[EarlGrey selectElementWithMatcher:matcher] atIndexPath:indexPath performAction:grey_tap()];16}17+ (void)selectElementWithMatcher:(id <GREYMatcher>)matcher atIndexPath:(NSIndexPath *)indexPath inSection:(NSInteger)section {
performAction
Using AI Code Generation
1+ (void)performAction:(GREYActionBlock)actionBlock2 onElementWithMatcher:(id<GREYMatcher>)elementMatcher3 file:(const char *)file line:(NSUInteger)line;4+ (void)performAction:(GREYActionBlock)actionBlock5 onElementWithMatcher:(id<GREYMatcher>)elementMatcher6 file:(const char *)file line:(NSUInteger)line;7+ (void)performAction:(GREYActionBlock)actionBlock8 onElementWithMatcher:(id<GREYMatcher>)elementMatcher9 file:(const char *)file line:(NSUInteger)line;10+ (void)performAction:(GREYActionBlock)actionBlock11 onElementWithMatcher:(id<GREYMatcher>)elementMatcher12 file:(const char *)file line:(NSUInteger)line;13+ (void)performAction:(GREYActionBlock)actionBlock14 onElementWithMatcher:(id<GREYMatcher>)elementMatcher15 file:(const char *)file line:(NSUInteger)line;16+ (void)performAction:(GREYActionBlock)actionBlock17 onElementWithMatcher:(id<GREYMatcher>)elementMatcher18 file:(const char *)file line:(NSUInteger)line;19+ (void)performAction:(GREYActionBlock)actionBlock20 onElementWithMatcher:(id<GREYMatcher>)elementMatcher21 file:(const char *)file line:(NSUInteger)line;22+ (void)performAction:(GREYActionBlock)actionBlock23 onElementWithMatcher:(id<GREYMatcher>)elementMatcher24 file:(const char *)file line:(NSUInteger)line;25+ (void)performAction:(GREYActionBlock)actionBlock26 onElementWithMatcher:(id<GREYMatcher>)elementMatcher27 file:(const char *)file line:(NSUInteger)line;28+ (
Learn 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!!