Best EarlGrey code snippet using performAction.grey_setPickerColumnToValue
KeyboardKeysTest.m
Source:KeyboardKeysTest.m
...240 performAction:grey_typeText(string)] assertWithMatcher:grey_text(string)];241}242- (void)testUIKeyboardTypeDefault {243 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"KeyboardPicker")]244 performAction:grey_setPickerColumnToValue(0, @"Default")];245 NSString *string = @":$a8. {T<b@CC";246 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]247 performAction:grey_typeText(string)] assertWithMatcher:grey_text(string)];248}249- (void)testUIKeyboardTypeASCIICapable {250 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"KeyboardPicker")]251 performAction:grey_setPickerColumnToValue(0, @"ASCIICapable")];252 NSString *string = @":$a8. {T<b@CC";253 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]254 performAction:grey_typeText(string)] assertWithMatcher:grey_text(string)];255}256- (void)testUIKeyboardTypeNumbersAndPunctuation {257 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"KeyboardPicker")]258 performAction:grey_setPickerColumnToValue(0, @"NumbersAndPunctuation")];259 NSString *string = @":$a8. {T<b@CC";260 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]261 performAction:grey_typeText(string)] assertWithMatcher:grey_text(string)];262}263- (void)testUIKeyboardTypeURL {264 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"KeyboardPicker")]265 performAction:grey_setPickerColumnToValue(0, @"URL")];266 NSString *string = @"http://www.google.com/@*s$&T+t?[]#testLabel%foo;";267 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]268 performAction:grey_typeText(string)] assertWithMatcher:grey_text(string)];269}270- (void)testUIKeyboardTypeNumberPad {271 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"KeyboardPicker")]272 performAction:grey_setPickerColumnToValue(0, @"NumberPad")];273 NSString *string = @"\b0123456\b789\b\b";274 NSString *verificationString = @"0123457";275 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]276 performAction:grey_typeText(string)] assertWithMatcher:grey_text(verificationString)];277}278- (void)testUIKeyboardTypePhonePad {279 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"KeyboardPicker")]280 performAction:grey_setPickerColumnToValue(0, @"PhonePad")];281 NSString *string = @"01*23\b\b+45#67,89;";282 NSString *verificationString = @"01*+45#67,89;";283 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]284 performAction:grey_typeText(string)] assertWithMatcher:grey_text(verificationString)];285}286- (void)testUIKeyboardTypeEmailAddress {287 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"KeyboardPicker")]288 performAction:grey_setPickerColumnToValue(0, @"EmailAddress")];289 NSString *string = @"l0rem.ipsum+42@google.com#$_T*-";290 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]291 performAction:grey_typeText(string)] assertWithMatcher:grey_text(string)];292}293- (void)testUIKeyboardTypeDecimalPad {294 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"KeyboardPicker")]295 performAction:grey_setPickerColumnToValue(0, @"DecimalPad")];296 NSString *string = @"\b0123.456\b78..9\b\b";297 NSString *verificationString = @"0123.4578.";298 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]299 performAction:grey_typeText(string)] assertWithMatcher:grey_text(verificationString)];300}301- (void)testUIKeyboardTypeTwitter {302 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"KeyboardPicker")]303 performAction:grey_setPickerColumnToValue(0, @"Twitter")];304 NSString *string = @"@earlgrey Your framework is #awesome!!!1$:,eG%g\n";305 NSString *verificationString = @"@earlgrey Your framework is #awesome!!!1$:,eG%g";306 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]307 performAction:grey_typeText(string)] assertWithMatcher:grey_text(verificationString)];308}309- (void)testUIKeyboardTypeWebSearch {310 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"KeyboardPicker")]311 performAction:grey_setPickerColumnToValue(0, @"WebSearch")];312 NSString *string = @":$a8. {T<b@CC";313 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]314 performAction:grey_typeText(string)] assertWithMatcher:grey_text(string)];315}316- (void)testTypingOnLandscapeLeft {317 [EarlGrey rotateDeviceToOrientation:UIDeviceOrientationLandscapeLeft error:nil];318 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]319 performAction:grey_typeText(@"Cat")] assertWithMatcher:grey_text(@"Cat")];320}321- (void)testTypingOnLandscapeRight {322 [EarlGrey rotateDeviceToOrientation:UIDeviceOrientationLandscapeRight error:nil];323 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]324 performAction:grey_typeText(@"Cat")] assertWithMatcher:grey_text(@"Cat")];325}326- (void)testSuccessivelyTypingInTheSameTextField {327 [[[[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]328 performAction:grey_typeText(@"This ")] performAction:grey_typeText(@"Is A ")]329 performAction:grey_typeText(@"Test")] assertWithMatcher:grey_text(@"This Is A Test")];330}331- (void)testTypingBlankString {332 NSString *string = @" ";333 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]334 performAction:grey_typeText(string)] assertWithMatcher:grey_text(string)];335}336- (void)testClearAfterTypingInCustomTextView {337 [[[[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomTextView")]338 performAction:grey_typeText(@"Foo")] assertWithMatcher:grey_accessibilityLabel(@"Foo")]339 performAction:grey_clearText()] assertWithMatcher:grey_accessibilityLabel(@"")];340}341- (void)testClearAfterClearingInCustomTextView {342 [[[[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomTextView")]343 performAction:grey_clearText()] assertWithMatcher:grey_accessibilityLabel(@"")]344 performAction:grey_clearText()] assertWithMatcher:grey_accessibilityLabel(@"")];345}346- (void)testTypeAfterClearingInCustomTextView {347 [[[[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomTextView")]348 performAction:grey_clearText()] assertWithMatcher:grey_accessibilityLabel(@"")]349 performAction:grey_typeText(@"Foo")] assertWithMatcher:grey_accessibilityLabel(@"Foo")];350}351- (void)testKeyplaneChangeInCustomTextView {352 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomTextView")]353 performAction:grey_typeText(@"AAAAA")];354 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomTextView")]355 performAction:grey_typeText(@"\b")];356 // Keyplane should change to uppercase keyplane with backspace.357 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Q")]358 assertWithMatcher:grey_sufficientlyVisible()];359}360- (void)testKeyplaneChangeInTextField {361 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]362 performAction:grey_typeText(@"AAAAA")];363 // Keyplane should change to lowercase keyplane when capital letter typed.364 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"q")]365 assertWithMatcher:grey_sufficientlyVisible()];366 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]367 performAction:grey_typeText(@"\b")];368 // Pressing backspace should reset the keyplane appropriately to the autoCapitalizationType369 // property from the text input view. In this test, the text field has auto capitalization on, so370 // it should reset to uppercase keyplane.371 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Q")]372 assertWithMatcher:grey_sufficientlyVisible()];373}374- (void)testTypingOnTextFieldInUIInputAccessory {375 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Input Button")]376 performAction:grey_tap()];377 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"InputAccessoryTextField")]378 performAction:grey_typeText(@"Test")] assertWithMatcher:grey_text(@"Test")];379}380- (void)testMatchingFailsWithUIAccessibilityTextFieldElement {381 if (iOS13()) {382 id<GREYMatcher> elementMatcher =383 grey_allOf(grey_accessibilityValue(@"Text Field"),384 grey_kindOfClassName(kTextFieldAXElementClassName), nil);385 [[EarlGrey selectElementWithMatcher:elementMatcher] assertWithMatcher:grey_notNil()];386 NSError *error;387 [[EarlGrey selectElementWithMatcher:elementMatcher] performAction:grey_clearText()388 error:&error];389 XCTAssertNil(error, @"Typing on a UIAccessibilityElement has an error: %@", error);390 [[EarlGrey selectElementWithMatcher:elementMatcher] performAction:grey_typeText(@"a")];391 }392}393- (void)testClearAndReplaceWorksWithUIAccessibilityTextFieldElement {394 XCTSkipIf(iOS14_OR_ABOVE());395 id<GREYMatcher> elementMatcher =396 grey_allOf(grey_accessibilityValue(@"Text Field"),397 grey_kindOfClassName(kTextFieldAXElementClassName), nil);398 if (iOS13_OR_ABOVE()) {399 [[EarlGrey selectElementWithMatcher:elementMatcher] assertWithMatcher:grey_notNil()];400 NSError *error;401 [[EarlGrey selectElementWithMatcher:elementMatcher] performAction:grey_clearText()402 error:&error];403 XCTAssertNil(error, @"Typing on a UIAccessibilityElement has an error: %@", error);404 [[EarlGrey selectElementWithMatcher:elementMatcher] performAction:grey_typeText(@"a")];405 } else {406 [[[EarlGrey selectElementWithMatcher:elementMatcher] performAction:grey_clearText()]407 performAction:grey_replaceText(@"foo")];408 // Ensure the element exists by tapping on it. This also removes the cursor.409 [[EarlGrey selectElementWithMatcher:grey_textFieldValue(@"foo")] performAction:grey_tap()];410 }411}412- (void)testTypingAndResigningOfFirstResponder {413 GREYAssertFalse([GREYKeyboard keyboardShownWithError:nil], @"Keyboard shouldn't be shown");414 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]415 performAction:grey_typeText(@"Foo")] assertWithMatcher:grey_text(@"Foo")];416 GREYAssertTrue([GREYKeyboard keyboardShownWithError:nil], @"Keyboard shouldn't be shown");417 XCTAssertTrue([EarlGrey dismissKeyboardWithError:nil]);418 GREYAssertFalse([GREYKeyboard keyboardShownWithError:nil],419 @"Keyboard shouldn't be shown as it is resigned");420 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]421 performAction:grey_typeText(@"Foo")] assertWithMatcher:grey_text(@"FooFoo")];422 GREYAssertTrue([GREYKeyboard keyboardShownWithError:nil], @"Keyboard shouldn't be shown");423}424- (void)testTogglingShiftByChangingCase {425 NSString *multiCaseString = @"aA1a1A1aA1AaAa1A1a";426 for (NSUInteger i = 0; i < multiCaseString.length; i++) {427 NSString *currentCharacter = [multiCaseString substringWithRange:NSMakeRange(i, 1)];428 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]429 performAction:grey_typeText(currentCharacter)]430 assertWithMatcher:grey_text([multiCaseString substringToIndex:i + 1])];431 id keyboardClass = GREY_REMOTE_CLASS_IN_APP(GREYKeyboard);432 for (NSString *axLabel in [[keyboardClass returnByValue] shiftKeyIdentifyingCharacters]) {433 NSError *error;434 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(axLabel)] performAction:grey_tap()435 error:&error];436 }437 }438 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]439 assertWithMatcher:grey_text(multiCaseString)];440}441- (void)testIsKeyboardShownWithCustomKeyboardTracker {442 GREYAssertFalse([GREYKeyboard keyboardShownWithError:nil], @"Keyboard shouldn't be shown");443 GREYHostApplicationDistantObject *host = GREYHostApplicationDistantObject.sharedInstance;444 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomKeyboardTracker")]445 performAction:host.actionForSetFirstResponder];446 GREYAssertFalse([GREYKeyboard keyboardShownWithError:nil], @"Keyboard shouldn't be shown");447}448/**449 * Verifies error details for dismissing a keyboard when the keyboard is not present.450 */451- (void)testTypingAndResigningWithError {452 GREYAssertFalse([GREYKeyboard keyboardShownWithError:nil], @"Keyboard shouldn't be shown");453 GREYHostApplicationDistantObject *host = GREYHostApplicationDistantObject.sharedInstance;454 NSError *error;455 XCTAssertFalse([EarlGrey dismissKeyboardWithError:&error]);456 NSString *localizedErrorDescription = [error localizedDescription];457 NSString *reason = @"Failed to dismiss keyboard:";458 GREYAssertTrue([localizedErrorDescription containsString:reason],459 @"Unexpected error message for initial dismiss: %@, Original error: %@",460 localizedErrorDescription, error);461 [[EarlGrey selectElementWithMatcher:grey_keyWindow()]462 performAction:host.actionForSetFirstResponder463 error:&error];464 XCTAssertFalse([EarlGrey dismissKeyboardWithError:&error]);465 localizedErrorDescription = [error localizedDescription];466 GREYAssertTrue([localizedErrorDescription containsString:reason],467 @"Unexpected error message for second dismiss: %@, Original error: %@",468 localizedErrorDescription, error);469}470- (void)testDismissingKeyboardWhenReturnIsNotPresent {471 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"KeyboardPicker")]472 performAction:grey_setPickerColumnToValue(0, @"PhonePad")];473 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextField")]474 performAction:grey_tap()];475 XCTAssertTrue([EarlGrey dismissKeyboardWithError:nil]);476}477- (void)testDismissingKeyboardWhenReturnIsPresentButDoesNotDismissTheKeyboard {478 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomTextView")]479 performAction:grey_tap()];480 NSError *error;481 XCTAssertTrue([EarlGrey dismissKeyboardWithError:&error]);482 XCTAssertNil(error);483 GREYAssertFalse([GREYKeyboard keyboardShownWithError:nil], @"Keyboard shouldn't be shown");484}485- (void)testTextViewDidChangeCalled {486 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TypingTextView")]...
FTRPickerViewInteractionTest.m
Source:FTRPickerViewInteractionTest.m
...132 [[EarlGrey selectElementWithMatcher:grey_text(@"Custom")] performAction:grey_tap()];133 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"viewForRowDelegateSwitch")]134 performAction:grey_turnSwitchOn(YES)];135 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]136 performAction:grey_setPickerColumnToValue(0, @"Green")];137 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]138 performAction:grey_setPickerColumnToValue(1, @"4")];139 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]140 assertWithMatcher:grey_pickerColumnSetToValue(0, @"Green")];141 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]142 assertWithMatcher:grey_pickerColumnSetToValue(1, @"4")];143}144- (void)testAttributedTitleForRowDefined {145 [[EarlGrey selectElementWithMatcher:grey_text(@"Custom")] performAction:grey_tap()];146 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"attributedTitleForRowDelegateSwitch")]147 performAction:grey_turnSwitchOn(YES)];148 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]149 performAction:grey_setPickerColumnToValue(0, @"Green")];150 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]151 performAction:grey_setPickerColumnToValue(1, @"4")];152 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]153 assertWithMatcher:grey_pickerColumnSetToValue(0, @"Green")];154 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]155 assertWithMatcher:grey_pickerColumnSetToValue(1, @"4")];156}157- (void)testTitleForRowDefined {158 [[EarlGrey selectElementWithMatcher:grey_text(@"Custom")] performAction:grey_tap()];159 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"titleForRowDelegateSwitch")]160 performAction:grey_turnSwitchOn(YES)];161 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]162 performAction:grey_setPickerColumnToValue(0, @"Green")];163 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]164 performAction:grey_setPickerColumnToValue(1, @"4")];165 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]166 assertWithMatcher:grey_pickerColumnSetToValue(0, @"Green")];167 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]168 assertWithMatcher:grey_pickerColumnSetToValue(1, @"4")];169}170@end...
PickerViewInteractionTest.m
Source:PickerViewInteractionTest.m
...24- (void)testInteractionIsImpossibleIfInteractionDisabled {25 [[EarlGrey selectElementWithMatcher:grey_text(@"Disabled")] performAction:grey_tap()];26 NSError *error;27 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"InteractionDisabledPickerId")]28 performAction:grey_setPickerColumnToValue(0, @"Green")29 error:&error];30 GREYAssertTrue([error.domain isEqual:kGREYInteractionErrorDomain], @"Error domain should match");31 GREYAssertTrue(error.code == kGREYInteractionConstraintsFailedErrorCode,32 @"Error code should match");33 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"InteractionDisabledPickerId")]34 assertWithMatcher:grey_pickerColumnSetToValue(0, @"Red")];35}36- (void)testDateOnlyPicker {37 NSString *dateString = @"1986/12/26";38 NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];39 dateFormatter.dateFormat = @"YYYY/MM/dd";40 NSDate *desiredDate = [dateFormatter dateFromString:dateString];41 [[EarlGrey selectElementWithMatcher:grey_text(@"Date")] performAction:grey_tap()];42 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"DatePickerId")]43 performAction:grey_setDate(desiredDate)];44 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"DatePickerId")]45 assertWithMatcher:grey_datePickerValue(desiredDate)];46 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"DateLabelId")]47 assertWithMatcher:grey_text(dateString)];48}49- (void)testDateUpdateCallbackIsNotInvokedIfDateDoesNotChange {50 NSString *dateString = @"1986/12/26";51 NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];52 dateFormatter.dateFormat = @"YYYY/MM/dd";53 NSDate *desiredDate = [dateFormatter dateFromString:dateString];54 [[EarlGrey selectElementWithMatcher:grey_text(@"Date")] performAction:grey_tap()];55 // Changing the date must change the label.56 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"DatePickerId")]57 performAction:grey_setDate(desiredDate)];58 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"DatePickerId")]59 assertWithMatcher:grey_datePickerValue(desiredDate)];60 // Clearing the label to revert the changes.61 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"ClearDateLabelButtonId")]62 performAction:grey_tap()];63 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"DateLabelId")]64 assertWithMatcher:grey_text(@"")];65 // Executing the change date action with the same value should not change the value, thus not66 // invoking the update callback.67 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"DatePickerId")]68 performAction:grey_setDate(desiredDate)];69 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"DateLabelId")]70 assertWithMatcher:grey_text(@"")];71}72- (void)testTimeOnlyPicker {73 NSString *timeString = @"19:30:00";74 NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];75 dateFormatter.dateFormat = @"HH:mm:ss";76 NSDate *desiredTime = [dateFormatter dateFromString:timeString];77 [[EarlGrey selectElementWithMatcher:grey_text(@"Time")] performAction:grey_tap()];78 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"DatePickerId")]79 performAction:grey_setDate(desiredTime)];80 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"DatePickerId")]81 assertWithMatcher:grey_datePickerValue(desiredTime)];82}83- (void)testDateTimePicker {84 NSString *dateTimeString = @"1986/12/26 19:30:00";85 NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];86 dateFormatter.dateFormat = @"YYYY/MM/dd HH:mm:ss";87 NSDate *desiredDateTime = [dateFormatter dateFromString:dateTimeString];88 [[EarlGrey selectElementWithMatcher:grey_text(@"DateTime")] performAction:grey_tap()];89 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"DatePickerId")]90 performAction:grey_setDate(desiredDateTime)];91 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"DatePickerId")]92 assertWithMatcher:grey_datePickerValue(desiredDateTime)];93}94- (void)testCountdownTimePicker {95 NSString *timerString = @"12:30:00";96 NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];97 dateFormatter.dateFormat = @"HH:mm:ss";98 NSDate *desiredTimer = [dateFormatter dateFromString:timerString];99 [[EarlGrey selectElementWithMatcher:grey_text(@"Counter")] performAction:grey_tap()];100 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"DatePickerId")]101 performAction:grey_setDate(desiredTimer)];102 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"DatePickerId")]103 assertWithMatcher:grey_datePickerValue(desiredTimer)];104}105- (void)testCustomPicker {106 [[EarlGrey selectElementWithMatcher:grey_text(@"Custom")] performAction:grey_tap()];107 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]108 performAction:grey_setPickerColumnToValue(0, @"Blue")];109 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]110 performAction:grey_setPickerColumnToValue(1, @"5")];111 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]112 assertWithMatcher:grey_pickerColumnSetToValue(0, @"Blue")];113 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]114 assertWithMatcher:grey_pickerColumnSetToValue(1, @"5")];115}116- (void)testPickerViewDidSelectRowInComponentIsCalled {117 [[EarlGrey selectElementWithMatcher:grey_text(@"Custom")] performAction:grey_tap()];118 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]119 performAction:grey_setPickerColumnToValue(0, @"Hidden")] assertWithMatcher:grey_notVisible()];120}121- (void)testNoPickerViewComponentDelegateMethodsAreDefined {122 [[EarlGrey selectElementWithMatcher:grey_text(@"Custom")] performAction:grey_tap()];123 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"noDelegateMethodDefinedSwitch")]124 performAction:grey_turnSwitchOn(YES)];125 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]126 assertWithMatcher:grey_pickerColumnSetToValue(0, nil)];127 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]128 assertWithMatcher:grey_pickerColumnSetToValue(1, nil)];129}130- (void)testViewForRowDefined {131 [[EarlGrey selectElementWithMatcher:grey_text(@"Custom")] performAction:grey_tap()];132 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"viewForRowDelegateSwitch")]133 performAction:grey_turnSwitchOn(YES)];134 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]135 performAction:grey_setPickerColumnToValue(0, @"Green")];136 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]137 performAction:grey_setPickerColumnToValue(1, @"4")];138 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]139 assertWithMatcher:grey_pickerColumnSetToValue(0, @"Green")];140 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]141 assertWithMatcher:grey_pickerColumnSetToValue(1, @"4")];142}143- (void)testAttributedTitleForRowDefined {144 [[EarlGrey selectElementWithMatcher:grey_text(@"Custom")] performAction:grey_tap()];145 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"attributedTitleForRowDelegateSwitch")]146 performAction:grey_turnSwitchOn(YES)];147 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]148 performAction:grey_setPickerColumnToValue(0, @"Green")];149 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]150 performAction:grey_setPickerColumnToValue(1, @"4")];151 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]152 assertWithMatcher:grey_pickerColumnSetToValue(0, @"Green")];153 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]154 assertWithMatcher:grey_pickerColumnSetToValue(1, @"4")];155}156- (void)testTitleForRowDefined {157 [[EarlGrey selectElementWithMatcher:grey_text(@"Custom")] performAction:grey_tap()];158 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"titleForRowDelegateSwitch")]159 performAction:grey_turnSwitchOn(YES)];160 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]161 performAction:grey_setPickerColumnToValue(0, @"Green")];162 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]163 performAction:grey_setPickerColumnToValue(1, @"4")];164 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]165 assertWithMatcher:grey_pickerColumnSetToValue(0, @"Green")];166 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]167 assertWithMatcher:grey_pickerColumnSetToValue(1, @"4")];168}169@end...
CollectionViewTest.m
Source:CollectionViewTest.m
...22 [self openTestViewNamed:@"Collection Views"];23}24- (void)testSearchActionWithCollectionViewHorizontalLayout {25 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"layoutPicker")]26 performAction:grey_setPickerColumnToValue(0, @"Horizontal Layout")];27 // For reference this is how A, B, C, X, Y and Z are laid out using the horizontal layout:28 // A ... X29 // B ... Y30 // C ... Z31 // . ...32 // This test will search and find A, B, C, X, Y and Z and tap them.33 // Scroll to left to find A, B and C.34 [self ftr_scrollInDirection:kGREYDirectionLeft untilInteractableWithChar:'A'];35 [self ftr_verifyTapOnChar:'A'];36 [self ftr_verifyTapOnChar:'B'];37 [self ftr_verifyTapOnChar:'C'];38 // Scroll to right to find X Y and Z.39 [self ftr_scrollInDirection:kGREYDirectionRight untilInteractableWithChar:'Z'];40 [self ftr_verifyTapOnChar:'X'];41 [self ftr_verifyTapOnChar:'Y'];42 [self ftr_verifyTapOnChar:'Z'];43}44- (void)testSearchActionWithCollectionViewVerticalLayout {45 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"layoutPicker")]46 performAction:grey_setPickerColumnToValue(0, @"Vertical Layout")];47 // For reference this is how A, B, C, X, Y and Z are laid out using the vertical layout:48 // A B C .49 // . . . .50 // . . . .51 // . . . .52 // X Y Z53 // This test will search and find A, B, C, X, Y and Z and tap them.54 // Scroll to top to find A, B and C.55 [self ftr_scrollInDirection:kGREYDirectionUp untilInteractableWithChar:'A'];56 [self ftr_verifyTapOnChar:'A'];57 [self ftr_verifyTapOnChar:'B'];58 [self ftr_verifyTapOnChar:'C'];59 // Scroll to bottom to find X, Y and Z.60 [self ftr_scrollInDirection:kGREYDirectionDown untilInteractableWithChar:'Z'];61 [self ftr_verifyTapOnChar:'X'];62 [self ftr_verifyTapOnChar:'Y'];63 [self ftr_verifyTapOnChar:'Z'];64}65- (void)testSearchActionWithCollectionViewCustomLayout {66 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"layoutPicker")]67 performAction:grey_setPickerColumnToValue(0, @"Vertical Layout")];68 // For reference this is how A, B, C, X, Y and Z are laid out using the custom layout:69 // A B C ...70 // ...71 // ... X72 // Y Z73 // This test will search and find A, B, C, X, Y and Z and tap them.74 // Scroll to top left for A, B and C.75 [self ftr_scrollInDirection:kGREYDirectionLeft untilInteractableWithChar:'A'];76 [self ftr_verifyTapOnChar:'A'];77 [self ftr_verifyTapOnChar:'B'];78 [self ftr_verifyTapOnChar:'C'];79 // Scroll to bottom to find Z.80 [self ftr_scrollInDirection:kGREYDirectionDown untilInteractableWithChar:'Z'];81 // Scroll to bottom-right to find X and tap it....
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!!