How to use grey_kindOfClass method of selectElementWithMatcher class

Best EarlGrey code snippet using selectElementWithMatcher.grey_kindOfClass

FTRBasicInteractionTest.m

Source:FTRBasicInteractionTest.m Github

copy

Full Screen

...111/**112 * Ensure that any assertion on an unmatched element throws an exception.113 */114- (void)testNotNilCallOnUnmatchedElementThrowsException {115 XCTAssertThrows([[[EarlGrey selectElementWithMatcher:grey_kindOfClassName(@"GarbageValue")]116 atIndex:0] assertWithMatcher:grey_notNil()]);117}118/**119 * Ensure that a not-nil assertion on a matched element does not throw an exception.120 */121- (void)testNotNilCheckOnMatchedElementDoesNotThrowException {122 GREYElementInteraction *interaction =123 [[EarlGrey selectElementWithMatcher:grey_kindOfClass([UITableViewCell class])] atIndex:0];124 [interaction assertWithMatcher:grey_notNil()];125}126/**127 * Checks for error handling using EarlGrey 2.0's Error API.128 */129- (void)testErrorHandling {130 NSError *error;131 [[EarlGrey selectElementWithMatcher:grey_text(@"GarbageValue")] performAction:grey_tap()132 error:&error];133 XCTAssertEqualObjects(error.domain, kGREYInteractionErrorDomain,134 @"Interaction Error not thrown for tapping on an invalid element.");135 error = nil;136 [[EarlGrey selectElementWithMatcher:grey_text(@"GarbageValue")] assertWithMatcher:grey_notNil()137 error:&error];138 XCTAssertEqualObjects(error.domain, kGREYInteractionErrorDomain,139 @"Interaction Error not thrown for not-nil assert on an invalid element.");140 error = nil;141 [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()142 error:&error];143 XCTAssertNil(error, @"Error not nil for tapping on a valid element");144 error = nil;145 [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] assertWithMatcher:grey_notNil()146 error:&error];147 XCTAssertNil(error, @"Error not nil for asserting not-nil on a valid element");148}149/**150 * Perform typing in a text field and assert the typed value.151 */152- (void)testTypingRandomValueInTextFields {153 [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];154 [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] performAction:grey_tap()];155 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"foo")]156 performAction:grey_typeText(@"hi")];157 [[EarlGrey selectElementWithMatcher:grey_text(@"hi")]158 assertWithMatcher:grey_sufficientlyVisible()];159 [[EarlGrey selectElementWithMatcher:grey_text(@"EarlGrey TestApp")] performAction:grey_tap()];160}161/**162 * Perform typing a longer string with spaces and capital text in a text field and assert the163 * typed value.164 */165- (void)testTypingLongStringInTextField {166 [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];167 [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] performAction:grey_tap()];168 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"foo")]169 performAction:grey_typeText(@"Sam01le SWiFt TeSt")];170 [[EarlGrey selectElementWithMatcher:grey_text(@"Sam01le SWiFt TeSt")]171 assertWithMatcher:grey_sufficientlyVisible()];172 [[EarlGrey selectElementWithMatcher:grey_text(@"EarlGrey TestApp")] performAction:grey_tap()];173}174/**175 * Perform replace-text in a text field and assert the typed value.176 */177- (void)testReplaceTextInTextField {178 [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];179 [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] performAction:grey_tap()];180 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"foo")]181 performAction:grey_replaceText(@"donec.metus+spam@google.com")];182 [[EarlGrey selectElementWithMatcher:grey_allOf(grey_text(@"donec.metus+spam@google.com"),183 grey_kindOfClass([UITextField class]), nil)]184 assertWithMatcher:grey_sufficientlyVisible()];185 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"foo")]186 performAction:grey_replaceText(@"aA1a1A1aA1AaAa1A1a")];187 [[EarlGrey selectElementWithMatcher:grey_allOf(grey_text(@"aA1a1A1aA1AaAa1A1a"),188 grey_kindOfClass([UITextField class]), nil)]189 assertWithMatcher:grey_sufficientlyVisible()];190}191/**192 * Check notifications are fired on the main thread for the replace text action in a UITextField.193 */194- (void)testReplaceTextFiredNotifications {195 [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];196 [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] performAction:grey_tap()];197 [[GREYHostApplicationDistantObject sharedInstance] setUpObserverForReplaceText];198 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"foo")]199 performAction:grey_replaceText(@"donec.metus+spam@google.com")];200 BOOL notificationReceived = [[GREYHostApplicationDistantObject sharedInstance]201 textFieldTextDidBeginEditingNotificationFiredOnMainThread];202 XCTAssertTrue(notificationReceived);203}204/**205 * Check for basic visibility checking in the Basic Views.206 */207- (void)testAssertionsInBasicViews {208 [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];209 [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")]210 assertWithMatcher:grey_sufficientlyVisible()];211 [[EarlGrey selectElementWithMatcher:grey_text(@"EarlGrey TestApp")] performAction:grey_tap()];212}213/**214 * Use a GREYCondition to check if an element is visible on the screen. Toggle a Switch for the215 * element to be visible.216 */217- (void)testEarlGreyInvocationInsideConditionUsingWaitWithTimeout {218 [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];219 [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] performAction:grey_tap()];220 __block id<GREYAction> action =221 [[GREYHostApplicationDistantObject sharedInstance] actionForGettingTextFromMatchedElement];222 // Setup a condition to wait until a specific label says specific text.223 GREYCondition *waitCondition = [GREYCondition224 conditionWithName:@"WaitForLabelText"225 block:^BOOL() {226 NSError *error;227 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"sampleLabel")]228 performAction:action229 error:&error];230 return error == nil;231 }];232 // Switch text and wait.233 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Switch")]234 performAction:grey_turnSwitchOn(NO)];235 XCTAssertTrue([waitCondition waitWithTimeout:10.0],236 @"Switch not manipulated within the allotted time for a Condition.");237}238/**239 * Use a GREYCondition to check if an element is visible on the screen. Change a stepper value for240 * the element to be visible.241 */242- (void)testEarlGreyInvocationInsideConditionUsingWaitWithLargeTimeout {243 [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];244 GREYCondition *waitCondition = [GREYCondition245 conditionWithName:@"conditionWithAction"246 block:^BOOL {247 static double stepperValue = 51;248 [[EarlGrey selectElementWithMatcher:grey_kindOfClass([UIStepper class])]249 performAction:grey_setStepperValue(++stepperValue)];250 return stepperValue == 55;251 }];252 XCTAssertTrue([waitCondition waitWithTimeout:15.0],253 @"Stepper Change not completed within the allotted time for the Condition.");254 [[EarlGrey selectElementWithMatcher:grey_kindOfClass([UIStepper class])]255 assertWithMatcher:grey_stepperValue(55)];256}257/**258 * Ensure basic interaction with a stepper.259 */260- (void)testBasicInteractionWithStepper {261 [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];262 [[EarlGrey selectElementWithMatcher:grey_kindOfClass([UIStepper class])]263 performAction:grey_setStepperValue(87)];264 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Value Label")]265 assertWithMatcher:grey_text(@"Value: 87%")];266 [[[EarlGrey selectElementWithMatcher:grey_kindOfClass([UIStepper class])]267 performAction:grey_setStepperValue(16)] assertWithMatcher:grey_stepperValue(16)];268}269/**270 * Ensure basic interaction with a switch.271 */272- (void)testInteractionWithSwitch {273 [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];274 [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] performAction:grey_tap()];275 [[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Switch")]276 performAction:grey_turnSwitchOn(NO)] assertWithMatcher:grey_switchWithOnState(NO)];277 [[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Switch")]278 performAction:grey_turnSwitchOn(YES)] assertWithMatcher:grey_switchWithOnState(YES)];279 [[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Switch")]280 performAction:grey_turnSwitchOn(YES)] assertWithMatcher:grey_switchWithOnState(YES)];281 [[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Switch")]282 performAction:grey_turnSwitchOn(NO)] assertWithMatcher:grey_switchWithOnState(NO)];283}284/**285 * Ensure basic interaction with a hidden label.286 */287- (void)testInteractionWithHiddenLabel {288 [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];289 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Hidden Label")]290 assertWithMatcher:grey_text(@"Hidden Label")];291}292/**293 * Ensure basic interaction with a view who's parent has alpha set to zero.294 */295- (void)testInteractionWithLabelWithParentWithAlphaZero {296 [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];297 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Long Press")]298 assertWithMatcher:grey_not(grey_sufficientlyVisible())];299}300/**301 * Ensure basic interaction using a remote matcher.302 */303- (void)testEarlGreyRemoteMatcher {304 id<GREYMatcher> matcher =305 [[GREYHostApplicationDistantObject sharedInstance] matcherForFirstElement];306 [[EarlGrey selectElementWithMatcher:grey_allOf(grey_kindOfClass([UITableViewCell class]), matcher,307 nil)] performAction:grey_tap()];308 NSError *error;309 [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] assertWithMatcher:grey_notNil()310 error:&error];311 XCTAssertEqual(error.code, kGREYInteractionElementNotFoundErrorCode,312 @"No table view cell from the main Table can be visible.");313}314/**315 * Ensure basic interaction using a remote action.316 */317- (void)testEarlGreyRemoteAction {318 [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];319 [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] performAction:grey_tap()];320 id<GREYAction> action =321 [[GREYHostApplicationDistantObject sharedInstance] actionForTapOnAccessibleElement];322 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Switch")] performAction:action];323}324/**325 * Ensure basic interaction using a remote assertion.326 */327- (void)testEarlGreyRemoteAssertion {328 id<GREYAssertion> assertion =329 [[GREYHostApplicationDistantObject sharedInstance] assertionThatAlphaIsGreaterThanZero];330 [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] assert:assertion];331}332/**333 * Ensure tapping on a disabled UIControl fails.334 */335- (void)testTappingOnADisabledButton {336 [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];337 NSError *error;338 [[EarlGrey selectElementWithMatcher:grey_buttonTitle(@"Disabled")] performAction:grey_tap()339 error:&error];340 XCTAssertEqualObjects(error.domain, kGREYInteractionErrorDomain);341 XCTAssertEqual(error.code, kGREYInteractionConstraintsFailedErrorCode);342}343/**344 * Checks the working of a condition with a large timeout.345 */346- (void)testEarlGreyInvocationInsideGREYConditionUsingWaitWithLargeTimeout {347 [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];348 GREYCondition *condition = [GREYCondition349 conditionWithName:@"conditionWithAction"350 block:^BOOL {351 static double stepperValue = 51;352 [[EarlGrey selectElementWithMatcher:grey_kindOfClass([UIStepper class])]353 performAction:grey_setStepperValue(++stepperValue)];354 return stepperValue == 55;355 }];356 XCTAssertTrue([condition waitWithTimeout:10.0]);357 [[EarlGrey selectElementWithMatcher:grey_kindOfClass([UIStepper class])]358 assertWithMatcher:grey_stepperValue(55)];359}360/**361 * Checks the working of a condition with a normal timeout.362 */363- (void)testEarlGreyInvocationInsideGREYConditionUsingWaitWithTimeout {364 [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];365 [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] performAction:grey_tap()];366 id<GREYAction> action = [[GREYHostApplicationDistantObject sharedInstance] actionToGetLabelText];367 // Setup a condition to wait until a specific label says specific text.368 GREYCondition *waitCondition = [GREYCondition369 conditionWithName:@"WaitForLabelText"370 block:^BOOL() {371 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"sampleLabel")]372 performAction:action];373 NSString *text = [[GREYHostApplicationDistantObject sharedInstance] labelText];374 return [text isEqualToString:@"OFF"];375 }];376 // Switch text and wait.377 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Switch")]378 performAction:grey_turnSwitchOn(NO)];379 XCTAssertTrue([waitCondition waitWithTimeout:10.0]);380}381/**382 * Check tapping on a new custom window that covers the whole screen.383 */384- (void)testTapOnWindow {385 [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];386 [[EarlGrey selectElementWithMatcher:grey_keyWindow()] performAction:grey_tap()];387 UIWindow *window = [[GREYHostApplicationDistantObject sharedInstance] setupGestureRecognizer];388 XCTAssertNotNil(window);389 // Tap on topmost window.390 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TopMostWindow")]391 performAction:grey_tap()];392 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TopMostWindow")]393 assertWithMatcher:grey_notVisible()];394}395/**396 * Check setting of the root view controller multiple times in the main window.397 */398- (void)testRootViewControllerSetMultipleTimesOnMainWindow {399 [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];400 UIViewController *originalVC =401 [[GREYHostApplicationDistantObject sharedInstance] originalVCAfterSettingNewVCAsRoot];402 [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] assertWithMatcher:grey_nil()];403 [[GREYHostApplicationDistantObject sharedInstance] setRootViewController:nil];404 [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] assertWithMatcher:grey_nil()];405 [[GREYHostApplicationDistantObject sharedInstance] setRootViewController:originalVC];406 [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] assertWithMatcher:grey_notNil()];407}408/**409 * Check setting of the root view controller in different windows.410 */411- (void)testRootViewControllerSetOnMultipleWindows {412 [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];413 UIWindow *window = nil;414 UIViewController *originalVC = [[GREYHostApplicationDistantObject sharedInstance]415 originalVCAfterSettingRootVCInAnotherWindow:window];416 [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] assertWithMatcher:grey_nil()];417 [[GREYHostApplicationDistantObject sharedInstance] setRootViewController:nil inWindow:window];418 [[GREYHostApplicationDistantObject sharedInstance] setRootViewController:originalVC];419 [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] assertWithMatcher:grey_notNil()];420}421/**422 * Ensures basic interactions with views.423 */424- (void)testBasicInteractionWithViews {425 [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];426 [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] performAction:grey_tap()];427 GREYElementInteraction *typeHere =428 [EarlGrey selectElementWithMatcher:grey_allOf(grey_accessibilityLabel(@"Type Something Here"),429 grey_kindOfClass([UITextField class]), nil)];430 [[typeHere performAction:grey_replaceText(@"Hello 2")] assertWithMatcher:grey_text(@"Hello 2")];431 [typeHere performAction:grey_clearText()];432 [[typeHere performAction:grey_tapAtPoint(CGPointMake(0, 0))]433 performAction:grey_replaceText(@"Hello!")];434 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"return")] performAction:grey_tap()];435 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Send")]436 performAction:grey_tapAtPoint(CGPointMake(5, 5))];437 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Simple Label")]438 assertWithMatcher:grey_text(@"Hello!")];439 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Switch")]440 performAction:grey_turnSwitchOn(NO)];441 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Simple Label")]442 assertWithMatcher:grey_text(@"OFF")];443 [[[EarlGrey selectElementWithMatcher:grey_text(@"Long Press")]444 performAction:grey_longPressWithDuration(1.1f)] assertWithMatcher:grey_notVisible()];445 [[[EarlGrey selectElementWithMatcher:grey_text(@"Double Tap")] performAction:grey_doubleTap()]446 assertWithMatcher:grey_notVisible()];447}448/**449 * Checks a custom action.450 */451- (void)testEarlGreyInvocationInsideCustomAction {452 [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];453 id<GREYAction> action =454 [[GREYHostApplicationDistantObject sharedInstance] actionForCheckingIfElementHidden];455 NSError *error;456 [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] performAction:action error:&error];457 if (!error) {458 [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] performAction:grey_tap()];459 [[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Long Press")]460 performAction:grey_longPressWithDuration(1.1f)] assertWithMatcher:grey_nil()];461 } else {462 GREYFail(@"Element should exist. We should not be here.");463 }464}465/**466 * Checks a custom assertion.467 */468- (void)testEarlGreyInvocationInsideCustomAssertion {469 [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];470 id<GREYAssertion> assertion =471 [[GREYHostApplicationDistantObject sharedInstance] assertionForCheckingIfElementPresent];472 NSError *error;473 [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] assert:assertion error:&error];474 if (!error) {475 [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] performAction:grey_tap()];476 [[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Long Press")]477 performAction:grey_longPressWithDuration(1.1f)] assertWithMatcher:grey_nil()];478 } else {479 GREYFail(@"Element should exist. We should not be here.");480 }481}482/**483 * Tests a long press at a point.484 */485- (void)testLongPressAtPointOnAccessibilityElement {486 [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];487 [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] performAction:grey_tap()];488 [[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Long Press")]489 performAction:grey_longPressAtPointWithDuration(CGPointMake(10, 10), 1.1f)]490 assertWithMatcher:grey_nil()];491}492/**493 * Checks long press on a text field.494 */495- (void)testLongPressOnTextField {496 [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];497 [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] performAction:grey_tap()];498 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"foo")]499 performAction:grey_longPressWithDuration(1.0f)];500 [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] assertWithMatcher:grey_notNil()];501}502/**503 * Check long pressing followed by selecting a menu option.504 */505- (void)testLongPressFollowedBySelectingMenuOption {506 [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];507 [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] performAction:grey_tap()];508 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"foo")]509 performAction:grey_typeText(@"Hello")];510 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"foo")]511 performAction:grey_longPressAtPointWithDuration(CGPointMake(1, 1), 1.0f)];512 [[EarlGrey selectElementWithMatcher:grey_text(@"Select")] performAction:grey_tap()];513 [[EarlGrey selectElementWithMatcher:grey_text(@"Cut")] performAction:grey_tap()];514 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"foo")]515 performAction:grey_typeText(@"FromEarlGrey")];516 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"foo")]517 performAction:grey_longPressAtPointWithDuration(CGPointMake(1, 1), 1.0f)];518 [[EarlGrey selectElementWithMatcher:grey_text(@"Paste")] performAction:grey_tap()];519 // Smart Inserts in Xcode 9 cause a space to appear by default after a paste. This attribute520 // is not available on Xcode 7 and therefore cannot be used to fix the test. Therefore, we521 // are changing the value based on the Xcode version.522 if (iOS11_OR_ABOVE()) {523 [[EarlGrey selectElementWithMatcher:grey_text(@"Hello FromEarlGrey")]524 assertWithMatcher:grey_sufficientlyVisible()];525 } else {526 [[EarlGrey selectElementWithMatcher:grey_text(@"HelloFromEarlGrey")]527 assertWithMatcher:grey_sufficientlyVisible()];528 }529}530/**531 * Check interaction with a view that has its parent view hidden and unhidden.532 */533- (void)testInteractionWithLabelWithParentHiddenAndUnhidden {534 [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];535 id<GREYAction> hideAction =536 [[GREYHostApplicationDistantObject sharedInstance] actionToHideOrUnhideBlock:YES];537 id<GREYAction> unhideAction =538 [[GREYHostApplicationDistantObject sharedInstance] actionToHideOrUnhideBlock:NO];539 [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] performAction:grey_tap()];540 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"tab2Container")]541 performAction:hideAction];542 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Long Press")]543 assertWithMatcher:grey_not(grey_sufficientlyVisible())];544 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"tab2Container")]545 performAction:unhideAction];546 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Long Press")]547 assertWithMatcher:grey_sufficientlyVisible()];548}549/**550 * Check interaction with a view that has its parent view opaque and translucent.551 */552- (void)testInteractionWithLabelWithParentTranslucentAndOpaque {553 [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];554 id<GREYAction> makeOpaqueAction =555 [[GREYHostApplicationDistantObject sharedInstance] actionToMakeOpaque:YES];556 id<GREYAction> makeTransparentAction =557 [[GREYHostApplicationDistantObject sharedInstance] actionToMakeOpaque:NO];558 [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] performAction:grey_tap()];559 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"tab2Container")]560 performAction:makeTransparentAction];561 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Long Press")]562 assertWithMatcher:grey_not(grey_sufficientlyVisible())];563 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"tab2Container")]564 performAction:makeOpaqueAction];565 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Long Press")]566 assertWithMatcher:grey_sufficientlyVisible()];567}568/**569 * Check interaction with a view that has its window opaque and translucent.570 *571 * @remark No test is provided for the key window since changing its hidden value will572 * cause other tests to fail since the keyWindow is modified.573 */574- (void)testInteractionWithLabelWithWindowTranslucentAndOpaque {575 [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];576 id<GREYAction> makeOpaqueAction =577 [[GREYHostApplicationDistantObject sharedInstance] actionToMakeWindowOpaque:YES];578 id<GREYAction> makeTransparentAction =579 [[GREYHostApplicationDistantObject sharedInstance] actionToMakeWindowOpaque:NO];580 [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] performAction:grey_tap()];581 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"tab2Container")]582 performAction:makeTransparentAction];583 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Long Press")]584 assertWithMatcher:grey_not(grey_sufficientlyVisible())];585 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"tab2Container")]586 performAction:makeOpaqueAction];587 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Long Press")]588 assertWithMatcher:grey_sufficientlyVisible()];589}590/**591 * Checks the state of a UIButton.592 */593- (void)testButtonSelectedState {594 [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];595 [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] performAction:grey_tap()];596 id<GREYMatcher> buttonMatcher = grey_allOf(597 grey_kindOfClass([UIButton class]), grey_descendant(grey_accessibilityLabel(@"Send")), nil);598 [[EarlGrey selectElementWithMatcher:buttonMatcher] assertWithMatcher:grey_not(grey_selected())];599 [[EarlGrey selectElementWithMatcher:buttonMatcher] performAction:grey_tap()];600 [[EarlGrey selectElementWithMatcher:buttonMatcher] assertWithMatcher:grey_selected()];601}602/**603 * Checks the removal and addition of the status bar.604 */605- (void)testStatusBarRemoval {606 // By default, the status bar should not be included.607 NSError *error;608 GREYElementInteraction *interaction =609 [EarlGrey selectElementWithMatcher:grey_kindOfClassName(@"UIStatusBarWindow")];610 [interaction assertWithMatcher:grey_notNil() error:&error];611 XCTAssertNotNil(error);612 error = nil;613 // By setting the includeStatusBar variable, the Status Bar should be found.614 [interaction includeStatusBar];615 [interaction assertWithMatcher:grey_notNil() error:&error];616 XCTAssertNil(error);617}618/**619 * Checks an interaction with shorthand matchers created in the app side.620 */621- (void)testActionAndMatcherShorthandCreatedInTheApp {622 id<GREYAction> tapAction =623 [[GREYHostApplicationDistantObject sharedInstance] sampleShorthandAction];...

Full Screen

Full Screen

FirebaseAuthEarlGreyTests.m

Source:FirebaseAuthEarlGreyTests.m Github

copy

Full Screen

...44- (void)setUp {45 [super setUp];46 [self signOut];47 [[EarlGrey selectElementWithMatcher:grey_allOf(grey_scrollView(),48 grey_kindOfClass([UITableView class]), nil)]49 performAction:grey_scrollToContentEdge(kGREYContentEdgeTop)];50}51#pragma mark - Tests52/**53 * This test runs in replay mode by default. To run in a different mode54 * follow the instructions below.55 *56 * Blaze:57 * --test_arg=\'--networkReplayMode=(replay|record|disabled|observe)\'58 *59 * Xcode:60 * Update the following flag in the xcscheme.61 * --networkReplayMode=(replay|record|disabled|observe)62 */63- (void)testSignInExistingUser {64 NSString *email = @"123@abc.com";65 [[[EarlGrey selectElementWithMatcher:grey_allOf(grey_text(@"Sign in with Email/Password"),66 grey_sufficientlyVisible(), nil)]67 usingSearchAction:grey_scrollInDirection(kGREYDirectionDown, kShortScrollDistance)68 onElementWithMatcher:grey_allOf(grey_scrollView(), grey_kindOfClass([UITableView class]),69 nil)] performAction:grey_tap()];70 id<GREYMatcher> comfirmationButtonMatcher =71 grey_allOf(grey_kindOfClass([UILabel class]), grey_accessibilityLabel(@"OK"), nil);72 [[EarlGrey selectElementWithMatcher:73 #warning TODO Add accessibilityIdentifiers for the elements.74 grey_kindOfClass(NSClassFromString(@"_UIAlertControllerView"))]75 performAction:grey_typeText(email)];76 [[EarlGrey selectElementWithMatcher:comfirmationButtonMatcher] performAction:grey_tap()];77 [[EarlGrey78 selectElementWithMatcher:grey_kindOfClass(NSClassFromString(@"_UIAlertControllerView"))]79 performAction:grey_typeText(@"password")];80 [[EarlGrey selectElementWithMatcher:comfirmationButtonMatcher] performAction:grey_tap()];81 [[[EarlGrey82 selectElementWithMatcher:grey_allOf(grey_text(email), grey_sufficientlyVisible(), nil)]83 usingSearchAction:grey_scrollInDirection(kGREYDirectionUp, kShortScrollDistance)84 onElementWithMatcher:grey_allOf(grey_scrollView(), grey_kindOfClass([UITableView class]),85 nil)] assertWithMatcher:grey_sufficientlyVisible()];86}87/** Test sign in with a valid BYOAuth token retrived from a remote server. */88- (void)testSignInWithValidBYOAuthToken {89 NSError *error;90 NSString *customToken = [NSString stringWithContentsOfURL:[NSURL URLWithString:kCustomTokenUrl]91 encoding:NSUTF8StringEncoding92 error:&error];93 if (!customToken) {94 GREYFail(@"There was an error retrieving the custom token: %@", error);95 }96 [[[EarlGrey selectElementWithMatcher:grey_allOf(grey_text(@"Sign In (BYOAuth)"),97 grey_sufficientlyVisible(), nil)]98 usingSearchAction:grey_scrollInDirection(kGREYDirectionDown, kShortScrollDistance)99 onElementWithMatcher:grey_allOf(grey_scrollView(), grey_kindOfClass([UITableView class]),100 nil)] performAction:grey_tap()];101 [[[EarlGrey selectElementWithMatcher:grey_kindOfClass([UITextView class])]102 performAction:grey_replaceText(customToken)] assertWithMatcher:grey_text(customToken)];103 [[EarlGrey selectElementWithMatcher:grey_text(@"Done")] performAction:grey_tap()];104 [self waitForElementWithText:@"OK" withDelay:kWaitForElementTimeOut];105 [[EarlGrey selectElementWithMatcher:grey_text(@"OK")] performAction:grey_tap()];106 [[[EarlGrey107 selectElementWithMatcher:grey_allOf(grey_text(kTestingAccountUserID),108 grey_sufficientlyVisible(), nil)]109 usingSearchAction:grey_scrollInDirection(kGREYDirectionUp,110 kShortScrollDistance)111 onElementWithMatcher:grey_allOf(grey_scrollView(),112 grey_kindOfClass([UITableView class]),113 nil)]114 assertWithMatcher:grey_sufficientlyVisible()];115}116- (void)testSignInWithInvalidBYOAuthToken {117 [[[EarlGrey selectElementWithMatcher:grey_allOf(grey_text(@"Sign In (BYOAuth)"),118 grey_sufficientlyVisible(), nil)]119 usingSearchAction:grey_scrollInDirection(kGREYDirectionDown, kShortScrollDistance)120 onElementWithMatcher:grey_allOf(grey_scrollView(), grey_kindOfClass([UITableView class]),121 nil)] performAction:grey_tap()];122 [[[EarlGrey selectElementWithMatcher:grey_kindOfClass([UITextView class])]123 performAction:grey_replaceText(kInvalidCustomToken)]124 assertWithMatcher:grey_text(kInvalidCustomToken)];125 [[EarlGrey selectElementWithMatcher:grey_text(@"Done")] performAction:grey_tap()];126 NSString *invalidTokenErrorMessage =127 @"The custom token format is incorrect. Please check the documentation.";128 [self waitForElementWithText:invalidTokenErrorMessage withDelay:kWaitForElementTimeOut];129 [[EarlGrey selectElementWithMatcher:grey_text(@"OK")] performAction:grey_tap()];130}131#pragma mark - Helpers132/** Sign out current account. */133- (void)signOut {134 NSError *signOutError;135 BOOL status = [[FIRAuth auth] signOut:&signOutError];136 // Just log the error because we don't want to fail the test if signing out fails....

Full Screen

Full Screen

FTRSyncAPITest.m

Source:FTRSyncAPITest.m Github

copy

Full Screen

...43 grey_execute_sync(^{44 firstGREYExecuteSyncStarted = YES;45 [[EarlGrey selectElementWithMatcher:[GREYMatchers matcherForText:@"Tab 2"]]46 performAction:grey_tap()];47 id<GREYMatcher> matcher = grey_allOf(grey_kindOfClass([UITextField class]),48 grey_accessibilityLabel(@"Type Something Here"),49 nil);50 [[[EarlGrey selectElementWithMatcher:matcher] performAction:grey_tap()]51 performAction:grey_typeText(@"Hello!")];52 });53 grey_execute_sync(^{54 id<GREYMatcher> matcher = grey_allOf(grey_kindOfClass([UITextField class]),55 grey_accessibilityLabel(@"Type Something Here"),56 nil);57 [[EarlGrey selectElementWithMatcher:matcher] assertWithMatcher:grey_text(@"Hello!")];58 });59 });60 // This should wait for grey_execute_sync to start execution on the background thread.61 BOOL success = [[GREYCondition conditionWithName:@"Wait for first grey_execute_sync"62 block:^BOOL{63 return firstGREYExecuteSyncStarted;64 }] waitWithTimeout:5.0];65 GREYAssert(success, @"Waiting for first grey_execute_sync to start timed-out");66 [[EarlGrey selectElementWithMatcher:grey_allOf(grey_kindOfClass([UITextField class]),67 grey_accessibilityLabel(@"Type Something Here"),68 nil)]69 assertWithMatcher:grey_text(@"Hello!")];70}71- (void)testGREYExecuteAsyncOnMainThread {72 grey_execute_async(^{73 [[EarlGrey selectElementWithMatcher:[GREYMatchers matcherForText:@"Tab 2"]]74 performAction:grey_tap()];75 [[[EarlGrey selectElementWithMatcher:grey_allOf(grey_kindOfClass([UITextField class]),76 grey_accessibilityLabel(@"Type Something Here"),77 nil)]78 performAction:grey_tapAtPoint(CGPointMake(0, 0))]79 performAction:grey_typeText(@"Hello!")];80 });81 // This should wait for the above async to finish.82 [[EarlGrey selectElementWithMatcher:grey_allOf(grey_kindOfClass([UITextField class]),83 grey_accessibilityLabel(@"Type Something Here"),84 nil)]85 assertWithMatcher:grey_text(@"Hello!")];86}87- (void)testGREYExecuteAsyncOnBackgroundThread {88 __block BOOL GREYExecuteAsyncStarted = NO;89 // Execute on a background thread.90 dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{91 grey_execute_async(^{92 GREYExecuteAsyncStarted = YES;93 [[EarlGrey selectElementWithMatcher:[GREYMatchers matcherForText:@"Tab 2"]]94 performAction:grey_tap()];95 id matcher = grey_allOf(grey_kindOfClass([UITextField class]),96 grey_accessibilityLabel(@"Type Something Here"),97 nil);98 [[[EarlGrey selectElementWithMatcher:matcher] performAction:grey_tap()]99 performAction:grey_typeText(@"Hello!")];100 });101 });102 // This should wait for grey_execute_async to start execution on the background thread.103 BOOL success = [[GREYCondition conditionWithName:@"Wait for background grey_execute_async"104 block:^BOOL{105 return GREYExecuteAsyncStarted;106 }] waitWithTimeout:5.0];107 GREYAssert(success, @"Waiting for grey_execute_async to start timed-out");108 // This should wait for the above async to finish.109 [[EarlGrey selectElementWithMatcher:grey_allOf(grey_kindOfClass([UITextField class]),110 grey_accessibilityLabel(@"Type Something Here"),111 nil)]112 assertWithMatcher:grey_text(@"Hello!")];113}114@end...

Full Screen

Full Screen

BYOAuthTests.m

Source:BYOAuthTests.m Github

copy

Full Screen

...34 }35 [[[EarlGrey selectElementWithMatcher:grey_allOf(grey_text(@"Sign In (BYOAuth)"),36 grey_sufficientlyVisible(), nil)]37 usingSearchAction:grey_scrollInDirection(kGREYDirectionDown, kShortScrollDistance)38 onElementWithMatcher:grey_allOf(grey_scrollView(), grey_kindOfClass([UITableView class]),39 nil)] performAction:grey_tap()];40 [[[EarlGrey selectElementWithMatcher:grey_kindOfClass([UITextView class])]41 performAction:grey_replaceText(customToken)] assertWithMatcher:grey_text(customToken)];42 [[EarlGrey selectElementWithMatcher:grey_text(@"Done")] performAction:grey_tap()];43 [self waitForElementWithText:@"OK" withDelay:kWaitForElementTimeOut];44 [[EarlGrey selectElementWithMatcher:grey_text(@"OK")] performAction:grey_tap()];45 [[[EarlGrey selectElementWithMatcher:grey_allOf(grey_text(kTestingAccountUserID),46 grey_sufficientlyVisible(), nil)]47 usingSearchAction:grey_scrollInDirection(kGREYDirectionUp, kShortScrollDistance)48 onElementWithMatcher:grey_allOf(grey_scrollView(), grey_kindOfClass([UITableView class]),49 nil)] assertWithMatcher:grey_sufficientlyVisible()];50}51- (void)testSignInWithInvalidBYOAuthToken {52 [[[EarlGrey selectElementWithMatcher:grey_allOf(grey_text(@"Sign In (BYOAuth)"),53 grey_sufficientlyVisible(), nil)]54 usingSearchAction:grey_scrollInDirection(kGREYDirectionDown, kShortScrollDistance)55 onElementWithMatcher:grey_allOf(grey_scrollView(), grey_kindOfClass([UITableView class]),56 nil)] performAction:grey_tap()];57 [[[EarlGrey selectElementWithMatcher:grey_kindOfClass([UITextView class])]58 performAction:grey_replaceText(kInvalidCustomToken)]59 assertWithMatcher:grey_text(kInvalidCustomToken)];60 [[EarlGrey selectElementWithMatcher:grey_text(@"Done")] performAction:grey_tap()];61 NSString *invalidTokenErrorMessage = @"Sign-In Error";62 [self waitForElementWithText:invalidTokenErrorMessage withDelay:kWaitForElementTimeOut];63 [[EarlGrey selectElementWithMatcher:grey_text(@"OK")] performAction:grey_tap()];64}65@end...

Full Screen

Full Screen

DemoAppTests.m

Source:DemoAppTests.m Github

copy

Full Screen

...9#import <UIKit/UIKit.h>10#import <XCTest/XCTest.h>11id<GREYMatcher> matcher(NSString *name, Class class)12{13 return grey_allOf(grey_accessibilityLabel(name), grey_kindOfClass(class), grey_sufficientlyVisible(), nil);14}15id<GREYMatcher> cellMatcher(NSString *name)16{17 id<GREYMatcher> matcher = grey_allOf(grey_accessibilityLabel(name), nil);18 return matcher;19}20void selectTab(NSString *tabName)21{22 [[EarlGrey selectElementWithMatcher:matcher(tabName, NSClassFromString(@"UITabBarButton"))] performAction:grey_tap()];23}24void selectButton(NSString *name)25{26 [[EarlGrey selectElementWithMatcher:grey_buttonTitle(name)] performAction:grey_tap()];27}...

Full Screen

Full Screen

FIRAuthE2eTests.m

Source:FIRAuthE2eTests.m Github

copy

Full Screen

...21 NSString *email = @"123@abc.com";22 [[[EarlGrey selectElementWithMatcher:grey_allOf(grey_text(@"Sign in with Email/Password"),23 grey_sufficientlyVisible(), nil)]24 usingSearchAction:grey_scrollInDirection(kGREYDirectionDown, kShortScrollDistance)25 onElementWithMatcher:grey_allOf(grey_scrollView(), grey_kindOfClass([UITableView class]),26 nil)] performAction:grey_tap()];27 id<GREYMatcher> comfirmationButtonMatcher =28 grey_allOf(grey_kindOfClass([UILabel class]), grey_accessibilityLabel(@"OK"), nil);29 [[EarlGrey selectElementWithMatcher:30 // TODO: Add accessibilityIdentifiers for the elements.31 grey_kindOfClass(NSClassFromString(@"_UIAlertControllerView"))]32 performAction:grey_typeText(email)];33 [[EarlGrey selectElementWithMatcher:comfirmationButtonMatcher] performAction:grey_tap()];34 [[EarlGrey35 selectElementWithMatcher:grey_kindOfClass(NSClassFromString(@"_UIAlertControllerView"))]36 performAction:grey_typeText(@"password")];37 [[EarlGrey selectElementWithMatcher:comfirmationButtonMatcher] performAction:grey_tap()];38 [[[EarlGrey39 selectElementWithMatcher:grey_allOf(grey_text(email), grey_sufficientlyVisible(), nil)]40 usingSearchAction:grey_scrollInDirection(kGREYDirectionUp, kShortScrollDistance)41 onElementWithMatcher:grey_allOf(grey_scrollView(), grey_kindOfClass([UITableView class]),42 nil)] assertWithMatcher:grey_sufficientlyVisible()];43}44@end...

Full Screen

Full Screen

grey_kindOfClass

Using AI Code Generation

copy

Full Screen

1GREYElementInteraction *interaction = [EarlGrey selectElementWithMatcher:grey_kindOfClass([UIButton class])];2[interaction assertWithMatcher:grey_sufficientlyVisible()];3[interaction performAction:grey_tap()];4GREYElementInteraction *interaction = [EarlGrey selectElementWithMatcher:grey_kindOfClass([UIButton class])];5[interaction assertWithMatcher:grey_sufficientlyVisible()];6[interaction performAction:grey_tap()];7let interaction = EarlGrey.selectElement(with: grey_kindOfClass(UIButton.self))8interaction?.assert(with: grey_sufficientlyVisible())9interaction?.perform(grey_tap())10let interaction = EarlGrey.selectElement(with: grey_kindOfClass(UIButton.self))11interaction?.assert(with: grey_sufficientlyVisible())12interaction?.perform(grey_tap())13let interaction = EarlGrey.selectElement(with: grey_kindOfClass(UIButton.self))14interaction?.assert(with: grey_sufficientlyVisible())15interaction?.perform(grey_tap())16let interaction = EarlGrey.selectElement(with: grey_kindOfClass(UIButton.self))17interaction?.assert(with: grey_sufficientlyVisible())18interaction?.perform(grey_tap())19let interaction = EarlGrey.selectElement(with: grey_kindOfClass(UIButton.self))20interaction?.assert(with: grey_sufficientlyVisible())21interaction?.perform(grey_tap())22let interaction = EarlGrey.selectElement(with: grey_kindOfClass(UIButton.self))23interaction?.assert(with: grey_sufficientlyVisible())24interaction?.perform(grey_tap())25let interaction = EarlGrey.selectElement(with: grey_kindOfClass(UIButton.self))26interaction?.assert(with: grey_sufficientlyVisible())

Full Screen

Full Screen

grey_kindOfClass

Using AI Code Generation

copy

Full Screen

1[[EarlGrey selectElementWithMatcher:grey_kindOfClass([UILabel class])]2 performAction:grey_tap()];3[[EarlGrey selectElementWithMatcher:GREYMatchers.matcherForKindOfClass([UILabel class])]4 performAction:grey_tap()];5[[EarlGrey selectElementWithMatcher:GREYMatchers.matcherForAllOfMatchers(@[GREYMatchers.matcherForKindOfClass([UILabel class]),GREYMatchers.matcherForText(@"Label")])]6 performAction:grey_tap()];7[[EarlGrey selectElementWithMatcher:GREYMatchers.matcherForAllOfMatchers(@[GREYMatchers.matcherForKindOfClass([UILabel class]),GREYMatchers.matcherForText(@"Label")])]8 performAction:grey_tap()];9[[EarlGrey selectElementWithMatcher:GREYMatchers.matcherForAnyOfMatchers(@[GREYMatchers.matcherForKindOfClass([UILabel class]),GREYMatchers.matcherForText(@"Label")])]10 performAction:grey_tap()];11[[EarlGrey selectElementWithMatcher:GREYMatchers.matcherForNotMatcher(GREYMatchers.matcherForText(@"Label"))]12 performAction:grey_tap()];13[[EarlGrey selectElementWithMatcher:GREYMatchers.matcherForText(@"Label")]14 performAction:grey_tap()];15[[EarlGrey selectElementWithMatcher:GREYMatchers.matcherForAccessibilityID(@"Label")]16 performAction:grey_tap()];17[[EarlGrey selectElementWithMatcher:GREYMatchers.matcherForAccessibilityLabel(@"Label")]18 performAction:grey_tap()];

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run EarlGrey automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful