Best EarlGrey code snippet using selectElementWithMatcher.grey_sufficientlyVisible
FirebaseAuthEarlGreyTests.m
Source:FirebaseAuthEarlGreyTests.m
...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.137 if (!status) {138 NSLog(@"Error signing out: %@", signOutError);139 }140}141/** Wait for an element with text to appear. */142- (void)waitForElementWithText:(NSString *)text withDelay:(NSTimeInterval)maxDelay {143 GREYCondition *displayed =144 [GREYCondition conditionWithName:@"Wait for element"145 block:^BOOL {146 NSError *error = nil;147 [[EarlGrey selectElementWithMatcher:grey_text(text)]148 assertWithMatcher:grey_sufficientlyVisible()149 error:&error];150 return !error;151 }];152 GREYAssertTrue([displayed waitWithTimeout:maxDelay], @"Failed to wait for element '%@'.", text);153}154@end...
IntegrationTests.m
Source:IntegrationTests.m
...23 return self;24}25- (void)testFullScreenCanPop {26 [[EarlGrey selectElementWithMatcher:grey_keyWindow()]27 assertWithMatcher:grey_sufficientlyVisible()];28 [[EarlGrey selectElementWithMatcher:grey_buttonTitle(@"Full Screen (Cold)")]29 performAction:grey_tap()];30 waitForInitialFlutterRender();31 __weak FlutterViewController* weakViewController;32 @autoreleasepool {33 UINavigationController* navController =34 (UINavigationController*)((AppDelegate*)[35 [UIApplication sharedApplication]36 delegate])37 .window.rootViewController;38 weakViewController =39 (FullScreenViewController*)navController.visibleViewController;40 GREYAssertNotNil(weakViewController, @"Expected non-nil FullScreenViewController.");41 }42 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"POP")] performAction:grey_tap()];43 waitForInitialFlutterRender();44 [[EarlGrey selectElementWithMatcher:grey_buttonTitle(@"Native iOS View")]45 assertWithMatcher:grey_sufficientlyVisible()];46 GREYAssertNil(weakViewController, @"Expected FullScreenViewController to be deallocated.");47}48- (void)testDualFlutterView {49 [[EarlGrey selectElementWithMatcher:grey_keyWindow()]50 assertWithMatcher:grey_sufficientlyVisible()];51 [[EarlGrey selectElementWithMatcher:grey_buttonTitle(@"Dual Flutter View (Cold)")]52 performAction:grey_tap()];53 waitForInitialFlutterRender();54 // Verify that there are two Flutter views with the expected marquee text.55 [[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"This is Marquee")] atIndex:0]56 assertWithMatcher:grey_notNil()];57 [[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"This is Marquee")] atIndex:1]58 assertWithMatcher:grey_notNil()];59 [[EarlGrey selectElementWithMatcher:grey_buttonTitle(@"Back")] performAction:grey_tap()];60 [[EarlGrey selectElementWithMatcher:grey_buttonTitle(@"Native iOS View")]61 assertWithMatcher:grey_sufficientlyVisible()];62}63- (void)testHybridView {64 [[EarlGrey selectElementWithMatcher:grey_keyWindow()]65 assertWithMatcher:grey_sufficientlyVisible()];66 [[EarlGrey selectElementWithMatcher:grey_buttonTitle(@"Hybrid View (Warm)")] performAction:grey_tap()];67 waitForInitialFlutterRender();68 [self validateCountsFlutter:@"Platform" count:0];69 [self validateCountsPlatform:@"Flutter" count:_flutterWarmEngineTaps];70 static const int platformTapCount = 4;71 static const int flutterTapCount = 6;72 for (int i = _flutterWarmEngineTaps; i < flutterTapCount; i++, _flutterWarmEngineTaps++) {73 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Increment via Flutter")]74 performAction:grey_tap()];75 }76 [self validateCountsFlutter:@"Platform" count:0];77 [self validateCountsPlatform:@"Flutter" count:_flutterWarmEngineTaps];78 for (int i = 0; i < platformTapCount; i++) {79 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Increment via iOS")]80 performAction:grey_tap()];81 }82 [self validateCountsFlutter:@"Platform" count:platformTapCount];83 [self validateCountsPlatform:@"Flutter" count:_flutterWarmEngineTaps];84 [[EarlGrey selectElementWithMatcher:grey_buttonTitle(@"Back")] performAction:grey_tap()];85 [[EarlGrey selectElementWithMatcher:grey_buttonTitle(@"Native iOS View")]86 assertWithMatcher:grey_sufficientlyVisible()];87}88/** Validates that the text labels showing the number of button taps match the expected counts. */89- (void)validateCountsFlutter:(NSString*)labelPrefix90 count:(int)flutterCount {91 NSString* flutterCountStr =92 [NSString stringWithFormat:@"%@ button tapped %d times.", labelPrefix, flutterCount];93 // TODO(https://github.com/flutter/flutter/issues/17988): Flutter doesn't expose accessibility94 // IDs, so the best we can do is to search for an element with the text we expect.95 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(flutterCountStr)]96 assertWithMatcher:grey_sufficientlyVisible()];97}98- (void)validateCountsPlatform:(NSString*)labelPrefix count:(int)platformCount {99 NSString* platformCountStr =100 [NSString stringWithFormat:@"%@ button tapped %d times.", labelPrefix, platformCount];101 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"counter_on_iOS")]102 assertWithMatcher:grey_text(platformCountStr)] assertWithMatcher:grey_sufficientlyVisible()];103}104@end...
grey_sufficientlyVisible
Using AI Code Generation
1[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"MyLabel")] assertWithMatcher:grey_sufficientlyVisible()];2[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"MyLabel")] assertWithMatcher:grey_notVisible()];3[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"MyLabel")] assertWithMatcher:grey_sufficientlyVisible()];4[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"MyLabel")] assertWithMatcher:grey_notVisible()];5[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"MyLabel")] assertWithMatcher:grey_sufficientlyVisible()];6[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"MyLabel")] assertWithMatcher:grey_notVisible()];7[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"MyLabel")] assertWithMatcher:grey_sufficientlyVisible()];8[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"MyLabel")] assertWithMatcher:grey_notVisible()];9[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"MyLabel")] assertWithMatcher:grey_sufficientlyVisible()];10[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"MyLabel")] assertWithMatcher:grey_notVisible()];11[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"MyLabel")] assertWithMatcher:grey_sufficientlyVisible()];
grey_sufficientlyVisible
Using AI Code Generation
1GREYElementInteraction *interaction = [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"buttonID")] usingSearchAction:grey_scrollInDirection(kGREYDirectionDown, 200) onElementWithMatcher:grey_accessibilityID(@"scrollViewID")];2[interaction performAction:grey_tap()];3GREYElementInteraction *interaction = [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"buttonID")] usingSearchAction:grey_scrollInDirection(kGREYDirectionDown, 200) onElementWithMatcher:grey_accessibilityID(@"scrollViewID")];4[interaction assertWithMatcher:grey_sufficientlyVisible()];5GREYElementInteraction *interaction = [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"buttonID")] usingSearchAction:grey_scrollInDirection(kGREYDirectionDown, 200) onElementWithMatcher:grey_accessibilityID(@"scrollViewID")];6[interaction assertWithMatcher:grey_sufficientlyVisible()];7GREYElementInteraction *interaction = [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"buttonID")] usingSearchAction:grey_scrollInDirection(kGREYDirectionDown, 200) onElementWithMatcher:grey_accessibilityID(@"scrollViewID")];8[interaction assertWithMatcher:grey_sufficientlyVisible()];9GREYElementInteraction *interaction = [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"buttonID")] usingSearchAction:grey_scrollInDirection(kGREYDirectionDown, 200) onElementWithMatcher:grey_accessibilityID(@"scrollViewID")];10[interaction assertWithMatcher:grey_sufficientlyVisible()];11GREYElementInteraction *interaction = [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"buttonID")] usingSearchAction:grey_scrollInDirection(kGREYDirectionDown, 200) onElementWithMatcher:grey_accessibility
grey_sufficientlyVisible
Using AI Code Generation
1[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"buttonID")] grey_sufficientlyVisible];2[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"buttonID")] grey_sufficientlyVisible];3[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"buttonID")] grey_sufficientlyVisible];4[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"buttonID")] grey_sufficientlyVisible];5[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"buttonID")] grey_sufficientlyVisible];6[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"buttonID")] grey_sufficientlyVisible];7[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"buttonID")] grey_sufficientlyVisible];8[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"buttonID")] grey_sufficientlyVisible];9[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"buttonID")] grey_sufficientlyVisible];10[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"buttonID")] grey_sufficientlyVisible];11[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"buttonID")] grey_sufficientlyVisible];12[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"buttonID")] grey_sufficientlyVisible];13[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"
grey_sufficientlyVisible
Using AI Code Generation
1[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"myButton")] performAction:grey_tap()];2[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"myButton")] assertWithMatcher:grey_sufficientlyVisible()];3[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"myButton")] assertWithMatcher:grey_sufficientlyVisible()];4[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"myButton")] performAction:grey_tap()];5[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"myButton")] assertWithMatcher:grey_sufficientlyVisible()];6[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"myButton")] assertWithMatcher:grey_sufficientlyVisible()];7[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"myButton")] performAction:grey_tap()];8[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"myButton")] assertWithMatcher:grey_sufficientlyVisible()];9[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"myButton")] assertWithMatcher:grey_sufficientlyVisible()];10[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"myButton")] performAction:grey_tap()];11[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"myButton")] assertWithMatcher:grey_sufficientlyVisible()];
grey_sufficientlyVisible
Using AI Code Generation
1[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"button")]2 assertWithMatcher:grey_sufficientlyVisible()];3[[EarlGrey selectElementWithMatcher:grey_allOf(grey_accessibilityID(@"button"),4 grey_sufficientlyVisible(), nil)]5 assertWithMatcher:grey_sufficientlyVisible()];6[[EarlGrey selectElementWithMatcher:grey_allOf(grey_accessibilityID(@"button"),7 grey_sufficientlyVisible(), nil)]8 assertWithMatcher:grey_sufficientlyVisible()];9[[EarlGrey selectElementWithMatcher:grey_allOf(grey_accessibilityID(@"button"),10 grey_sufficientlyVisible(), nil)]11 assertWithMatcher:grey_sufficientlyVisible()];12[[EarlGrey selectElementWithMatcher:grey_allOf(grey_accessibilityID(@"button"),13 grey_sufficientlyVisible(), nil)]14 assertWithMatcher:grey_sufficientlyVisible()];15[[EarlGrey selectElementWithMatcher:grey_allOf(grey_accessibilityID(@"button"),16 grey_sufficientlyVisible(), nil)]17 assertWithMatcher:grey_sufficientlyVisible()];18[[EarlGrey selectElementWithMatcher:grey_allOf(grey_accessibilityID(@"button"),19 grey_sufficientlyVisible(), nil)]20 assertWithMatcher:grey_sufficientlyVisible()];21[[EarlGrey selectElementWithMatcher:grey_allOf(grey_accessibilityID(@"button"),22 grey_sufficientlyVisible(), nil)]23 assertWithMatcher:grey_sufficientlyVisible()];
grey_sufficientlyVisible
Using AI Code Generation
1#import <EarlGrey/EarlGrey.h>2#import "EarlGrey.h"3#import "EarlGreyImpl.h"4#import "GREYHostBackgroundDistantObject+GREYApp.h"5#import "GREYHostBackgroundDistantObject+GREYTestHelper.h"6#import "GREYHostBackgroundDistantObject+GREYConfiguration.h"7#import "GREYHostBackgroundDistantObject+GREYElementInteraction.h"8@interface GREYHostBackgroundDistantObject (GREYElementInteraction)9- (GREYElementInteraction *)selectElementWithMatcher:(id<GREYMatcher>)matcher;10@interface GREYHostBackgroundDistantObject (GREYTestHelper)11- (void)setElementMatcherBlock:(id<GREYMatcher>(^)(void))elementMatcherBlock;12@interface GREYHostBackgroundDistantObject (GREYApp)13- (BOOL)grey_isAppActive;14- (void)grey_activateApp;15@interface GREYHostBackgroundDistantObject (GREYConfiguration)16- (void)setConfigurationValue:(id)value forConfigKey:(NSString *)key;17@interface GREYHostBackgroundDistantObject (GREYConfiguration)18- (void)setConfigurationValue:(id)value forConfigKey:(NSString *)key;19@interface GREYHostBackgroundDistantObject (GREYElementInteraction)20- (GREYElementInteraction *)selectElementWithMatcher:(id<GREYMatcher>)matcher;21@interface GREYHostBackgroundDistantObject (GREYTestHelper)22- (void)setElementMatcherBlock:(id<GREYMatcher>(^)(void))elementMatcherBlock;23@interface GREYHostBackgroundDistantObject (GREYApp)24- (BOOL)grey_isAppActive;25- (void)grey_activateApp;26@interface GREYHostBackgroundDistantObject (GREYConfiguration)27- (void)setConfigurationValue:(id)value forConfigKey:(NSString *)key;28@interface GREYHostBackgroundDistantObject (GREYConfiguration)29- (void)setConfigurationValue:(id)value forConfigKey:(NSString *)key;30@interface GREYHostBackgroundDistantObject (GREYElementInteraction)31- (GREYElementInteraction *)selectElementWithMatcher:(id<GREYMatcher>)matcher;32@interface GREYHostBackgroundDistantObject (GREYTestHelper)33- (void)setElementMatcherBlock:(id<GREYMatcher>(^)(void))elementMatcher
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!!