Skip to content

feat: add placeholderValue to page source tree #1016

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
62 changes: 44 additions & 18 deletions WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#import "XCUIElement+FBUtilities.h"
#import "XCUIElement+FBWebDriverAttributes.h"
#import "XCUIElementQuery.h"
#import "FBElementHelpers.h"

static NSString* const FBUnknownBundleId = @"unknown";

Expand All @@ -45,6 +46,7 @@
static NSString* const FBExclusionAttributeVisible = @"visible";
static NSString* const FBExclusionAttributeAccessible = @"accessible";
static NSString* const FBExclusionAttributeFocused = @"focused";
static NSString* const FBExclusionAttributePlaceholderValue = @"placeholderValue";


_Nullable id extractIssueProperty(id issue, NSString *propertyName) {
Expand Down Expand Up @@ -201,28 +203,15 @@ + (NSDictionary *)dictionaryForElement:(id<FBXCElementSnapshot>)snapshot
info[@"label"] = FBValueOrNull(wrappedSnapshot.wdLabel);
info[@"rect"] = wrappedSnapshot.wdRect;

NSDictionary<NSString *, NSString * (^)(void)> *attributeBlocks = @{
FBExclusionAttributeFrame: ^{
return NSStringFromCGRect(wrappedSnapshot.wdFrame);
},
FBExclusionAttributeEnabled: ^{
return [@([wrappedSnapshot isWDEnabled]) stringValue];
},
FBExclusionAttributeVisible: ^{
return [@([wrappedSnapshot isWDVisible]) stringValue];
},
FBExclusionAttributeAccessible: ^{
return [@([wrappedSnapshot isWDAccessible]) stringValue];
},
FBExclusionAttributeFocused: ^{
return [@([wrappedSnapshot isWDFocused]) stringValue];
}
};
NSDictionary<NSString *, NSString *(^)(void)> *attributeBlocks = [self fb_attributeBlockMapForWrappedSnapshot:wrappedSnapshot];

NSSet *nonPrefixedKeys = [NSSet setWithObjects:FBExclusionAttributeFrame,
FBExclusionAttributePlaceholderValue, nil];

for (NSString *key in attributeBlocks) {
if (excludedAttributes == nil || ![excludedAttributes containsObject:key]) {
NSString *value = ((NSString * (^)(void))attributeBlocks[key])();
if ([key isEqualToString:FBExclusionAttributeFrame]) {
if ([nonPrefixedKeys containsObject:key]) {
info[key] = value;
} else {
info[[NSString stringWithFormat:@"is%@", [key capitalizedString]]] = value;
Expand All @@ -248,6 +237,43 @@ + (NSDictionary *)dictionaryForElement:(id<FBXCElementSnapshot>)snapshot
return info;
}

// Helper used by `dictionaryForElement:` to assemble attribute value blocks,
// including both common attributes and conditionally included ones like placeholderValue.
+ (NSDictionary<NSString *, NSString *(^)(void)> *)fb_attributeBlockMapForWrappedSnapshot:(FBXCElementSnapshotWrapper *)wrappedSnapshot

{
// Base attributes common to every element
NSMutableDictionary<NSString *, NSString *(^)(void)> *blocks =
[@{
FBExclusionAttributeFrame: ^{
return NSStringFromCGRect(wrappedSnapshot.wdFrame);
},
FBExclusionAttributeEnabled: ^{
return [@([wrappedSnapshot isWDEnabled]) stringValue];
},
FBExclusionAttributeVisible: ^{
return [@([wrappedSnapshot isWDVisible]) stringValue];
},
FBExclusionAttributeAccessible: ^{
return [@([wrappedSnapshot isWDAccessible]) stringValue];
},
FBExclusionAttributeFocused: ^{
return [@([wrappedSnapshot isWDFocused]) stringValue];
}
} mutableCopy];

XCUIElementType elementType = wrappedSnapshot.elementType;

// Text-input placeholder (only for elements that support inner text)
if (FBDoesElementSupportInnerText(elementType)) {
blocks[FBExclusionAttributePlaceholderValue] = ^{
return (NSString *)FBValueOrNull(wrappedSnapshot.wdPlaceholderValue);
};
}

return [blocks copy];
}

+ (NSDictionary *)accessibilityInfoForElement:(id<FBXCElementSnapshot>)snapshot
{
FBXCElementSnapshotWrapper *wrappedSnapshot = [FBXCElementSnapshotWrapper ensureWrapped:snapshot];
Expand Down
Loading