From 953b3e37a8962eda5a488c4d55c17091ae54a94c Mon Sep 17 00:00:00 2001 From: Sawan Garg Date: Fri, 8 Nov 2024 19:08:44 +0530 Subject: [PATCH 01/14] added support for excluded_attributes in JSON source hierarchy --- .../Categories/XCUIApplication+FBHelpers.h | 2 +- .../Categories/XCUIApplication+FBHelpers.m | 45 ++++++++++++++----- WebDriverAgentLib/Commands/FBDebugCommands.m | 5 ++- .../XCUIApplicationHelperTests.m | 2 +- 4 files changed, 41 insertions(+), 13 deletions(-) diff --git a/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.h b/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.h index 3ef66423b..615218dea 100644 --- a/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.h +++ b/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.h @@ -29,7 +29,7 @@ NS_ASSUME_NONNULL_BEGIN /** Return application elements tree in form of nested dictionaries */ -- (NSDictionary *)fb_tree; +- (NSDictionary *)fb_tree:(NSArray *) excluded_attributes; /** Return application elements accessibility tree in form of nested dictionaries diff --git a/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.m b/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.m index c3c99e6f5..e9936b342 100644 --- a/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.m +++ b/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.m @@ -151,12 +151,12 @@ - (BOOL)fb_deactivateWithDuration:(NSTimeInterval)duration error:(NSError **)err return YES; } -- (NSDictionary *)fb_tree +- (NSDictionary *)fb_tree:(NSArray *) excluded_attributes { id snapshot = self.fb_isResolvedFromCache.boolValue ? self.lastSnapshot : [self fb_snapshotWithAllAttributesAndMaxDepth:nil]; - return [self.class dictionaryForElement:snapshot recursive:YES]; + return [self.class dictionaryForElement:snapshot recursive:YES excludedAttributes:excluded_attributes]; } - (NSDictionary *)fb_accessibilityTree @@ -167,7 +167,7 @@ - (NSDictionary *)fb_accessibilityTree return [self.class accessibilityInfoForElement:snapshot]; } -+ (NSDictionary *)dictionaryForElement:(id)snapshot recursive:(BOOL)recursive ++ (NSDictionary *)dictionaryForElement:(id)snapshot recursive:(BOOL)recursive excludedAttributes:(NSArray *) excluded_attributes { NSMutableDictionary *info = [[NSMutableDictionary alloc] init]; info[@"type"] = [FBElementTypeTransformer shortStringWithElementType:snapshot.elementType]; @@ -177,11 +177,36 @@ + (NSDictionary *)dictionaryForElement:(id)snapshot recursi info[@"value"] = FBValueOrNull(wrappedSnapshot.wdValue); info[@"label"] = FBValueOrNull(wrappedSnapshot.wdLabel); info[@"rect"] = wrappedSnapshot.wdRect; - info[@"frame"] = NSStringFromCGRect(wrappedSnapshot.wdFrame); - info[@"isEnabled"] = [@([wrappedSnapshot isWDEnabled]) stringValue]; - info[@"isVisible"] = [@([wrappedSnapshot isWDVisible]) stringValue]; - info[@"isAccessible"] = [@([wrappedSnapshot isWDAccessible]) stringValue]; - info[@"isFocused"] = [@([wrappedSnapshot isWDFocused]) stringValue]; + + NSDictionary *attributeBlocks = @{ + @"frame": ^{ + return NSStringFromCGRect(wrappedSnapshot.wdFrame); + }, + @"enabled": ^{ + return [@([wrappedSnapshot isWDEnabled]) stringValue]; + }, + @"visible": ^{ + return [@([wrappedSnapshot isWDVisible]) stringValue]; + }, + @"accessible": ^{ + return [@([wrappedSnapshot isWDAccessible]) stringValue]; + }, + @"focused": ^{ + return [@([wrappedSnapshot isWDFocused]) stringValue]; + } + }; + + for (NSString *key in attributeBlocks) { + if (![excluded_attributes containsObject:key]) { + NSString *value = ((NSString * (^)(void))attributeBlocks[key])(); + if ([key isEqualToString:@"frame"]) { + info[key] = value; + } else { + info[[NSString stringWithFormat:@"is%@", [key capitalizedString]]] = value; + } + } + } + if (!recursive) { return info.copy; @@ -191,7 +216,7 @@ + (NSDictionary *)dictionaryForElement:(id)snapshot recursi if ([childElements count]) { info[@"children"] = [[NSMutableArray alloc] init]; for (id childSnapshot in childElements) { - [info[@"children"] addObject:[self dictionaryForElement:childSnapshot recursive:YES]]; + [info[@"children"] addObject:[self dictionaryForElement:childSnapshot recursive:YES excludedAttributes:excluded_attributes]]; } } return info; @@ -379,7 +404,7 @@ - (BOOL)fb_dismissKeyboardWithKeyNames:(nullable NSArray *)keyNames id extractedElement = extractIssueProperty(issue, @"element"); id elementSnapshot = [extractedElement fb_takeSnapshot]; - NSDictionary *elementAttributes = elementSnapshot ? [self.class dictionaryForElement:elementSnapshot recursive:NO] : @{}; + NSDictionary *elementAttributes = elementSnapshot ? [self.class dictionaryForElement:elementSnapshot recursive:NO excludedAttributes:@[]] : @{}; [resultArray addObject:@{ @"detailedDescription": extractIssueProperty(issue, @"detailedDescription") ?: @"", diff --git a/WebDriverAgentLib/Commands/FBDebugCommands.m b/WebDriverAgentLib/Commands/FBDebugCommands.m index dc96958d0..1f6d26f37 100644 --- a/WebDriverAgentLib/Commands/FBDebugCommands.m +++ b/WebDriverAgentLib/Commands/FBDebugCommands.m @@ -54,7 +54,10 @@ + (NSArray *)routes withExcludedAttributes:excludedAttributes] withScope:sourceScope]]; } else if ([sourceType caseInsensitiveCompare:SOURCE_FORMAT_JSON] == NSOrderedSame) { - result = application.fb_tree; + NSArray *excludedAttributes = nil == request.parameters[@"excluded_attributes"] + ? nil + : [request.parameters[@"excluded_attributes"] componentsSeparatedByString:@","]; + result = [application fb_tree:excludedAttributes]; } else if ([sourceType caseInsensitiveCompare:SOURCE_FORMAT_DESCRIPTION] == NSOrderedSame) { result = application.fb_descriptionRepresentation; } else { diff --git a/WebDriverAgentTests/IntegrationTests/XCUIApplicationHelperTests.m b/WebDriverAgentTests/IntegrationTests/XCUIApplicationHelperTests.m index 15b906db7..dcbd21401 100644 --- a/WebDriverAgentTests/IntegrationTests/XCUIApplicationHelperTests.m +++ b/WebDriverAgentTests/IntegrationTests/XCUIApplicationHelperTests.m @@ -40,7 +40,7 @@ - (void)testQueringSpringboard - (void)testApplicationTree { - XCTAssertNotNil(self.testedApplication.fb_tree); + XCTAssertNotNil([self.testedApplication fb_tree:@[]]); XCTAssertNotNil(self.testedApplication.fb_accessibilityTree); } From 2ec10efa7e5343df6aac0fb0bbfe30e257ea1eaf Mon Sep 17 00:00:00 2001 From: Sawan Garg Date: Fri, 8 Nov 2024 19:24:14 +0530 Subject: [PATCH 02/14] changed variable name to camel case --- .../Categories/XCUIApplication+FBHelpers.h | 2 +- .../Categories/XCUIApplication+FBHelpers.m | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.h b/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.h index 615218dea..3c4fe4318 100644 --- a/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.h +++ b/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.h @@ -29,7 +29,7 @@ NS_ASSUME_NONNULL_BEGIN /** Return application elements tree in form of nested dictionaries */ -- (NSDictionary *)fb_tree:(NSArray *) excluded_attributes; +- (NSDictionary *)fb_tree:(NSArray *) excludedAttributes; /** Return application elements accessibility tree in form of nested dictionaries diff --git a/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.m b/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.m index e9936b342..4d9fc5ca5 100644 --- a/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.m +++ b/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.m @@ -151,12 +151,12 @@ - (BOOL)fb_deactivateWithDuration:(NSTimeInterval)duration error:(NSError **)err return YES; } -- (NSDictionary *)fb_tree:(NSArray *) excluded_attributes +- (NSDictionary *)fb_tree:(NSArray *) excludedAttributes { id snapshot = self.fb_isResolvedFromCache.boolValue ? self.lastSnapshot : [self fb_snapshotWithAllAttributesAndMaxDepth:nil]; - return [self.class dictionaryForElement:snapshot recursive:YES excludedAttributes:excluded_attributes]; + return [self.class dictionaryForElement:snapshot recursive:YES excludedAttributes:excludedAttributes]; } - (NSDictionary *)fb_accessibilityTree @@ -167,7 +167,7 @@ - (NSDictionary *)fb_accessibilityTree return [self.class accessibilityInfoForElement:snapshot]; } -+ (NSDictionary *)dictionaryForElement:(id)snapshot recursive:(BOOL)recursive excludedAttributes:(NSArray *) excluded_attributes ++ (NSDictionary *)dictionaryForElement:(id)snapshot recursive:(BOOL)recursive excludedAttributes:(NSArray *) excludedAttributes { NSMutableDictionary *info = [[NSMutableDictionary alloc] init]; info[@"type"] = [FBElementTypeTransformer shortStringWithElementType:snapshot.elementType]; @@ -197,7 +197,7 @@ + (NSDictionary *)dictionaryForElement:(id)snapshot recursi }; for (NSString *key in attributeBlocks) { - if (![excluded_attributes containsObject:key]) { + if (![excludedAttributes containsObject:key]) { NSString *value = ((NSString * (^)(void))attributeBlocks[key])(); if ([key isEqualToString:@"frame"]) { info[key] = value; @@ -216,7 +216,7 @@ + (NSDictionary *)dictionaryForElement:(id)snapshot recursi if ([childElements count]) { info[@"children"] = [[NSMutableArray alloc] init]; for (id childSnapshot in childElements) { - [info[@"children"] addObject:[self dictionaryForElement:childSnapshot recursive:YES excludedAttributes:excluded_attributes]]; + [info[@"children"] addObject:[self dictionaryForElement:childSnapshot recursive:YES excludedAttributes:excludedAttributes]]; } } return info; From 89db96e526cff9d1b5a0ef9ca04f6e09321e149c Mon Sep 17 00:00:00 2001 From: Sawan Garg Date: Fri, 8 Nov 2024 19:39:13 +0530 Subject: [PATCH 03/14] added comment --- WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.m b/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.m index 4d9fc5ca5..a37b7e310 100644 --- a/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.m +++ b/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.m @@ -197,7 +197,7 @@ + (NSDictionary *)dictionaryForElement:(id)snapshot recursi }; for (NSString *key in attributeBlocks) { - if (![excludedAttributes containsObject:key]) { + if (![excludedAttributes containsObject:key]) { // check for attribute exclusion NSString *value = ((NSString * (^)(void))attributeBlocks[key])(); if ([key isEqualToString:@"frame"]) { info[key] = value; From 3b66b7ba5824ccfa3efcc0994e3fab554ff948b9 Mon Sep 17 00:00:00 2001 From: Sawan Garg Date: Sat, 9 Nov 2024 00:40:52 +0530 Subject: [PATCH 04/14] addressed PR comments --- .../Categories/XCUIApplication+FBHelpers.h | 5 +++-- .../Categories/XCUIApplication+FBHelpers.m | 11 +++++++---- WebDriverAgentLib/Commands/FBDebugCommands.m | 8 +++++--- .../IntegrationTests/XCUIApplicationHelperTests.m | 2 +- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.h b/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.h index 3c4fe4318..f8e98bf7f 100644 --- a/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.h +++ b/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.h @@ -27,9 +27,10 @@ NS_ASSUME_NONNULL_BEGIN - (BOOL)fb_deactivateWithDuration:(NSTimeInterval)duration error:(NSError **)error; /** - Return application elements tree in form of nested dictionaries + @Param excludedAttributes which needs to be excluded from the response possible values contain frame, enabled, visible, accessible, focused + @Return application elements tree in form of nested dictionaries */ -- (NSDictionary *)fb_tree:(NSArray *) excludedAttributes; +- (NSDictionary *)fb_tree:(nullable NSSet *) excludedAttributes; /** Return application elements accessibility tree in form of nested dictionaries diff --git a/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.m b/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.m index a37b7e310..868295952 100644 --- a/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.m +++ b/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.m @@ -151,7 +151,7 @@ - (BOOL)fb_deactivateWithDuration:(NSTimeInterval)duration error:(NSError **)err return YES; } -- (NSDictionary *)fb_tree:(NSArray *) excludedAttributes +- (NSDictionary *)fb_tree:(nullable NSSet *) excludedAttributes { id snapshot = self.fb_isResolvedFromCache.boolValue ? self.lastSnapshot @@ -167,7 +167,9 @@ - (NSDictionary *)fb_accessibilityTree return [self.class accessibilityInfoForElement:snapshot]; } -+ (NSDictionary *)dictionaryForElement:(id)snapshot recursive:(BOOL)recursive excludedAttributes:(NSArray *) excludedAttributes ++ (NSDictionary *)dictionaryForElement:(id)snapshot + recursive:(BOOL)recursive + excludedAttributes:(nullable NSSet *) excludedAttributes { NSMutableDictionary *info = [[NSMutableDictionary alloc] init]; info[@"type"] = [FBElementTypeTransformer shortStringWithElementType:snapshot.elementType]; @@ -178,7 +180,7 @@ + (NSDictionary *)dictionaryForElement:(id)snapshot recursi info[@"label"] = FBValueOrNull(wrappedSnapshot.wdLabel); info[@"rect"] = wrappedSnapshot.wdRect; - NSDictionary *attributeBlocks = @{ + NSDictionary *attributeBlocks = @{ @"frame": ^{ return NSStringFromCGRect(wrappedSnapshot.wdFrame); }, @@ -197,7 +199,7 @@ + (NSDictionary *)dictionaryForElement:(id)snapshot recursi }; for (NSString *key in attributeBlocks) { - if (![excludedAttributes containsObject:key]) { // check for attribute exclusion + if (excludedAttributes == nil || ![excludedAttributes containsObject:key]) { // check for attribute exclusion NSString *value = ((NSString * (^)(void))attributeBlocks[key])(); if ([key isEqualToString:@"frame"]) { info[key] = value; @@ -208,6 +210,7 @@ + (NSDictionary *)dictionaryForElement:(id)snapshot recursi } + if (!recursive) { return info.copy; } diff --git a/WebDriverAgentLib/Commands/FBDebugCommands.m b/WebDriverAgentLib/Commands/FBDebugCommands.m index 1f6d26f37..c3f9a7816 100644 --- a/WebDriverAgentLib/Commands/FBDebugCommands.m +++ b/WebDriverAgentLib/Commands/FBDebugCommands.m @@ -54,9 +54,11 @@ + (NSArray *)routes withExcludedAttributes:excludedAttributes] withScope:sourceScope]]; } else if ([sourceType caseInsensitiveCompare:SOURCE_FORMAT_JSON] == NSOrderedSame) { - NSArray *excludedAttributes = nil == request.parameters[@"excluded_attributes"] - ? nil - : [request.parameters[@"excluded_attributes"] componentsSeparatedByString:@","]; + NSString *excludedAttributesString = request.parameters[@"excluded_attributes"]; + NSSet *excludedAttributes = (excludedAttributesString == nil) + ? nil + : [NSSet setWithArray:[excludedAttributesString componentsSeparatedByString:@","]]; + result = [application fb_tree:excludedAttributes]; } else if ([sourceType caseInsensitiveCompare:SOURCE_FORMAT_DESCRIPTION] == NSOrderedSame) { result = application.fb_descriptionRepresentation; diff --git a/WebDriverAgentTests/IntegrationTests/XCUIApplicationHelperTests.m b/WebDriverAgentTests/IntegrationTests/XCUIApplicationHelperTests.m index dcbd21401..e97e5fe45 100644 --- a/WebDriverAgentTests/IntegrationTests/XCUIApplicationHelperTests.m +++ b/WebDriverAgentTests/IntegrationTests/XCUIApplicationHelperTests.m @@ -40,7 +40,7 @@ - (void)testQueringSpringboard - (void)testApplicationTree { - XCTAssertNotNil([self.testedApplication fb_tree:@[]]); + XCTAssertNotNil([self.testedApplication fb_tree:@[@"visible"]]); XCTAssertNotNil(self.testedApplication.fb_accessibilityTree); } From 9e9ad30cfef6588d9391db810914288157f7a2cd Mon Sep 17 00:00:00 2001 From: Sawan Garg Date: Sat, 9 Nov 2024 00:44:39 +0530 Subject: [PATCH 05/14] fixed test input as well --- .../IntegrationTests/XCUIApplicationHelperTests.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WebDriverAgentTests/IntegrationTests/XCUIApplicationHelperTests.m b/WebDriverAgentTests/IntegrationTests/XCUIApplicationHelperTests.m index e97e5fe45..7e3edce19 100644 --- a/WebDriverAgentTests/IntegrationTests/XCUIApplicationHelperTests.m +++ b/WebDriverAgentTests/IntegrationTests/XCUIApplicationHelperTests.m @@ -40,7 +40,7 @@ - (void)testQueringSpringboard - (void)testApplicationTree { - XCTAssertNotNil([self.testedApplication fb_tree:@[@"visible"]]); + XCTAssertNotNil([self.testedApplication fb_tree:[NSSet setWithArray:@[@"visible"]]]); XCTAssertNotNil(self.testedApplication.fb_accessibilityTree); } From 8462cc9effba054c4dbcf2fe4516baf0140feca3 Mon Sep 17 00:00:00 2001 From: Sawan Garg Date: Sat, 9 Nov 2024 01:09:36 +0530 Subject: [PATCH 06/14] change array to nil --- WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.m b/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.m index 868295952..79a5ffd43 100644 --- a/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.m +++ b/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.m @@ -407,7 +407,7 @@ - (BOOL)fb_dismissKeyboardWithKeyNames:(nullable NSArray *)keyNames id extractedElement = extractIssueProperty(issue, @"element"); id elementSnapshot = [extractedElement fb_takeSnapshot]; - NSDictionary *elementAttributes = elementSnapshot ? [self.class dictionaryForElement:elementSnapshot recursive:NO excludedAttributes:@[]] : @{}; + NSDictionary *elementAttributes = elementSnapshot ? [self.class dictionaryForElement:elementSnapshot recursive:NO excludedAttributes:nil] : @{}; [resultArray addObject:@{ @"detailedDescription": extractIssueProperty(issue, @"detailedDescription") ?: @"", From 8e8ba8592d73d919f2db93e6a30dc676d97b177b Mon Sep 17 00:00:00 2001 From: Sawan Garg Date: Sat, 9 Nov 2024 02:56:07 +0530 Subject: [PATCH 07/14] removed comment and formatted the long method call --- WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.m | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.m b/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.m index 79a5ffd43..2d1eeb932 100644 --- a/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.m +++ b/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.m @@ -199,7 +199,7 @@ + (NSDictionary *)dictionaryForElement:(id)snapshot }; for (NSString *key in attributeBlocks) { - if (excludedAttributes == nil || ![excludedAttributes containsObject:key]) { // check for attribute exclusion + if (excludedAttributes == nil || ![excludedAttributes containsObject:key]) { NSString *value = ((NSString * (^)(void))attributeBlocks[key])(); if ([key isEqualToString:@"frame"]) { info[key] = value; @@ -219,7 +219,9 @@ + (NSDictionary *)dictionaryForElement:(id)snapshot if ([childElements count]) { info[@"children"] = [[NSMutableArray alloc] init]; for (id childSnapshot in childElements) { - [info[@"children"] addObject:[self dictionaryForElement:childSnapshot recursive:YES excludedAttributes:excludedAttributes]]; + [info[@"children"] addObject:[self dictionaryForElement:childSnapshot + recursive:YES + excludedAttributes:excludedAttributes]]; } } return info; From e8ccf3c640a87a11c84523c4db982b64cc907553 Mon Sep 17 00:00:00 2001 From: Sawan Garg Date: Sat, 9 Nov 2024 03:09:05 +0530 Subject: [PATCH 08/14] added assertion to verify exclusion of attribute --- .../IntegrationTests/XCUIApplicationHelperTests.m | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/WebDriverAgentTests/IntegrationTests/XCUIApplicationHelperTests.m b/WebDriverAgentTests/IntegrationTests/XCUIApplicationHelperTests.m index 7e3edce19..74b5bf2a2 100644 --- a/WebDriverAgentTests/IntegrationTests/XCUIApplicationHelperTests.m +++ b/WebDriverAgentTests/IntegrationTests/XCUIApplicationHelperTests.m @@ -40,7 +40,12 @@ - (void)testQueringSpringboard - (void)testApplicationTree { - XCTAssertNotNil([self.testedApplication fb_tree:[NSSet setWithArray:@[@"visible"]]]); + XCTAssertNotNil([self.testedApplication fb_tree:nil]); + + NSDictionary *applicationTree = [self.testedApplication fb_tree:[NSSet setWithArray:@[@"visible"]]]; + XCTAssertNotNil(applicationTree); + XCTAssertNil([applicationTree objectForKey:@"isVisible"], @"'isVisible' key should not be present in the application tree"); + XCTAssertNotNil(self.testedApplication.fb_accessibilityTree); } From e3ba4c8db0de97103a37fa42980c5ff876361238 Mon Sep 17 00:00:00 2001 From: Sawan Garg Date: Sat, 9 Nov 2024 03:13:18 +0530 Subject: [PATCH 09/14] changed docstring format --- WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.h b/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.h index f8e98bf7f..83538698b 100644 --- a/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.h +++ b/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.h @@ -27,8 +27,8 @@ NS_ASSUME_NONNULL_BEGIN - (BOOL)fb_deactivateWithDuration:(NSTimeInterval)duration error:(NSError **)error; /** - @Param excludedAttributes which needs to be excluded from the response possible values contain frame, enabled, visible, accessible, focused - @Return application elements tree in form of nested dictionaries + @param excludedAttributes Set of possible attributes to be excluded i.e frame, enabled, visible, accessible, focused + @return application elements tree in form of nested dictionaries */ - (NSDictionary *)fb_tree:(nullable NSSet *) excludedAttributes; From 61b87d4f2a749c7d07be31e6cd292e56ea343ecb Mon Sep 17 00:00:00 2001 From: Sawan Garg Date: Mon, 11 Nov 2024 13:34:21 +0530 Subject: [PATCH 10/14] PR comments resolved for reformatting, separate test case --- WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.h | 2 +- WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.m | 4 +++- .../IntegrationTests/XCUIApplicationHelperTests.m | 7 +++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.h b/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.h index 83538698b..e7e3d5e95 100644 --- a/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.h +++ b/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.h @@ -27,7 +27,7 @@ NS_ASSUME_NONNULL_BEGIN - (BOOL)fb_deactivateWithDuration:(NSTimeInterval)duration error:(NSError **)error; /** - @param excludedAttributes Set of possible attributes to be excluded i.e frame, enabled, visible, accessible, focused + @param excludedAttributes Set of possible attributes to be excluded i.e frame, enabled, visible, accessible, focused. If set to nil or an empty array then no attributes will be excluded from the resulting JSON @return application elements tree in form of nested dictionaries */ - (NSDictionary *)fb_tree:(nullable NSSet *) excludedAttributes; diff --git a/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.m b/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.m index 2d1eeb932..0778072d1 100644 --- a/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.m +++ b/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.m @@ -409,7 +409,9 @@ - (BOOL)fb_dismissKeyboardWithKeyNames:(nullable NSArray *)keyNames id extractedElement = extractIssueProperty(issue, @"element"); id elementSnapshot = [extractedElement fb_takeSnapshot]; - NSDictionary *elementAttributes = elementSnapshot ? [self.class dictionaryForElement:elementSnapshot recursive:NO excludedAttributes:nil] : @{}; + NSDictionary *elementAttributes = elementSnapshot + ? [self.class dictionaryForElement:elementSnapshot recursive:NO excludedAttributes:nil] + : @{}; [resultArray addObject:@{ @"detailedDescription": extractIssueProperty(issue, @"detailedDescription") ?: @"", diff --git a/WebDriverAgentTests/IntegrationTests/XCUIApplicationHelperTests.m b/WebDriverAgentTests/IntegrationTests/XCUIApplicationHelperTests.m index 74b5bf2a2..62bed2946 100644 --- a/WebDriverAgentTests/IntegrationTests/XCUIApplicationHelperTests.m +++ b/WebDriverAgentTests/IntegrationTests/XCUIApplicationHelperTests.m @@ -49,6 +49,13 @@ - (void)testApplicationTree XCTAssertNotNil(self.testedApplication.fb_accessibilityTree); } +- (void)testApplicationTreeAttributesFiltering +{ + NSDictionary *applicationTree = [self.testedApplication fb_tree:[NSSet setWithArray:@[@"visible"]]]; + XCTAssertNotNil(applicationTree); + XCTAssertNil([applicationTree objectForKey:@"isVisible"], @"'isVisible' key should not be present in the application tree"); +} + - (void)testDeactivateApplication { NSError *error; From 4be52625b034db31edd1e137171416127b0f02e8 Mon Sep 17 00:00:00 2001 From: Sawan Garg Date: Mon, 11 Nov 2024 16:26:56 +0530 Subject: [PATCH 11/14] removed duplicate lines, empty spaces. maintain the backward compatibility --- WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.h | 4 ++++ WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.m | 7 +++++-- .../IntegrationTests/XCUIApplicationHelperTests.m | 5 ----- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.h b/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.h index e7e3d5e95..bca87caf0 100644 --- a/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.h +++ b/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.h @@ -26,6 +26,10 @@ NS_ASSUME_NONNULL_BEGIN */ - (BOOL)fb_deactivateWithDuration:(NSTimeInterval)duration error:(NSError **)error; +/** + @return application elements tree in form of nested dictionaries + */ +- (NSDictionary *)fb_tree; /** @param excludedAttributes Set of possible attributes to be excluded i.e frame, enabled, visible, accessible, focused. If set to nil or an empty array then no attributes will be excluded from the resulting JSON @return application elements tree in form of nested dictionaries diff --git a/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.m b/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.m index 0778072d1..6cdae945b 100644 --- a/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.m +++ b/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.m @@ -151,6 +151,11 @@ - (BOOL)fb_deactivateWithDuration:(NSTimeInterval)duration error:(NSError **)err return YES; } +- (NSDictionary *)fb_tree +{ + return [self fb_tree:nil]; +} + - (NSDictionary *)fb_tree:(nullable NSSet *) excludedAttributes { id snapshot = self.fb_isResolvedFromCache.boolValue @@ -209,8 +214,6 @@ + (NSDictionary *)dictionaryForElement:(id)snapshot } } - - if (!recursive) { return info.copy; } diff --git a/WebDriverAgentTests/IntegrationTests/XCUIApplicationHelperTests.m b/WebDriverAgentTests/IntegrationTests/XCUIApplicationHelperTests.m index 62bed2946..27ae98e7a 100644 --- a/WebDriverAgentTests/IntegrationTests/XCUIApplicationHelperTests.m +++ b/WebDriverAgentTests/IntegrationTests/XCUIApplicationHelperTests.m @@ -41,11 +41,6 @@ - (void)testQueringSpringboard - (void)testApplicationTree { XCTAssertNotNil([self.testedApplication fb_tree:nil]); - - NSDictionary *applicationTree = [self.testedApplication fb_tree:[NSSet setWithArray:@[@"visible"]]]; - XCTAssertNotNil(applicationTree); - XCTAssertNil([applicationTree objectForKey:@"isVisible"], @"'isVisible' key should not be present in the application tree"); - XCTAssertNotNil(self.testedApplication.fb_accessibilityTree); } From 4ba58bdee5dbeb5a634f4a25d177864d18338f90 Mon Sep 17 00:00:00 2001 From: Sawan Garg Date: Mon, 11 Nov 2024 16:30:34 +0530 Subject: [PATCH 12/14] added backward compatibility in test cases as well --- .../IntegrationTests/XCUIApplicationHelperTests.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WebDriverAgentTests/IntegrationTests/XCUIApplicationHelperTests.m b/WebDriverAgentTests/IntegrationTests/XCUIApplicationHelperTests.m index 27ae98e7a..794be2192 100644 --- a/WebDriverAgentTests/IntegrationTests/XCUIApplicationHelperTests.m +++ b/WebDriverAgentTests/IntegrationTests/XCUIApplicationHelperTests.m @@ -40,7 +40,7 @@ - (void)testQueringSpringboard - (void)testApplicationTree { - XCTAssertNotNil([self.testedApplication fb_tree:nil]); + XCTAssertNotNil(self.testedApplication.fb_tree); XCTAssertNotNil(self.testedApplication.fb_accessibilityTree); } From 3e0dd51ecc5529289717c4dbbe7d3b4fe3f42e31 Mon Sep 17 00:00:00 2001 From: Sawan Garg Date: Mon, 11 Nov 2024 16:36:37 +0530 Subject: [PATCH 13/14] updated docstring to match the previous one. --- WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.h b/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.h index bca87caf0..abc91a3fe 100644 --- a/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.h +++ b/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.h @@ -27,7 +27,7 @@ NS_ASSUME_NONNULL_BEGIN - (BOOL)fb_deactivateWithDuration:(NSTimeInterval)duration error:(NSError **)error; /** - @return application elements tree in form of nested dictionaries + Return application elements tree in form of nested dictionaries */ - (NSDictionary *)fb_tree; /** From edd5da96fc53b759df1334da459126a8141d38cb Mon Sep 17 00:00:00 2001 From: Sawan Garg Date: Mon, 11 Nov 2024 16:37:48 +0530 Subject: [PATCH 14/14] updated docstring --- WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.h b/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.h index abc91a3fe..54d4bd281 100644 --- a/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.h +++ b/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.h @@ -27,9 +27,10 @@ NS_ASSUME_NONNULL_BEGIN - (BOOL)fb_deactivateWithDuration:(NSTimeInterval)duration error:(NSError **)error; /** - Return application elements tree in form of nested dictionaries + Return application elements tree in form of nested dictionaries */ - (NSDictionary *)fb_tree; + /** @param excludedAttributes Set of possible attributes to be excluded i.e frame, enabled, visible, accessible, focused. If set to nil or an empty array then no attributes will be excluded from the resulting JSON @return application elements tree in form of nested dictionaries