How to use selectElementWithMatcher class

Best EarlGrey code snippet using selectElementWithMatcher

FirebaseAuthEarlGreyTests.m

Source:FirebaseAuthEarlGreyTests.m Github

copy

Full Screen

...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;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...

Full Screen

Full Screen

IntegrationTests.m

Source:IntegrationTests.m Github

copy

Full Screen

...22 }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...

Full Screen

Full Screen

DemoAppTests.m

Source:DemoAppTests.m Github

copy

Full Screen

...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}32void inputText(NSString *labelName, NSString *text)33{34 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(labelName)] performAction:grey_typeText(text)];35}36void assertView(NSString *name)37{38 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(name)] assertWithMatcher:grey_sufficientlyVisible()];39}40void waitForViewWithAccessibility(NSString *view)41{42 NSError *error;43 [[EarlGrey selectElementWithMatcher:grey_firstResponder()] assertWithMatcher:grey_text(view) error:&error];44 if (error) {45 NSLog(@"Error: %@", error);46 }47}48@interface DemoAppTests : XCTestCase <GREYFailureHandler>49@end50@implementation DemoAppTests51- (void)handleException:(GREYFrameworkException *)exception details:(NSString *)details52{53 // Log the failure and state of the app if required.54 // Call thru to XCTFail() with an appropriate error message.55 NSLog(@"Failed test %@", exception);56}57- (void)setInvocationFile:(NSString *)fileName andInvocationLine:(NSUInteger)lineNumber58{59 // Record the file name and line number of the statement which was executing before the60 // failure occurred.61 NSLog(@"Failed %@ at %lu", fileName, (unsigned long)lineNumber);62}63- (void)setUp64{65 [EarlGrey setFailureHandler:self];66}67#pragma mark - Tabs68- (void)testTabBar_demoControllers69{70 selectTab(@"Demo");71 // assertView(@"Action Buttons");72}73- (void)testTabBar_authPage74{75 selectTab(@"OAuth");76 // assertView(@"Log in with Twitter");77}78- (void)testTabBar_teamPage79{80 selectTab(@"Team");81}82#pragma mark - OAuth Tab83- (void)testLoginButton84{85 selectTab(@"OAuth");86 selectView(@"Clear Test Account");87 selectView(@"Log in with Twitter");88 selectView(@"Cancel");89 // TODO: Add tab first item if accounts exist90}91- (void)testCustomLoginButton92{93 selectTab(@"OAuth");94 selectButton(@"Login with Custom Button");95 GREYCondition *waitForWebView = [GREYCondition conditionWithName:@"wait for web view" block:^BOOL {96 return [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Username or email")] assertWithMatcher:grey_notNil()];97 }];98 GREYAssertTrue([waitForWebView waitWithTimeout:3], @"Wait for web view");99}100- (void)testAuth_RemoveAccount101{102 selectTab(@"OAuth");103 selectView(@"Clear Test Account");104 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Accounts in current session")] assertWithMatcher:grey_text(@"")];105}106#pragma mark - Compact Tweets107- (void)testTweets_compact108{109 selectTab(@"Demo");110 selectView(@"Compact Tweets");111 selectView(@"Image Attachment");112 selectView(@"Close");113}114#pragma mark - Regular Tweets115- (void)testTweets_regular116{117 selectTab(@"Demo");118 selectView(@"Regular Tweets");...

Full Screen

Full Screen

selectElementWithMatcher

Using AI Code Generation

copy

Full Screen

1#import <EarlGrey/EarlGrey.h>2#import <EarlGrey/GREYMatchers.h>3GREYElementInteraction *element = [EarlGrey selectElementWithMatcher:grey_accessibilityID(@"test")];4[element assertWithMatcher:grey_sufficientlyVisible()];5GREYElementInteraction *element = [EarlGrey selectElementWithMatcher:grey_accessibilityID(@"test")];6[element assertWithMatcher:grey_sufficientlyVisible()];7GREYElementInteraction *element = [EarlGrey selectElementWithMatcher:grey_accessibilityID(@"test")];8[element assertWithMatcher:grey_sufficientlyVisible()];9GREYElementInteraction *element = [EarlGrey selectElementWithMatcher:grey_accessibilityID(@"test")];10[element assertWithMatcher:grey_sufficientlyVisible()];11GREYElementInteraction *element = [EarlGrey selectElementWithMatcher:grey_accessibilityID(@"test")];12[element assertWithMatcher:grey_sufficientlyVisible()];13GREYElementInteraction *element = [EarlGrey selectElementWithMatcher:grey_accessibilityID(@"test")];14[element assertWithMatcher:grey_sufficientlyVisible()];15GREYElementInteraction *element = [EarlGrey selectElementWithMatcher:grey_accessibilityID(@"test")];16[element assertWithMatcher:grey_sufficientlyVisible()];17GREYElementInteraction *element = [EarlGrey selectElementWithMatcher:grey_accessibilityID(@"test")];18[element assertWithMatcher:grey_sufficientlyVisible()];19GREYElementInteraction *element = [EarlGrey selectElementWithMatcher:grey_accessibilityID(@"test")];20[element assertWithMatcher:grey_sufficientlyVisible()];21GREYElementInteraction *element = [EarlGrey selectElementWithMatcher:grey_accessibilityID(@"test")

Full Screen

Full Screen

selectElementWithMatcher

Using AI Code Generation

copy

Full Screen

1#import <EarlGrey/EarlGrey.h>2+ (void)selectElementWithMatcher:(id<GREYMatcher>)matcher;3#import "EarlGreyHelper.h"4+ (void)selectElementWithMatcher:(id<GREYMatcher>)matcher5{6 [[EarlGrey selectElementWithMatcher:matcher] performAction:grey_tap()];7}8#import "EarlGreyHelper.h"9- (void)viewDidLoad10{11 [super viewDidLoad];12 [EarlGreyHelper selectElementWithMatcher:grey_accessibilityID(@"button")];13}

Full Screen

Full Screen

selectElementWithMatcher

Using AI Code Generation

copy

Full Screen

1#import <Foundation/Foundation.h>2#import <EarlGrey/EarlGrey.h>3+ (void)selectElementWithMatcher:(GREYElementMatcherBlock)elementMatcher;4#import "EarlGreyHelper.h"5+(void)selectElementWithMatcher:(GREYElementMatcherBlock)elementMatcher6{7 [[EarlGrey selectElementWithMatcher:elementMatcher] performAction:grey_tap()];8}9#import "ViewController.h"10#import "EarlGreyHelper.h"11@interface ViewController ()12- (void)viewDidLoad {13 [super viewDidLoad];14}15- (void)didReceiveMemoryWarning {16 [super didReceiveMemoryWarning];17}18- (IBAction)buttonTapped:(id)sender {19 [EarlGreyHelper selectElementWithMatcher:grey_accessibilityLabel(@"Button")];20}

Full Screen

Full Screen

selectElementWithMatcher

Using AI Code Generation

copy

Full Screen

1#import "EarlGrey.h"2#import "GREYMatchers.h"3#import "GREYConfiguration.h"4#import "GREYConfiguration+Private.h"5#import "GREYConstants.h"6#import "GREYDefines.h"7#import "GREYElementInteraction.h"8#import "GREYElementMatcherBlock.h"9#import "GREYHostBackgroundDistantObject.h"10#import "GREYHostBackgroundDistantObject+Private.h"11#import "GREYHostBackgroundDistantObject+GREYTestHelper.h"12#import "GREYHostBackgroundDistantObject+GREYTestHelperPrivate.h"13#import "GREYHostBackgroundDistantObject+GREYTestHelperApp.h"14#import "GREYHostBackgroundDistantObject+GREYTestHelperAppPrivate.h"15#import "GREYHostBackgroundDistantObject+GREYTestHelperApp+GREYTestHelper.h"16#import "GREYHostBackgroundDistantObject+GREYTestHelperApp+GREYTestHelperPrivate.h"17#import "GREYHostBackgroundDistantObject+GREYTestHelperApp+GREYTestHelperApp.h"18#import "GREYHostBackgroundDistantObject+GREYTestHelperApp+GREYTestHelperAppPrivate.h"19#import "GREYHostBackgroundDistantObject+GREYTestHelperApp+GREYTestHelperApp+GREYTestHelper.h"20#import "GREYHostBackgroundDistantObject+GREYTestHelperApp+GREYTestHelperApp+GREYTestHelperPrivate.h"21#import "GREYHostBackgroundDistantObject+GREYTestHelperApp+GREYTestHelperApp+GREYTestHelperApp.h"22#import "GREYHostBackgroundDistantObject+GREYTestHelperApp+GREYTestHelperApp+GREYTestHelperAppPrivate.h"23#import "GREYHostBackgroundDistantObject+GREYTestHelperApp+GREYTestHelperApp+GREYTestHelperApp+GREYTestHelper.h"24#import "GREYHostBackgroundDistantObject+GREYTestHelperApp+GREYTestHelperApp+GREYTestHelperApp+GREYTestHelperPrivate.h"25#import "GREYHostBackgroundDistantObject+GREYTestHelperApp+GREYTestHelperApp+GREYTestHelperApp+GREYTestHelperApp.h"26#import "GREYHostBackgroundDistantObject+GREYTestHelperApp+GREYTestHelperApp+GREYTestHelperApp+GREYTestHelperAppPrivate

Full Screen

Full Screen

selectElementWithMatcher

Using AI Code Generation

copy

Full Screen

1#import <Foundation/Foundation.h>2#import <EarlGrey/EarlGrey.h>3#import <UIKit/UIKit.h>4+ (void)selectElementWithMatcher:(id<GREYMatcher>)matcher;5#import "EarlGreyHelper.h"6+ (void)selectElementWithMatcher:(id<GREYMatcher>)matcher {7 [[EarlGrey selectElementWithMatcher:matcher] performAction:grey_tap()];8}9#import <XCTest/XCTest.h>10#import "EarlGreyHelper.h"11- (void)testSelectElementWithMatcher {12 [EarlGreyHelper selectElementWithMatcher:grey_accessibilityID(@"myButton")];13}

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