Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<NSString *> *) excludedAttributes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -242,7 +243,6 @@ + (NSDictionary *)dictionaryForElement:(id<FBXCElementSnapshot>)snapshot
info[@"value"] = FBValueOrNull(wrappedSnapshot.wdValue);
info[@"label"] = FBValueOrNull(wrappedSnapshot.wdLabel);
info[@"rect"] = wrappedSnapshot.wdRect;
info[@"customActions"] = FBValueOrNull(wrappedSnapshot.wdCustomActions);

NSDictionary<NSString *, NSString *(^)(void)> *attributeBlocks = [self fb_attributeBlockMapForWrappedSnapshot:wrappedSnapshot];

Expand All @@ -253,6 +253,7 @@ + (NSDictionary *)dictionaryForElement:(id<FBXCElementSnapshot>)snapshot
FBExclusionAttributeTraits,
FBExclusionAttributeMinValue,
FBExclusionAttributeMaxValue,
FBExclusionAttributeCustomActions,
nil];

for (NSString *key in attributeBlocks) {
Expand Down Expand Up @@ -315,6 +316,9 @@ + (NSDictionary *)dictionaryForElement:(id<FBXCElementSnapshot>)snapshot
},
FBExclusionAttributeTraits: ^{
return wrappedSnapshot.wdTraits;
},
FBExclusionAttributeCustomActions: ^{
return (NSString *)FBValueOrNull(wrappedSnapshot.wdCustomActions);
}
} mutableCopy];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Loading