diff --git a/packages/webdriveragent/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.h b/packages/webdriveragent/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.h index f78ccaf3..193b3af1 100644 --- a/packages/webdriveragent/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.h +++ b/packages/webdriveragent/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.h @@ -36,7 +36,7 @@ NS_ASSUME_NONNULL_BEGIN - (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 + @param excludedAttributes Set of possible attributes to be excluded i.e frame, nativeFrame, enabled, visible, accessible, nativeAccessibilityElement, focused, traits, placeholderValue, minValue, maxValue, customActions. 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/packages/webdriveragent/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.m b/packages/webdriveragent/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.m index 0d9faf99..b33b06bc 100644 --- a/packages/webdriveragent/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.m +++ b/packages/webdriveragent/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.m @@ -52,6 +52,7 @@ static NSString* const FBExclusionAttributeTraits = @"traits"; static NSString* const FBExclusionAttributeMinValue = @"minValue"; static NSString* const FBExclusionAttributeMaxValue = @"maxValue"; +static NSString* const FBExclusionAttributeCustomActions = @"customActions"; static NSString *FBJsonPrefixedAttributeKey(NSString *key) { @@ -242,7 +243,6 @@ + (NSDictionary *)dictionaryForElement:(id)snapshot info[@"value"] = FBValueOrNull(wrappedSnapshot.wdValue); info[@"label"] = FBValueOrNull(wrappedSnapshot.wdLabel); info[@"rect"] = wrappedSnapshot.wdRect; - info[@"customActions"] = FBValueOrNull(wrappedSnapshot.wdCustomActions); NSDictionary *attributeBlocks = [self fb_attributeBlockMapForWrappedSnapshot:wrappedSnapshot]; @@ -253,6 +253,7 @@ + (NSDictionary *)dictionaryForElement:(id)snapshot FBExclusionAttributeTraits, FBExclusionAttributeMinValue, FBExclusionAttributeMaxValue, + FBExclusionAttributeCustomActions, nil]; for (NSString *key in attributeBlocks) { @@ -315,6 +316,9 @@ + (NSDictionary *)dictionaryForElement:(id)snapshot }, FBExclusionAttributeTraits: ^{ return wrappedSnapshot.wdTraits; + }, + FBExclusionAttributeCustomActions: ^{ + return (NSString *)FBValueOrNull(wrappedSnapshot.wdCustomActions); } } mutableCopy]; diff --git a/packages/webdriveragent/WebDriverAgentTests/IntegrationTests/FBElementAttributeTests.m b/packages/webdriveragent/WebDriverAgentTests/IntegrationTests/FBElementAttributeTests.m index 23897482..bfa3bc67 100644 --- a/packages/webdriveragent/WebDriverAgentTests/IntegrationTests/FBElementAttributeTests.m +++ b/packages/webdriveragent/WebDriverAgentTests/IntegrationTests/FBElementAttributeTests.m @@ -12,11 +12,37 @@ #import "FBFindElementCommands.h" #import "FBTestMacros.h" #import "FBXCodeCompatibility.h" +#import "XCUIApplication+FBHelpers.h" #import "XCUIElement+FBAccessibility.h" #import "XCUIElement+FBCustomActions.h" #import "XCUIElement+FBIsVisible.h" #import "XCUIElement+FBWebDriverAttributes.h" +static void FBCountTreeNodes(NSDictionary *tree, NSUInteger *nodesCount, NSUInteger *customActionsCount) +{ + *nodesCount += 1; + if (nil != tree[@"customActions"]) { + *customActionsCount += 1; + } + for (NSDictionary *child in tree[@"children"]) { + FBCountTreeNodes(child, nodesCount, customActionsCount); + } +} + +static NSDictionary *FBFindTreeButton(NSDictionary *tree, NSString *name) +{ + if ([tree[@"type"] isEqualToString:@"Button"] && [tree[@"name"] isEqual:name]) { + return tree; + } + for (NSDictionary *child in tree[@"children"]) { + NSDictionary *result = FBFindTreeButton(child, name); + if (nil != result) { + return result; + } + } + return nil; +} + @interface FBElementAttributeTests : FBIntegrationTestCase @end @@ -270,4 +296,22 @@ - (void)testCustomActionsAttributes XCTAssertEqualObjects(customActions, @"Custom Action 1,Custom Action 2"); } +- (void)testCustomActionsInJSONTree +{ + NSDictionary *tree = self.testedApplication.fb_tree; + NSUInteger nodesCount = 0; + NSUInteger customActionsCount = 0; + FBCountTreeNodes(tree, &nodesCount, &customActionsCount); + XCTAssertEqual(customActionsCount, nodesCount); + NSDictionary *button = FBFindTreeButton(tree, @"Button"); + XCTAssertEqualObjects(button[@"customActions"], @"Custom Action 1,Custom Action 2"); + + tree = [self.testedApplication fb_tree:[NSSet setWithObject:@"customActions"]]; + XCTAssertNotNil(FBFindTreeButton(tree, @"Button")); + nodesCount = 0; + customActionsCount = 0; + FBCountTreeNodes(tree, &nodesCount, &customActionsCount); + XCTAssertEqual(customActionsCount, 0); +} + @end