From 159bf860e16e11035da8d975e103e5f59bbd323b Mon Sep 17 00:00:00 2001 From: Mobile DevX Robot Date: Thu, 4 Aug 2022 16:32:01 -0700 Subject: [PATCH] Internal Commit Uploaded PiperOrigin-RevId: 465432740 --- CommonLib/Additions/NSObject+GREYCommon.m | 47 +++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/CommonLib/Additions/NSObject+GREYCommon.m b/CommonLib/Additions/NSObject+GREYCommon.m index ba2163ee6..c2fd2eb0f 100644 --- a/CommonLib/Additions/NSObject+GREYCommon.m +++ b/CommonLib/Additions/NSObject+GREYCommon.m @@ -69,6 +69,12 @@ - (NSString *)grey_description { [description appendFormat:@"; isAccessible=%@", self.isAccessibilityElement ? @"Y" : @"N"]; } + // IsAccessibilityElement. + if ([self respondsToSelector:@selector(accessibilityViewIsModal)]) { + [description + appendFormat:@"; accessibilityViewIsModal=%@", self.accessibilityViewIsModal ? @"Y" : @"N"]; + } + // AccessibilityIdentifier from UIAccessibilityIdentification. if ([self respondsToSelector:@selector(accessibilityIdentifier)]) { NSString *value = [self performSelector:@selector(accessibilityIdentifier)]; @@ -188,6 +194,27 @@ - (NSString *)grey_description { return description; } +- (id)viewCoveringByViewIsModal { + if (![self respondsToSelector:@selector(superview)]) { + return nil; + } + id superview = [(id)self superview]; + if (![superview respondsToSelector:@selector(subviews)]) { + return nil; + } + NSArray *subviews = (NSArray *)[(id)superview subviews]; + for (id subview in subviews) { + if (subview == self || ![subview respondsToSelector:@selector(accessibilityViewIsModal)]) { + continue; + } + BOOL isModal = [(id)subview accessibilityViewIsModal]; + if (isModal) { + return subview; + } + } + return [(id)superview viewCoveringByViewIsModal]; +} + - (NSString *)grey_shortDescription { NSMutableString *description = [[NSMutableString alloc] init]; @@ -201,6 +228,26 @@ - (NSString *)grey_shortDescription { [description appendString:axIdentifierDescription]; } + if ([self respondsToSelector:@selector(accessibilityViewIsModal)]) { + NSString *accessibilityViewIsModal = + (BOOL)[self performSelector:@selector(accessibilityViewIsModal)] ? @"Y" : @"N"; + NSString *axViewIsModalDescription = + [self grey_formattedDescriptionOrEmptyStringForValue:accessibilityViewIsModal + withPrefix:@"; AX.viewIsModal="]; + [description appendString:axViewIsModalDescription]; + } + + id coveringView = [self viewCoveringByViewIsModal]; + NSString *coveringViewDesc = + (coveringView == nil) + ? @"nil" + : [NSString + stringWithFormat:@"%@ %p", NSStringFromClass([coveringView class]), coveringView]; + NSString *coveringViewDescription = + [self grey_formattedDescriptionOrEmptyStringForValue:coveringViewDesc + withPrefix:@"; AX.coveredBy="]; + [description appendString:coveringViewDescription]; + if ([self respondsToSelector:@selector(accessibilityLabel)]) { NSString *axLabelDescription = [self grey_formattedDescriptionOrEmptyStringForValue:self.accessibilityLabel