From 404967b9a0c3a3fa703565dba64fb9f0f8b21bd7 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 | 41 +++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/CommonLib/Additions/NSObject+GREYCommon.m b/CommonLib/Additions/NSObject+GREYCommon.m index ba2163ee6..58469aef3 100644 --- a/CommonLib/Additions/NSObject+GREYCommon.m +++ b/CommonLib/Additions/NSObject+GREYCommon.m @@ -69,6 +69,11 @@ - (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 +193,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 +227,21 @@ - (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