Best EarlGrey code snippet using selectElementWithMatcher.grey_allOf
GSCXScannerTestUtils.m
Source:GSCXScannerTestUtils.m
...174 performAction:grey_tap()];175}176+ (void)dismissNoIssuesAlert {177 id<GREYMatcher> alertMatcher =178 grey_allOf(grey_text(kGSCXNoIssuesDismissButtonText), grey_interactable(), nil);179 GREYCondition *waitToDismissSettings = [GREYCondition180 conditionWithName:kGSCXScannerNoIssuesAlertConditionName181 block:^BOOL {182 id<GREYMatcher> assertion =183 [GSCXScannerTestUtils gscxtest_matcherForInteractable:YES];184 NSError *error;185 [[EarlGrey selectElementWithMatcher:alertMatcher] assertWithMatcher:assertion186 error:&error];187 return error == nil;188 }];189 BOOL hasAlertAppeared =190 [waitToDismissSettings waitWithTimeout:kGSCXScannerNoIssuesAlertConditionTimeout191 pollInterval:kGSCXScannerNoIssuesAlertConditionPollInterval];192 // Usually, XCTAssert(hasAlertAppeared) would be used, but XCTAssert cannot be used in a193 // non-XCTestCase subclass. If it did not appear, trying to tap it will fail the test anyways.194 // Assigning it to NO silences the unused return value warning.195 hasAlertAppeared = NO;196 [[EarlGrey selectElementWithMatcher:alertMatcher] performAction:grey_tap()];197}198+ (void)dismissScreenshotView {199 [[EarlGrey selectElementWithMatcher:grey_allOf(grey_text(kGSCXScannerOverlayDismissButtonText),200 grey_interactable(), nil)]201 performAction:grey_tap()];202}203+ (void)dismissContinuousScanReport {204 [GSCXScannerTestUtils dismissScreenshotView];205}206+ (void)tapNavButtonWithAccessibilityLabel:(NSString *)accessibilityLabel {207 id<GREYMatcher> matcher = grey_allOf(208 grey_ancestor(grey_keyWindow()), grey_ancestor(grey_kindOfClass([UINavigationBar class])),209 grey_ancestor(grey_accessibilityTrait(UIAccessibilityTraitButton)),210 grey_text(accessibilityLabel), nil);211 [[EarlGrey selectElementWithMatcher:matcher] performAction:grey_tap()];212}213+ (void)presentMockSystemAlert {214 CGRect bounds = [[GREY_REMOTE_CLASS_IN_APP(UIScreen) mainScreen] bounds];215 UIWindow *window = [[GREY_REMOTE_CLASS_IN_APP(UIWindow) alloc] initWithFrame:bounds];216 window.rootViewController = [[GREY_REMOTE_CLASS_IN_APP(UIViewController) alloc] init];217 // The window's background color must be fully opaque, or else tapping the perform scan button218 // succeeds even if the alert is displayed. Normally, only views with alpha < 0.1 forward touch219 // events, but the way EarlGrey selects and performs actions is not consistent with this. EarlGrey220 // allows the button to be tapped anyways. Setting the background color to black fixes this. This221 // is not aesthetically identical to system alerts, but it does have identical behavior.222 window.rootViewController.view.backgroundColor = [UIColor blackColor];223 UIAlertController *alert = [GREY_REMOTE_CLASS_IN_APP(UIAlertController)224 alertControllerWithTitle:@"Alert"225 message:@"Alert message."226 preferredStyle:UIAlertControllerStyleAlert];227 [alert addAction:[GREY_REMOTE_CLASS_IN_APP(UIAlertAction)228 actionWithTitle:kGSCXScannerWindowCoordinatorTestsSystemAlertCancelTitle229 style:UIAlertActionStyleCancel230 handler:^(UIAlertAction *action) {231 window.hidden = YES;232 [window resignKeyWindow];233 }]];234 window.windowLevel = UIWindowLevelAlert;235 [window makeKeyAndVisible];236 [window.rootViewController presentViewController:alert animated:YES completion:nil];237}238+ (void)dismissMockSystemAlert {239 [[EarlGrey240 selectElementWithMatcher:grey_text(kGSCXScannerWindowCoordinatorTestsSystemAlertCancelTitle)]241 performAction:grey_tap()];242}243+ (void)tapShareReportButton {244 [[EarlGrey245 selectElementWithMatcher:grey_accessibilityID(kGSCXShareReportButtonAccessibilityIdentifier)]246 performAction:grey_tap()];247}248+ (void)tapCancelMockShareReportButton {249 [[EarlGrey selectElementWithMatcher:grey_text(kGSCXTestSharingDelegateAlertDismissTitle)]250 performAction:grey_tap()];251}252+ (void)tapGridButton {253 id<GREYMatcher> gridButtonMatcher =254 grey_accessibilityID(kGSCXContinuousScannerScreenshotGridButtonAccessibilityIdentifier);255 [[EarlGrey selectElementWithMatcher:gridButtonMatcher] performAction:grey_tap()];256}257+ (void)tapGridCellAtIndex:(NSUInteger)index {258 NSString *cellAXId =259 [GSCXContinuousScannerGridViewController accessibilityIdentifierForCellAtIndex:index];260 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(cellAXId)] performAction:grey_tap()];261}262+ (void)tapListButton {263 [[EarlGrey selectElementWithMatcher:264 grey_accessibilityID(265 kGSCXContinuousScannerScreenshotListBarButtonAccessibilityIdentifier)]266 performAction:grey_tap()];267}268+ (void)tapNextContinuousScanResultButton {269 [[EarlGrey270 selectElementWithMatcher:271 grey_accessibilityID(kGSCXContinuousScannerScreenshotNextButtonAccessibilityIdentifier)]272 performAction:grey_tap()];273}274+ (void)tapBackContinuousScanResultButton {275 [[EarlGrey276 selectElementWithMatcher:277 grey_accessibilityID(kGSCXContinuousScannerScreenshotBackButtonAccessibilityIdentifier)]278 performAction:grey_tap()];279}280+ (void)toggleListSectionAtIndex:(NSInteger)sectionIndex {281 id<GREYMatcher> scrollMatcher =282 grey_accessibilityID(kGSCXContinuousScannerListTableViewAccessibilityIdentifier);283 NSString *accessibilityID = [GSCXScannerIssueExpandableTableViewDelegate284 gscx_accessibilityIdentifierForHeaderInSection:sectionIndex];285 id<GREYMatcher> headerMatcher = grey_accessibilityID(accessibilityID);286 [[GSCXScannerTestUtils287 scrollElementWithMatcher:scrollMatcher288 toElementWithMatcher:grey_allOf(headerMatcher, grey_sufficientlyVisible(), nil)]289 performAction:grey_tap()];290}291+ (void)assertListSectionAtIndex:(NSInteger)sectionIndex292 accessibilityTrait:(UIAccessibilityTraits)accessibilityTrait293 exists:(BOOL)exists {294 NSString *headerAccessibilityId = [GSCXScannerIssueExpandableTableViewDelegate295 gscx_accessibilityIdentifierForHeaderInSection:sectionIndex];296 id<GREYMatcher> traitMatcher = grey_accessibilityTrait(accessibilityTrait);297 if (!exists) {298 traitMatcher = grey_not(traitMatcher);299 }300 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(headerAccessibilityId)]301 assertWithMatcher:traitMatcher];302}303+ (void)tapTabBarButtonWithTitle:(NSString *)title {304 Class tabBarButtonClass =305 NSClassFromString([GSCXScannerTestUtils gscxtest_UITabBarButtonClassName]);306 id<GREYMatcher> ancestorMatcher = grey_ancestor(grey_kindOfClass(tabBarButtonClass));307 id<GREYMatcher> titleMatcher = grey_text(title);308 [[EarlGrey selectElementWithMatcher:grey_allOf(ancestorMatcher, titleMatcher, nil)]309 performAction:grey_tap()];310}311+ (GREYElementInteraction *)selectRingViewAtIndex:(NSInteger)index {312 NSString *ringViewAXId = [GSCXRingViewArranger accessibilityIdentifierForRingViewAtIndex:index];313 return [EarlGrey selectElementWithMatcher:grey_accessibilityID(ringViewAXId)];314}315+ (void)assertCarouselSelectedCellAtIndex:(NSInteger)index {316 NSString *value = [GSCXScannerResultCarousel gscx_accessibilityValueAtSelectedIndex:index];317 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(318 kGSCXScannerResultCarouselAccessibilityIdentifier)]319 assertWithMatcher:grey_accessibilityValue(value)];320}321+ (void)assertRingViewCount:(NSInteger)count {322 for (NSInteger i = 0; i < count; i++) {323 [[GSCXScannerTestUtils selectRingViewAtIndex:i] assertWithMatcher:grey_notNil()];324 }325 [[GSCXScannerTestUtils selectRingViewAtIndex:count] assertWithMatcher:grey_nil()];326}327+ (void)assertSettingsButtonIsInteractable:(BOOL)interactable {328 id<GREYMatcher> assertion = [GSCXScannerTestUtils gscxtest_matcherForInteractable:interactable];329 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(330 kGSCXScannerOverlaySettingsButtonAccessibilityIdentifier)]331 assertWithMatcher:assertion];332}333+ (void)assertSettingsButtonIsInteractable:(BOOL)interactable334 error:(NSError *__autoreleasing *)error {335 id<GREYMatcher> assertion = [GSCXScannerTestUtils gscxtest_matcherForInteractable:interactable];336 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(337 kGSCXScannerOverlaySettingsButtonAccessibilityIdentifier)]338 assertWithMatcher:assertion339 error:error];340}341+ (void)assertPerformScanButtonIsInteractable:(BOOL)interactable {342 id<GREYMatcher> assertion = [GSCXScannerTestUtils gscxtest_matcherForInteractable:interactable];343 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(kGSCXPerformScanAccessibilityIdentifier)]344 assertWithMatcher:assertion];345}346+ (void)assertContinuousScanButtonIsInteractable:(BOOL)interactable {347 // UISwitch elements have interactable UIView subviews. This causes348 // gscxtest_matcherForInteractable to match the wrong element. Using grey_interactable matches the349 // switch itself.350 id<GREYMatcher> assertion = interactable ? grey_interactable() : grey_not(grey_interactable());351 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(352 kGSCXSettingsContinuousScanButtonAccessibilityIdentifier)]353 assertWithMatcher:assertion];354}355+ (void)assertLabelForCheckNamed:(NSString *)checkName356 isSufficientlyVisible:(BOOL)isSufficientlyVisible {357 id<GREYMatcher> isVisibleMatcher =358 isSufficientlyVisible ? grey_sufficientlyVisible() : grey_not(grey_sufficientlyVisible());359 id<GREYMatcher> isHiddenMatcher =360 [GSCXScannerTestUtils gscxtest_elementOrAncestorIsHiddenMatcher];361 // In some cases, such as expanding and collapsing sections in the list view, labels are not362 // actually removed from the view hierarchy. The label or an ancestor is made hidden. This causes363 // an ambiguous selection error, because multiple labels with the same text exist in the view364 // hierarchy, even though users can only access one. Ignoring elements that are hidden solves365 // this.366 id<GREYMatcher> labelMatcher = grey_allOf(grey_text(checkName), grey_not(isHiddenMatcher), nil);367 [[EarlGrey selectElementWithMatcher:labelMatcher] assertWithMatcher:isVisibleMatcher];368}369+ (void)assertLabelForCheckNamed:(NSString *)checkName370 isSufficientlyVisible:(BOOL)isSufficientlyVisible371 scrollingElementWithMatcher:(id<GREYMatcher>)scrollMatcher {372 id<GREYMatcher> isVisibleMatcher =373 isSufficientlyVisible ? grey_sufficientlyVisible() : grey_not(grey_sufficientlyVisible());374 id<GREYMatcher> isHiddenMatcher =375 [GSCXScannerTestUtils gscxtest_elementOrAncestorIsHiddenMatcher];376 id<GREYMatcher> labelMatcher =377 grey_allOf(grey_text(checkName), grey_not(isHiddenMatcher), grey_sufficientlyVisible(), nil);378 [[GSCXScannerTestUtils scrollElementWithMatcher:scrollMatcher379 toElementWithMatcher:labelMatcher] assertWithMatcher:isVisibleMatcher];380}381+ (void)assertListSectionCount:(NSInteger)sectionCount {382 id<GREYMatcher> scrollMatcher =383 grey_accessibilityID(kGSCXContinuousScannerListTableViewAccessibilityIdentifier);384 for (NSInteger section = 0; section < sectionCount; section++) {385 NSString *currentAccessibilityID = [GSCXScannerIssueExpandableTableViewDelegate386 gscx_accessibilityIdentifierForHeaderInSection:section];387 [[GSCXScannerTestUtils scrollElementWithMatcher:scrollMatcher388 toElementWithMatcher:grey_accessibilityID(currentAccessibilityID)]389 assertWithMatcher:grey_notNil()];390 }391 NSString *finalAccessibilityID = [GSCXScannerIssueExpandableTableViewDelegate392 gscx_accessibilityIdentifierForHeaderInSection:sectionCount];393 [[GSCXScannerTestUtils scrollElementWithMatcher:scrollMatcher394 toElementWithMatcher:grey_accessibilityID(finalAccessibilityID)]395 assertWithMatcher:grey_nil()];396}397+ (void)assertListRowCount:(NSInteger)rowCount inSection:(NSInteger)section {398 for (NSInteger row = 0; row < rowCount; row++) {399 NSIndexPath *currentIndexPath = [NSIndexPath indexPathForRow:row inSection:section];400 [GSCXScannerTestUtils gscxtest_assertListRowAtIndexPath:currentIndexPath exists:YES];401 }402 NSIndexPath *finalIndexPath = [NSIndexPath indexPathForRow:rowCount inSection:section];403 [GSCXScannerTestUtils gscxtest_assertListRowAtIndexPath:finalIndexPath exists:NO];404}405+ (BOOL)noIssuesFoundItemExists {406 NSError *error = nil;407 [[EarlGrey selectElementWithMatcher:grey_text(kGSCXSettingsNoIssuesFoundText)]408 assertWithMatcher:grey_interactable()409 error:&error];410 return ![GSCXScannerTestUtils gscxtest_isElementNotFoundError:error];411}412+ (BOOL)reportButtonItemExists {413 NSError *error = nil;414 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(415 kGSCXSettingsReportButtonAccessibilityIdentifier)]416 assertWithMatcher:grey_interactable()417 error:&error];418 return ![GSCXScannerTestUtils gscxtest_isElementNotFoundError:error];419}420+ (BOOL)waitForContinuousScan {421 GREYCondition *waitToDismissSettings = [GREYCondition422 conditionWithName:kGSCXContinuousScannerDismissSettingsConditionName423 block:^BOOL {424 NSError *error;425 [GSCXScannerTestUtils assertSettingsButtonIsInteractable:YES error:&error];426 return error == nil;427 }];428 BOOL wasSettingsDismissed =429 [waitToDismissSettings waitWithTimeout:kGSCXContinuousScannerTestsTimeInterval430 pollInterval:kGSCXContinuousScannerTestsPollInterval];431 if (wasSettingsDismissed) {432 [(GSCXTestAppDelegate *)[[GREY_REMOTE_CLASS_IN_APP(UIApplication) sharedApplication] delegate]433 triggerScheduleScanEvent];434 }435 return wasSettingsDismissed;436}437+ (id<GREYMatcher>)isHiddenMatcher {438 return [GREYElementMatcherBlock439 matcherWithMatchesBlock:^BOOL(id element) {440 return [element respondsToSelector:@selector(isHidden)] && [element isHidden];441 }442 descriptionBlock:^(id<GREYDescription> description) {443 [description appendText:@"isHidden is NO, expected YES"];444 }];445}446#pragma mark - Private447/**448 * Returns a @c GREYMatcher instance matching interactable elements if @c interactable is @c YES and449 * non-interactable elements otherwise.450 *451 * @param interactable @c YES if the matcher should match interactable elements, @c NO otherwise.452 * @return A @c GREYMatcher instance matching interactable or non-interactable elements, depending453 * on @c interactable.454 */455+ (id<GREYMatcher>)gscxtest_matcherForInteractable:(BOOL)interactable {456 id<GREYMatcher> interactableHitTestMatcher = [GREYElementMatcherBlock457 matcherWithMatchesBlock:^BOOL(id element) {458 if (![element respondsToSelector:@selector(accessibilityActivationPoint)]) {459 return NO;460 }461 CGPoint activationPoint = [element accessibilityActivationPoint];462 NSArray<UIWindow *> *windows =463 [[GREY_REMOTE_CLASS_IN_APP(UIApplication) sharedApplication] windows];464 // Iterate backwards because the windows are ordered front-to-back. Check the topmost window465 // first, then the second topmost, etc.466 for (NSInteger i = [windows count] - 1; i >= 0; i--) {467 UIView *hitElement = [windows[i] hitTest:activationPoint withEvent:nil];468 if (hitElement != nil) {469 return hitElement == element;470 }471 }472 return NO;473 }474 descriptionBlock:^(id<GREYDescription> description) {475 [description appendText:@"interactable via hitTest:withEvent:"];476 }];477 return (interactable) ? interactableHitTestMatcher : grey_not(interactableHitTestMatcher);478}479/**480 * Determines if an error represents an Earl Grey element not found error.481 *482 * @param error An @c NSError instance. May be @c nil.483 * @return @c YES if the error is not @c nil and represents an Earl Grey element not found error, @c484 * NO otherwise.485 */486+ (BOOL)gscxtest_isElementNotFoundError:(nullable NSError *)error {487 return error && [error.domain isEqualToString:kGREYInteractionErrorDomain] &&488 error.code == kGREYInteractionElementNotFoundErrorCode;489}490/**491 * Asserts that the row in the list view at @c indexPath exists or does not exist. Fails the test if492 * @c exists is @c YES but the row does not exist or @c exists is @c NO but the row does exist.493 *494 * @param indexPath The index path of the row to check if it exists.495 * @param exists @c YES to assert the row exists, @c NO to assert the row does not exist.496 */497+ (void)gscxtest_assertListRowAtIndexPath:(NSIndexPath *)indexPath exists:(BOOL)exists {498 NSString *accessibilityID = [GSCXScannerIssueExpandableTableViewDelegate499 gscx_accessibilityIdentifierForRowAtIndexPath:indexPath];500 // Sometimes, when toggling the section, the rows are not removed from the view hierarchy, but501 // merely made hidden. That should still count as not existing, because as far502 // as the user is concerned, they aren't there. This needs to be included in elementMatcher503 // to avoid disambiguation errors, since sometimes a hidden cell will still be in the view504 // hierarchy alongside an identical non-hidden cell. It needs to be in the assertion matcher505 // because scrollElementWithMatcher returns an interaction instance that doesn't do anything506 // until an assertion is performed.507 id<GREYMatcher> isHiddenMatcher =508 [GSCXScannerTestUtils gscxtest_elementOrAncestorIsHiddenMatcher];509 id<GREYMatcher> disambiguationMatcher = exists ? grey_notNil() : grey_nil();510 id<GREYMatcher> elementMatcher = grey_allOf(511 grey_accessibilityID(accessibilityID), grey_not(isHiddenMatcher), disambiguationMatcher, nil);512 id<GREYMatcher> scrollMatcher =513 grey_accessibilityID(kGSCXContinuousScannerListTableViewAccessibilityIdentifier);514 [[GSCXScannerTestUtils scrollElementWithMatcher:scrollMatcher toElementWithMatcher:elementMatcher]515 assertWithMatcher:disambiguationMatcher];516}517/**518 * @return A matcher for elements whose @c isHidden value or the @c isHidden value of one of their519 * ancestors is @c YES.520 */521+ (id<GREYMatcher>)gscxtest_elementOrAncestorIsHiddenMatcher {522 id<GREYMatcher> isHiddenMatcher = [GSCXScannerTestUtils isHiddenMatcher];523 return grey_anyOf(isHiddenMatcher, grey_ancestor(isHiddenMatcher), nil);524}...
FirebaseAuthEarlGreyTests.m
Source:FirebaseAuthEarlGreyTests.m
...43/** To reset the app so that each test sees the app in a clean state. */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;...
BYOAuthTests.m
Source:BYOAuthTests.m
...31 error:&error];32 if (!customToken) {33 GREYFail(@"There was an error retrieving the custom token: %@", error);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...
DemoAppTests.m
Source:DemoAppTests.m
...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}28void selectView(NSString *name)29{30 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(name)] performAction:grey_tap()];31}...
FIRAuthE2eTests.m
Source:FIRAuthE2eTests.m
...18@end19@implementation FIRAuthE2eTests20- (void)testSignInExistingUser {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...
grey_allOf
Using AI Code Generation
1[[EarlGrey selectElementWithMatcher:grey_allOf(grey_accessibilityLabel(@"Label1"),grey_accessibilityLabel(@"Label2"), nil)] performAction:grey_tap()];2[[EarlGrey selectElementWithMatcher:grey_anyOf(grey_accessibilityLabel(@"Label1"),grey_accessibilityLabel(@"Label2"), nil)] performAction:grey_tap()];3[[EarlGrey selectElementWithMatcher:grey_not(grey_accessibilityLabel(@"Label1"))] performAction:grey_tap()];4[[EarlGrey selectElementWithMatcher:grey_allOf(grey_accessibilityLabel(@"Label1"),grey_accessibilityLabel(@"Label2"), nil)] performAction:grey_tap()];5[[EarlGrey selectElementWithMatcher:grey_anyOf(grey_accessibilityLabel(@"Label1"),grey_accessibilityLabel(@"Label2"), nil)] performAction:grey_tap()];6[[EarlGrey selectElementWithMatcher:grey_not(grey_accessibilityLabel(@"Label1"))] performAction:grey_tap()];7EarlGrey.selectElement(with: grey_allOf(grey_accessibilityLabel("Label1"), grey_accessibilityLabel("Label2"), nil)).perform(grey_tap())8EarlGrey.selectElement(with: grey_anyOf(grey_accessibilityLabel("Label1"), grey_accessibilityLabel("Label2"), nil)).perform(grey_tap())9EarlGrey.selectElement(with: grey_not(grey_accessibilityLabel("Label1"))).perform(grey_tap())10EarlGrey.selectElement(with: grey_allOf(grey_accessibilityLabel("Label1"), grey_accessibilityLabel("Label2"), nil)).perform(grey_tap())
grey_allOf
Using AI Code Generation
1[[EarlGrey selectElementWithMatcher:grey_allOf(grey_accessibilityLabel(@"MyLabel"), grey_accessibilityHint(@"MyHint"), grey_accessibilityValue(@"MyValue"), grey_kindOfClass([UILabel class]), nil)] performAction:grey_tap()];2[[EarlGrey selectElementWithMatcher:grey_allOfMatchers(grey_accessibilityLabel(@"MyLabel"), grey_accessibilityHint(@"MyHint"), grey_accessibilityValue(@"MyValue"), grey_kindOfClass([UILabel class]), nil)] performAction:grey_tap()];3[[EarlGreyImpl sharedEarlGrey] selectElementWithMatcher:grey_allOfMatchers(grey_accessibilityLabel(@"MyLabel"), grey_accessibilityHint(@"MyHint"), grey_accessibilityValue(@"MyValue"), grey_kindOfClass([UILabel class]), nil) performAction:grey_tap()];4[[EarlGrey grey_allOfMatchers:grey_accessibilityLabel(@"MyLabel"), grey_accessibilityHint(@"MyHint"), grey_accessibilityValue(@"MyValue"), grey_kindOfClass([UILabel class]), nil] performAction:grey_tap()];5[[GREYElementInteraction interactionWithMatcher:grey_allOfMatchers(grey_accessibilityLabel(@"MyLabel"), grey_accessibilityHint(@"MyHint"), grey_accessibilityValue(@"MyValue"), grey_kindOfClass([UILabel class]), nil)] performAction:grey_tap()];6[[GREYElementInteraction interactionWithMatcher:grey_allOfMatchers(grey_accessibilityLabel(@"MyLabel"), grey_accessibilityHint(@"MyHint"), grey_accessibilityValue(@"MyValue"), grey_kindOfClass([UILabel class]), nil)] performAction:grey_tap()];7[[GREYElementInteraction interactionWithMatcher:grey_allOfMatchers(grey_accessibilityLabel(@"MyLabel"), grey_accessibilityHint(@"MyHint"), grey_accessibilityValue(@"MyValue"), grey_kindOfClass([UILabel class]), nil)] performAction:grey_tap()];
grey_allOf
Using AI Code Generation
1GREYElementInteraction *interaction = [[EarlGrey selectElementWithMatcher:grey_allOf(grey_accessibilityLabel(@"label"), grey_accessibilityID(@"id"), grey_text(@"text"), nil)] usingSearchAction:grey_scrollInDirection(kGREYDirectionDown, 50.0) onElementWithMatcher:grey_kindOfClass([UIScrollView class])];2- (instancetype)usingSearchAction:(id<GREYSearchAction>)searchAction3 onElementWithMatcher:(id<GREYMatcher>)elementMatcher;4- (instancetype)usingSearchAction:(id<GREYSearchAction>)searchAction5 onElementWithMatcher:(id<GREYMatcher>)elementMatcher6 error:(__strong NSError **)errorOrNil;7- (instancetype)usingSearchAction:(id<GREYSearchAction>)searchAction8 onElementWithMatcher:(id<GREYMatcher>)elementMatcher9 error:(__strong NSError **)errorOrNil10 constraints:(id<GREYMatcher>)constraints;11- (instancetype)usingSearchAction:(id<GREYSearchAction>)searchAction12 onElementWithMatcher:(id<GREYMatcher>)elementMatcher13 error:(__strong NSError **)errorOrNil14 constraints:(id<GREYMatcher>)constraints15 searchFromRoot:(BOOL)searchFromRoot;16- (instancetype)usingSearchAction:(id<GREYSearchAction>)searchAction17 onElementWithMatcher:(id<GREYMatcher>)elementMatcher18 error:(__strong NSError **)errorOrNil19 constraints:(id<GREYMatcher>)constraints20 searchFromRoot:(BOOL)searchFromRoot21 minimumVisiblePercent:(CGFloat)minimumVisiblePercent;
grey_allOf
Using AI Code Generation
1id<GREYMatcher> matcher = grey_allOf(@[2 grey_accessibilityID(@"text_field"),3 grey_sufficientlyVisible(),4 grey_interactable(),5 grey_not(grey_systemAlertViewShown()),6 grey_not(grey_systemKeyboardShown()),7 grey_not(grey_systemAlertViewShown()),8 grey_not(grey_systemKeyboardShown())9 ], nil);10[[EarlGrey selectElementWithMatcher:matcher] performAction:grey_typeText(@"Hello World")];11let matcher = grey_allOf([12 grey_accessibilityID("text_field"),13 grey_sufficientlyVisible(),14 grey_interactable(),15 grey_not(grey_systemAlertViewShown()),16 grey_not(grey_systemKeyboardShown()),17 grey_not(grey_systemAlertViewShown()),18 grey_not(grey_systemKeyboardShown())19EarlGrey.selectElement(with: matcher).perform(grey_typeText("Hello World"))20let matcher = grey_allOf([21 grey_accessibilityID("text_field"),22 grey_sufficientlyVisible(),23 grey_interactable(),24 grey_not(grey_systemAlertViewShown()),25 grey_not(grey_systemKeyboardShown()),26 grey_not(grey_systemAlertViewShown()),27 grey_not(grey_systemKeyboardShown())28EarlGrey.selectElement(with: matcher).perform(grey_typeText("Hello World"))29let matcher = grey_allOf([30 grey_accessibilityID("text_field"),31 grey_sufficientlyVisible(),32 grey_interactable(),33 grey_not(grey_systemAlertViewShown()),34 grey_not(grey_systemKeyboardShown()),35 grey_not(grey_systemAlertViewShown()),36 grey_not(grey_systemKeyboardShown())37EarlGrey.selectElement(with: matcher).perform(grey_typeText("Hello World"))38let matcher = grey_allOf([39 grey_accessibilityID("text_field"),40 grey_sufficientlyVisible(),41 grey_interactable(),42 grey_not(grey_systemAlertViewShown()),43 grey_not(grey_systemKeyboardShown()),
grey_allOf
Using AI Code Generation
1let matcher = grey_allOf([grey_accessibilityLabel("Password"), grey_accessibilityID("Password")])2let passwordTextField = EarlGrey.selectElementWithMatcher(matcher)3let matcher = grey_allOf([grey_accessibilityLabel("Password"), grey_accessibilityID("Password")])4let passwordTextField = EarlGrey.selectElementWithMatcher(matcher)5let matcher = grey_allOf([grey_accessibilityLabel("Password"), grey_accessibilityID("Password")])6let passwordTextField = EarlGrey.selectElementWithMatcher(matcher)7let matcher = grey_allOf([grey_accessibilityLabel("Password"), grey_accessibilityID("Password")])8let passwordTextField = EarlGrey.selectElementWithMatcher(matcher)9let matcher = grey_allOf([grey_accessibilityLabel("Password"), grey_accessibilityID("Password")])10let passwordTextField = EarlGrey.selectElementWithMatcher(matcher)11let matcher = grey_allOf([grey_accessibilityLabel("Password"), grey_accessibilityID("Password")])12let passwordTextField = EarlGrey.selectElementWithMatcher(matcher)13let matcher = grey_allOf([grey_accessibilityLabel("Password"), grey_accessibilityID("Password")])14let passwordTextField = EarlGrey.selectElementWithMatcher(matcher)
grey_allOf
Using AI Code Generation
1let matcher = grey_allOf([grey_accessibilityLabel("Add"),2grey_accessibilityID("Add")])3let addElement = EarlGrey.selectElementWithMatcher(matcher)4addElement.performAction(grey_tap())5let matcher = grey_allOf([grey_accessibilityLabel("Add"),6grey_accessibilityID("Add")])7let addElement = EarlGrey.selectElementWithMatcher(matcher)8addElement.performAction(grey_tap())9let matcher = grey_allOf([grey_accessibilityLabel("Add"),10grey_accessibilityID("Add")])11let addElement = EarlGrey.selectElementWithMatcher(matcher)12addElement.performAction(grey_tap())13let matcher = grey_allOf([grey_accessibilityLabel("Add"),14grey_accessibilityID("Add")])15let addElement = EarlGrey.selectElementWithMatcher(matcher)16addElement.performAction(grey_tap())17let matcher = grey_allOf([grey_accessibilityLabel("Add"),18grey_accessibilityID("Add")])19let addElement = EarlGrey.selectElementWithMatcher(matcher)20addElement.performAction(grey_tap())21let matcher = grey_allOf([grey_accessibilityLabel("Add"),22grey_accessibilityID("Add")])23let addElement = EarlGrey.selectElementWithMatcher(matcher)24addElement.performAction(grey_tap())
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!!