How to use grey_accessibilityID method of selectElementWithMatcher class

Best EarlGrey code snippet using selectElementWithMatcher.grey_accessibilityID

GSCXScannerTestUtils.m

Source:GSCXScannerTestUtils.m Github

copy

Full Screen

...90+ (void)openPage:(Class<GSCXTestPage>)pageClass {91 NSString *accessibilityId =92 [GSCXTestViewController accessibilityIdentifierOfCellForPage:pageClass];93 [[GSCXScannerTestUtils scrollElementWithMatcher:grey_kindOfClass([UITableView class])94 toElementWithMatcher:grey_accessibilityID(accessibilityId)]95 performAction:grey_tap()];96}97+ (GREYElementInteraction *)scrollElementWithMatcher:(id<GREYMatcher>)scrollMatcher98 toElementWithMatcher:(id<GREYMatcher>)elementMatcher {99 // Matches scrollable elements whose content size is greater than its frame in at least one100 // dimension. If not, the element cannot scroll, because all of its content is already visible.101 // In this case, there's no reason to trigger a scroll interaction, and elementMatcher can be102 // matched directly.103 id<GREYMatcher> canScrollMatcher = [GREYElementMatcherBlock104 matcherWithMatchesBlock:^BOOL(id element) {105 if (![element respondsToSelector:@selector(bounds)] ||106 ![element respondsToSelector:@selector(contentSize)]) {107 return NO;108 }109 CGRect bounds = [element bounds];110 CGSize contentSize = [element contentSize];111 if ([element respondsToSelector:@selector(contentInset)]) {112 bounds = UIEdgeInsetsInsetRect(bounds, [element contentInset]);113 }114 return CGRectGetWidth(bounds) < contentSize.width ||115 CGRectGetWidth(bounds) < contentSize.height;116 }117 descriptionBlock:^(id<GREYDescription> description) {118 [description appendText:@"Content size is not greater than frame."];119 }];120 NSError *scrollError = nil;121 [[EarlGrey selectElementWithMatcher:scrollMatcher] assertWithMatcher:canScrollMatcher122 error:&scrollError];123 if (scrollError != nil) {124 return [EarlGrey selectElementWithMatcher:elementMatcher];125 }126 NSError *error = nil;127 [[EarlGrey selectElementWithMatcher:elementMatcher] assertWithMatcher:elementMatcher128 error:&error];129 if (error == nil) {130 // The element could be found without scrolling, no need to continue.131 return [EarlGrey selectElementWithMatcher:elementMatcher];132 }133 // The view is probably not visible, scroll to bottom of the table view and go searching for it.134 // Start at the bottom instead of the top because tests often assert on items sequentially in135 // navigation order. If this went top to bottom, the next item would always be barely off screen,136 // causing the tests to have to scroll all the way to the top and all the way down to the desired137 // element each search. If the desired element is beneath the previous element, it's more likely138 // to be found quickly by the search, and it's more likely the next element will already be on139 // screen. This isn't faster in all cases, but it's a good hueristic.140 //141 // Scroll a percentage of the screen to scale scroll amount with screen size without skipping142 // portions of the scroll view contents.143 CGFloat scrollAmount =144 [[UIScreen mainScreen] bounds].size.height * kGSCXScannerTestUtilsScreenHeightScrollFactor;145 [[EarlGrey selectElementWithMatcher:scrollMatcher]146 performAction:grey_scrollToContentEdge(kGREYContentEdgeBottom)];147 return [[EarlGrey selectElementWithMatcher:elementMatcher]148 usingSearchAction:grey_scrollInDirection(kGREYDirectionUp, scrollAmount)149 onElementWithMatcher:scrollMatcher];150}151+ (void)tapSettingsButton {152 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(153 kGSCXScannerOverlaySettingsButtonAccessibilityIdentifier)]154 performAction:grey_tap()];155}156+ (void)dismissSettingsPage {157 [[EarlGrey158 selectElementWithMatcher:grey_accessibilityID(kGSCXDismissSettingsAccessibilityIdentifier)]159 performAction:grey_tap()];160}161+ (void)tapPerformScanButton {162 [self tapSettingsButton];163 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(kGSCXPerformScanAccessibilityIdentifier)]164 performAction:grey_tap()];165}166+ (void)tapStartContinuousScanningButton {167 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(168 kGSCXSettingsContinuousScanButtonAccessibilityIdentifier)]169 performAction:grey_longPress()];170}171+ (void)tapReportButton {172 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(173 kGSCXSettingsReportButtonAccessibilityIdentifier)]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}525/**526 * @return The name of the class of the button that toggles which view controller is visible in a527 * tab bar controller for the current iOS version. This is a private class, so it must be referred...

Full Screen

Full Screen

EarlGreyExampleTests.m

Source:EarlGreyExampleTests.m Github

copy

Full Screen

...28@end29@implementation EarlGreyExampleTests30- (void)testBasicSelection {31 // Select the button with Accessibility ID "clickMe".32 [EarlGrey selectElementWithMatcher:grey_accessibilityID(@"ClickMe")];33}34- (void)testBasicSelectionAndAction {35 // Select and tap the button with Accessibility ID "clickMe".36 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"ClickMe")]37 performAction:grey_tap()];38}39- (void)testBasicSelectionAndAssert {40 // Select the button with Accessibility ID "clickMe" and assert it's visible.41 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"ClickMe")]42 assertWithMatcher:grey_sufficientlyVisible()];43}44- (void)testBasicSelectionActionAssert {45 // Select and tap the button with Accessibility ID "clickMe", then assert it's visible.46 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"ClickMe")]47 performAction:grey_tap()]48 assertWithMatcher:grey_sufficientlyVisible()];49}50- (void)testSelectionOnMultipleElements {51 // This test will fail because both buttons are visible and match the selection.52 // We add a custom error here to prevent the Test Suite failing.53 NSError *error;54 [[EarlGrey selectElementWithMatcher:grey_sufficientlyVisible()]55 performAction:grey_tap() error:&error];56 if (error) {57 NSLog(@"Test Failed with Error : %@", [error description]);58 }59}60- (void)testCollectionMatchers {61 id<GREYMatcher> visibleSendButtonMatcher =62 grey_allOf(grey_accessibilityID(@"ClickMe"), grey_sufficientlyVisible(), nil);63 [[EarlGrey selectElementWithMatcher:visibleSendButtonMatcher]64 performAction:grey_doubleTap()];65}66- (void)testWithInRoot {67 // Second way to disambiguate: use inRoot to focus on a specific window or container.68 // There are two buttons with accessibility id "Send", but only one is inside SendMessageView.69 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Send")]70 inRoot:grey_kindOfClass([SendMessageView class])]71 performAction:grey_doubleTap()];72}73// Define a custom matcher for table cells that contains a date for a Thursday.74- (id<GREYMatcher>)matcherForThursdays {75 MatchesBlock matches = ^BOOL(UIView *cell) {76 if ([cell isKindOfClass:[UITableViewCell class]]) {77 NSDateFormatter *formatter = [[NSDateFormatter alloc] init];78 formatter.dateStyle = NSDateFormatterLongStyle;79 NSDate *date = [formatter dateFromString:[[(UITableViewCell *)cell textLabel] text]];80 if (!date) {81 return NO;82 }83 NSCalendar *calendar = [NSCalendar currentCalendar];84 NSInteger weekday = [calendar component:NSCalendarUnitWeekday fromDate:date];85 return weekday == 5;86 } else {87 return NO;88 }89 };90 DescribeToBlock describe = ^void(id<GREYDescription> description) {91 [description appendText:@"Date for a Thursday"];92 };93 return [[GREYElementMatcherBlock alloc] initWithMatchesBlock:matches94 descriptionBlock:describe];95}96- (void)testWithCustomMatcher {97 // Use the custom matcher.98 [[EarlGrey selectElementWithMatcher:[self matcherForThursdays]]99 performAction:grey_doubleTap()];100}101- (void)testTableCellOutOfScreen {102 // Go find one cell out of the screen.103 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Cell30")]104 usingSearchAction:grey_scrollInDirection(kGREYDirectionDown, 50)105 onElementWithMatcher:grey_accessibilityID(@"table")]106 performAction:grey_doubleTap()];107 // Move back to top of the table.108 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Cell1")]109 usingSearchAction:grey_scrollInDirection(kGREYDirectionUp, 500)110 onElementWithMatcher:grey_accessibilityID(@"table")]111 performAction:grey_doubleTap()];112}113- (void)testCatchErrorOnFailure {114 // TapMe doesn't exist, but the test doesn't fail because we are getting a pointer to the error.115 NSError *error;116 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TapMe")]117 performAction:grey_tap() error:&error];118 if (error) {119 NSLog(@"Error: %@", [error localizedDescription]);120 }121}122// Fade in and out an element.123- (void)fadeInAndOut:(UIView *)element {124 [UIView animateWithDuration:1.0125 delay:0.0126 options:UIViewAnimationOptionCurveEaseOut127 animations: ^{128 element.alpha = 0.0;}129 completion: ^(BOOL finished) {130 [UIView animateWithDuration:1.0131 delay:0.0132 options:UIViewAnimationOptionCurveEaseIn133 animations: ^{134 element.alpha = 1.0;}135 completion: nil];136 }];137}138// Define a custom action that applies fadeInAndOut to the selected element.139- (id<GREYAction>)tapClickMe {140 return [GREYActionBlock actionWithName:@"Fade In And Out"141 constraints:nil142 performBlock: ^(id element, NSError *__strong *errorOrNil) {143 // First make sure element is attached to a window.144 if ([element window] == nil) {145 NSDictionary *errorInfo = @{146 NSLocalizedDescriptionKey:147 NSLocalizedString(@"Element is not attached to a window", @"")};148 *errorOrNil = [NSError errorWithDomain:kGREYInteractionErrorDomain149 code:1150 userInfo:errorInfo];151 return NO;152 } else {153 [self fadeInAndOut:[element window]];154 return YES;155 }156 }];157}158- (void)testCustomAction {159 // Test using the custom action tapClickMe.160 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"ClickMe")]161 performAction:[self tapClickMe]];162}163// Write a custom assertion that checks if the alpha of an element is equal to the expected value.164- (id<GREYAssertion>)alphaEqual:(CGFloat)expectedAlpha {165 return [GREYAssertionBlock assertionWithName:@"Assert Alpha Equal"166 assertionBlockWithError:^BOOL(UIView *element,167 NSError *__strong *errorOrNil) {168 // Assertions can be performed on nil elements. Make sure view isn’t nil.169 if (element == nil) {170 *errorOrNil =171 [NSError errorWithDomain:kGREYInteractionErrorDomain172 code:kGREYInteractionElementNotFoundErrorCode173 userInfo:nil];174 return NO;175 }176 return element.alpha == expectedAlpha;177 }];178}179- (void)testWithCustomAssertion {180 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"ClickMe")]181 assert:([self alphaEqual:1.0])];182}183- (void)testWithCustomFailureHandler {184 // This test will fail and use our custom handler to handle the failure.185 // The custom handler is defined at the beginning of this file.186 PrintOnlyHandler *myHandler = [[PrintOnlyHandler alloc] init];187 [EarlGrey setFailureHandler:myHandler];188 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TapMe")]189 performAction:(grey_tap())];190}191- (void)testLayout {192 // Define a layout constraint.193 GREYLayoutConstraint *onTheRight =194 [GREYLayoutConstraint layoutConstraintWithAttribute:kGREYLayoutAttributeLeft195 relatedBy:kGREYLayoutRelationGreaterThanOrEqual196 toReferenceAttribute:kGREYLayoutAttributeRight197 multiplier:1.0198 constant:0.0];199 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"SendForLayoutTest")]200 assertWithMatcher:grey_layout(@[onTheRight], grey_accessibilityID(@"ClickMe"))];201}202- (void)testWithCondition {203 GREYCondition *myCondition = [GREYCondition conditionWithName: @"Example condition" block: ^BOOL {204 int i = 1;205 while (i <= 100000) {206 i++;207 }208 return YES;209 }];210 // Wait for my condition to be satisfied or timeout after 5 seconds.211 BOOL success = [myCondition waitWithTimeout:5];212 if (!success) {213 // Just printing for the example.214 NSLog(@"Condition not met");215 } else {216 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"ClickMe")]217 performAction:grey_tap()];218 }219}220@end...

Full Screen

Full Screen

MDCCollectionViewControllerTests.m

Source:MDCCollectionViewControllerTests.m Github

copy

Full Screen

...56 direction:(GREYDirection)direction57 withStep:(NSInteger)step58 tap:(BOOL)tap {59 id<GREYMatcher> targetMatcher = grey_allOfMatchers(60 @[ grey_accessibilityID(identifier), grey_sufficientlyVisible(), grey_interactable() ]);61 id<GREYMatcher> scrollableMatcher = grey_accessibilityID(scrollableIdentifier);62 [MDCCollectionViewControllerTests scrollToElementWithMatcher:targetMatcher63 inElementWithMatcher:scrollableMatcher64 direction:direction65 withStep:step66 action:tap ? grey_tap() : nil];67}68/**69 Navigates to a specific Example screen given an array of "breadcrumb" identifiers.70 @param breadcrumbs an array of identifiers for the example to open.71 @note Only the first two elements are currently handled.72 */73+ (void)jumpToExampleWithBreadcrumbs:(NSArray<NSString *> *)breadcrumbs {74 NSAssert(breadcrumbs.count >= 2, @"Breadcrumb paths must be at least 2 elements.");75 [MDCCollectionViewControllerTests scrollToElementWithIdentifier:breadcrumbs[0]76 inElementWithIdentifier:@"collectionView"77 direction:kGREYDirectionDown78 withStep:-179 tap:YES];80 [MDCCollectionViewControllerTests81 scrollToElementWithIdentifier:[NSString stringWithFormat:@"Cell%@", breadcrumbs[1]]82 inElementWithIdentifier:[NSString stringWithFormat:@"Table%@", breadcrumbs[0]]83 direction:kGREYDirectionDown84 withStep:-185 tap:YES];86}87/**88 Navigates back to the main screen from the Custom Section Insets example screen.89 */90+ (void)returnToMainScreen {91 // Leave the Custom Section Insets view92 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"back_bar_button")]93 performAction:grey_tap()];94 // Leave the Collections view95 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"back_bar_button")]96 performAction:grey_tap()];97 // Scroll to the top of the main screen98 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"collectionView")]99 performAction:grey_scrollToContentEdge(kGREYContentEdgeTop)];100}101#pragma mark - Property accessors102/**103 Returns a GREYActionBlock that retrieves the @c numberOfSections property value from a104 UICollectionView.105 @param numberOfSections inout parameter for storing the number of sections value.106 */107+ (GREYActionBlock *)getNumberOfSections:(NSInteger *)numberOfSections {108 return [GREYActionBlock109 actionWithName:@"getNumberOfSectionsFromUICollectionView"110 constraints:grey_respondsToSelector(@selector(numberOfSections))111 performBlock:^BOOL(UICollectionView *collectionView, NSError *__strong *errorOrNil) {112 *numberOfSections = collectionView.numberOfSections;113 return YES;114 }];115}116/**117 Returns a GREYActionBlock that retrieves the @c bounds property value from a UIView.118 @param bounds inout parameter for storing the bounds value.119 */120+ (GREYActionBlock *)getBounds:(CGRect *)bounds {121 return [GREYActionBlock actionWithName:@"getBoundsFromUIView"122 constraints:grey_respondsToSelector(@selector(bounds))123 performBlock:^BOOL(UIView *view, NSError *__strong *errorOrNil) {124 *bounds = view.bounds;125 return YES;126 }];127}128#pragma mark - EarlGrey assertions129/**130 Returns a GREYAssertionBlock that will XCTAssert that the selected element's bounds width is less131 than or equal to the passed width.132 @param width the width value for comparison.133 */134- (GREYAssertionBlock *)assertBoundsWidthLessThan:(CGFloat)width {135 return136 [GREYAssertionBlock assertionWithName:@"boundsAreGreaterOrEqualThanOtherBounds"137 assertionBlockWithError:^BOOL(UIView *element, NSError *__strong *errorOrNil) {138 XCTAssertLessThan(element.bounds.size.width, width,139 @"View's width is not less than or equal to the expected "140 "width.");141 return YES;142 }];143}144#pragma mark - Tests145/**146 Tests that the width of the bounds of each section is less than the width of the bounds of the one147 above (before) it.148 */149- (void)testEachSectionWidthLessThanSectionAbove {150 [MDCCollectionViewControllerTests151 jumpToExampleWithBreadcrumbs:@[ @"Collections", @"Custom Section Insets" ]];152 // Get the number of sections in the example collection view153 NSInteger totalSections;154 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(155 @"collectionsCustomSectionInsetsCollectionView")]156 performAction:[MDCCollectionViewControllerTests getNumberOfSections:&totalSections]];157 // Step through each section and confirm that the bounds are no greater than the one above it158 CGRect bounds = CGRectMake(0, 0, CGFLOAT_MAX, CGFLOAT_MAX);159 for (int section = 0; section < totalSections; ++section) {160 NSString *cellIdentifier = [NSString stringWithFormat:@"%d.0", section];161 [MDCCollectionViewControllerTests162 scrollToElementWithIdentifier:cellIdentifier163 inElementWithIdentifier:@"collectionsCustomSectionInsetsCollectionView"164 direction:kGREYDirectionDown165 withStep:-1166 tap:NO];167 [MDCCollectionViewControllerTests168 scrollToElementWithMatcher:grey_allOfMatchers(@[169 grey_kindOfClass([UISwitch class]), grey_ancestor(grey_accessibilityID(cellIdentifier)),170 grey_sufficientlyVisible(), grey_interactable()171 ])172 inElementWithMatcher:grey_accessibilityID(173 @"collectionsCustomSectionInsetsCollectionView")174 direction:kGREYDirectionDown175 withStep:-1176 action:grey_turnSwitchOn(YES)];177 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(cellIdentifier)]178 assert:[self assertBoundsWidthLessThan:bounds.size.width]]179 performAction:[MDCCollectionViewControllerTests getBounds:&bounds]];180 }181 [MDCCollectionViewControllerTests returnToMainScreen];182}183@end...

Full Screen

Full Screen

PerfContollerTests.m

Source:PerfContollerTests.m Github

copy

Full Screen

...43 [[EarlGrey selectElementWithMatcher:grey_keyWindow()]44 assertWithMatcher:grey_sufficientlyVisible()];45}46- (void)testTraceStages {47 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TracesTab")] performAction:grey_tap()];48 NSString *addTraceAccessibilityId =49 [GREY_REMOTE_CLASS_IN_APP(TracesViewController) addTraceAccessibilityItem].accessibilityID;50 [self tapElementWithMatcher:grey_accessibilityID(addTraceAccessibilityId)];51 [self tapStageButtonNTimes:kStagesCount];52 [self tapCountButtonsNTimes:kCounterTaps];53 NSString *stopAccessibilityId =54 [GREY_REMOTE_CLASS_IN_APP(PerfTraceView) stopAccessibilityItemWithTraceName:kTraceName]55 .accessibilityID;56 [self tapElementWithMatcher:grey_accessibilityID(stopAccessibilityId)];57}58- (void)testPerfURLConnectionWithDelegateClassInit {59 [self tapAndCheckConnectionTypeWithName:@"PerfURLConnectionWithDelegateClassInit"];60}61- (void)testPerfURLConnectionWithDelegate {62 [self tapAndCheckConnectionTypeWithName:@"PerfURLConnectionWithDelegate"];63}64- (void)testPerfURLConnectionWithDelegateStartImmediately {65 [self tapAndCheckConnectionTypeWithName:@"PerfURLConnectionWithDelegateStartImmediately"];66}67- (void)testPerfURLConnectionAsyncRequest {68 [self tapAndCheckConnectionTypeWithName:@"PerfURLConnectionAsyncRequest"];69}70- (void)testPerfURLSessionDownloadTaskWithDelegate {71 [self tapAndCheckConnectionTypeWithName:@"PerfURLSessionDownloadTaskWithDelegate"];72}73- (void)testPerfURLSessionDataTaskWithDelegate {74 [self tapAndCheckConnectionTypeWithName:@"PerfURLSessionDataTaskWithDelegate"];75}76- (void)testPerfURLSessionDownloadTask {77 [self tapAndCheckConnectionTypeWithName:@"PerfURLSessionDownloadTask"];78}79- (void)testPerfURLSessionDataTask {80 [self tapAndCheckConnectionTypeWithName:@"PerfURLSessionDataTask"];81}82#pragma mark - Private methods83- (void)tapAndCheckConnectionTypeWithName:(NSString *)connectionName {84 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"RequestsTab")]85 performAction:grey_tap()];86 NSString *conditionName =87 [NSString stringWithFormat:@"Check if %@ button visible", connectionName];88 GREYCondition *conditionForElement = [GREYCondition89 conditionWithName:conditionName90 block:^BOOL {91 NSError *error;92 [[EarlGrey selectElementWithMatcher:grey_buttonTitle(connectionName)]93 assertWithMatcher:grey_sufficientlyVisible()94 error:&error];95 return (error == nil);96 }];97 BOOL elementAppeared = [conditionForElement waitWithTimeout:1];98 if (!elementAppeared) {99 GREYElementInteraction *scrollViewInteractor =100 [EarlGrey selectElementWithMatcher:grey_accessibilityID(@"RequestsScrollView")];101 [scrollViewInteractor performAction:grey_swipeFastInDirection(kGREYDirectionUp)];102 }103 [self tapElementWithMatcher:grey_buttonTitle(connectionName)];104 AccessibilityItem *item = [GREY_REMOTE_CLASS_IN_APP(NetworkConnectionViewController)105 statusLabelAccessibilityItemWithConnectionName:connectionName];106 BOOL (^conditionBlock)(void) = ^BOOL {107 NSError *error = nil;108 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(item.accessibilityID)]109 assertWithMatcher:grey_anyOf(grey_text(@"Success"), grey_text(@"Fail"), nil)110 error:&error];111 if (error) {112 NSLog(@"EarlGrey synchronization: status label hasn't been updated yet");113 }114 return error == nil;115 };116 BOOL succeeded = [[GREYCondition conditionWithName:@"Wait for status label to change text"117 block:conditionBlock] waitWithTimeout:30];118 XCTAssertTrue(succeeded);119 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(item.accessibilityID)]120 assertWithMatcher:grey_text(@"Success")];121}122- (void)tapCountButtonsNTimes:(NSUInteger)tapsCount {123 for (int counterTapNumber = 0; counterTapNumber < tapsCount; counterTapNumber++) {124 NSString *counterAccessibilityID = counterTapNumber % 2 == 1125 ? [GREY_REMOTE_CLASS_IN_APP(PerfTraceView)126 metricOneAccessibilityItemWithTraceName:kTraceName]127 .accessibilityID128 : [GREY_REMOTE_CLASS_IN_APP(PerfTraceView)129 metricTwoAccessibilityItemWithTraceName:kTraceName]130 .accessibilityID;131 [self tapElementWithMatcher:grey_accessibilityID(counterAccessibilityID)];132 }133}134- (void)tapElementWithMatcher:(id<GREYMatcher>)matcher {135 [[EarlGrey selectElementWithMatcher:matcher] performAction:grey_tap()];136}137- (void)tapStageButtonNTimes:(NSUInteger)tapsCount {138 NSString *stageAccessibilityId =139 [GREY_REMOTE_CLASS_IN_APP(PerfTraceView) stageAccessibilityItemWithTraceName:kTraceName]140 .accessibilityID;141 for (int stageNumber = 0; stageNumber < tapsCount; stageNumber++) {142 [self tapElementWithMatcher:grey_accessibilityID(stageAccessibilityId)];143 }144}145@end...

Full Screen

Full Screen

CreateAccountPage.m

Source:CreateAccountPage.m Github

copy

Full Screen

...15static NSString *const password = @"RMBAutomationProfileTextFieldPassword";16static NSString *const createAccountButton = @"RMBAutomationProfileButtonSubmit";17static NSString *const birthDateField = @"RMBAutomationProfileDropdownDateOfBirth";18- (StarRewardsPage *) createAccountForUser: (User *) user {19 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(nameField)] performAction:grey_clearText()];20 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(nameField)] performAction:grey_typeText(user.name)];21 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(surnameField)] performAction:grey_clearText()];22 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(surnameField)] performAction:grey_typeText(user.surname)];23 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(emailField)] performAction:grey_clearText()];24 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(emailField)] performAction:grey_typeText(user.email)];25 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(password)] performAction:grey_clearText()];26 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(password)] performAction:grey_typeText(user.password)];27 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"RMBAutomationKeyboardControlsDone")] performAction:grey_tap()];28 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(birthDateField)] performAction:grey_tap()];29 30 XCUIApplication *application = [[XCUIApplication alloc] init];31 [[application.pickerWheels elementBoundByIndex:0] adjustToPickerWheelValue:@"March"];32 [[application.pickerWheels elementBoundByIndex:1] adjustToPickerWheelValue:@"4"];33 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"RMBAutomationKeyboardControlsDone")] performAction:grey_tap()];34 35 [application swipeUp];36 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(createAccountButton)] performAction:grey_tap()];37 return [[StarRewardsPage alloc] init];38}39@end...

Full Screen

Full Screen

SnackbarInteractionTests.m

Source:SnackbarInteractionTests.m Github

copy

Full Screen

...16@end17@implementation SnackbarEarlGreyTests18+ (void)returnToMainScreen {19 // Leave the Demo view20 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"back_bar_button")]21 performAction:grey_tap()];22 // Leave the Snackbar view23 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"back_bar_button")]24 performAction:grey_tap()];25 // Scroll to the top of the main screen26 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"collectionView")]27 performAction:grey_scrollToContentEdge(kGREYContentEdgeTop)];28}29- (void)testSliding {30 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"collectionView")]31 performAction:grey_scrollToContentEdge(kGREYContentEdgeBottom)];32 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Snackbar")] performAction:grey_tap()];33 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CellDemo")] performAction:grey_tap()];34 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Simple Snackbar")]35 performAction:grey_tap()];36 [SnackbarEarlGreyTests returnToMainScreen];37}38@end...

Full Screen

Full Screen

SignInPage.m

Source:SignInPage.m Github

copy

Full Screen

...13static NSString *const emailField = @"kSignInLoginFieldIdentifier";14static NSString *const passwordField = @"kSignInPasswordFieldIdentifier";15static NSString *const signInButton = @"kSignInButton";16- (void) clickOnSignInButton {17 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(signInButton)] performAction:grey_tap()];18}19- (CreateAccountPage *) clickOnAccountButton{20 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(createAccountButton)] performAction:grey_tap()];21 return [[CreateAccountPage alloc] init];22}23- (void) logInWithEmail: (NSString *) email password:(NSString *) password {24 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(emailField)] performAction:grey_clearText()];25 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(emailField)] performAction:grey_typeText(email)];26 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(passwordField)] performAction:grey_typeText(password)];27 [self clickOnSignInButton];28}29@end...

Full Screen

Full Screen

MyFirstEarlGrey2ObjCTest.m

Source:MyFirstEarlGrey2ObjCTest.m Github

copy

Full Screen

...13 XCUIApplication *application = [[XCUIApplication alloc] init];14 [application launch];15}16- (void)test_preconditions {17 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CountLabel")] assertWithMatcher:grey_sufficientlyVisible()];18 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CountLabel")] assertWithMatcher:grey_text(@"0")];19 20 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"IncrementCountButton")] assertWithMatcher:grey_sufficientlyVisible()];21 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"IncrementCountButton")] assertWithMatcher:grey_text(@"Increment Count")];22}23- (void)test_tapping_the_increment_count_button_increments_the_value_in_the_count_label {24 // When.25 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"IncrementCountButton")] performAction:grey_tap()];26 27 // Then.28 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CountLabel")] assertWithMatcher:grey_text(@"1")];29}30@end...

Full Screen

Full Screen

grey_accessibilityID

Using AI Code Generation

copy

Full Screen

1[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"id")] performAction:grey_tap()];2[[EarlGrey selectElementWithMatcher:grey_text(@"text")] performAction:grey_tap()];3[[EarlGrey selectElementWithMatcher:grey_text(@"text")] performAction:grey_tap()];4[[EarlGrey selectElementWithMatcher:grey_text(@"text")] performAction:grey_tap()];5[[EarlGrey selectElementWithMatcher:grey_text(@"text")] performAction:grey_tap()];6[[EarlGrey selectElementWithMatcher:grey_text(@"text")] performAction:grey_tap()];7[[EarlGrey selectElementWithMatcher:grey_text(@"text")] performAction:grey_tap()];8[[EarlGrey selectElementWithMatcher:grey_text(@"text")] performAction:grey_tap()];9[[EarlGrey selectElementWithMatcher:grey_text(@"text")] performAction:grey_tap()];10[[EarlGrey selectElementWithMatcher:grey_text(@"text")] performAction:grey_tap()];11[[EarlGrey selectElementWithMatcher:grey_text(@"text")] performAction:grey_tap()];12[[EarlGrey selectElementWithMatcher:grey_text(@"text")] performAction:grey_tap()];13[[EarlGrey selectElementWithMatcher:grey_text(@"text")] performAction:grey_tap()];14[[EarlGrey selectElementWithMatcher:grey_text(@"text")] performAction:grey_tap()];

Full Screen

Full Screen

grey_accessibilityID

Using AI Code Generation

copy

Full Screen

1[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"loginButton")] performAction:grey_tap() error:nil];2[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"loginButton")] performAction:grey_tap() error:nil];3[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"loginButton")] performAction:grey_tap() error:nil];4[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"loginButton")] performAction:grey_tap() error:nil];5[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"loginButton")] performAction:grey_tap() error:nil];6[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"loginButton")] performAction:grey_tap() error:nil];7[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"loginButton")] performAction:grey_tap() error:nil];8[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"loginButton")] performAction:grey_tap() error:nil];9[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"loginButton")] performAction:grey_tap() error:nil];10[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"loginButton")] performAction:grey_tap() error:nil];

Full Screen

Full Screen

grey_accessibilityID

Using AI Code Generation

copy

Full Screen

1 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Login")] performAction:grey_tap()];2 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Password")] performAction:grey_typeText(@"password")];3 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Login")] performAction:grey_tap()];4 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Logout")] performAction:grey_tap()];5#import "EarlGrey.h"6[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Login")] performAction:grey_tap()];7[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Password")] performAction:grey_typeText(@"password")];8[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Login")] performAction:grey_tap()];9[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Logout")] performAction:grey_tap()];10import EarlGrey11EarlGrey.selectElement(with: grey_accessibilityID("Login")).perform(grey_tap())12EarlGrey.selectElement(with: grey_accessibilityID("Password")).perform(grey_typeText("password"))13EarlGrey.selectElement(with: grey_accessibilityID("Login")).perform(grey_tap())14EarlGrey.selectElement(with: grey_accessibilityID("Logout")).perform(grey_tap())15import EarlGrey16EarlGrey.selectElement(with: grey_accessibilityID("Login")).perform(grey_tap())17EarlGrey.selectElement(with: grey_accessibilityID("Password")).perform(grey_typeText("password

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