Skip to content
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

feat: Increase Xpath Lookup Performance #666

Merged
merged 3 commits into from
Feb 23, 2023
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
4 changes: 1 addition & 3 deletions WebDriverAgentLib/Categories/XCUIElement+FBResolve.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ - (XCUIElement *)fb_stableInstance
if (nil == uid) {
return self;
}
NSPredicate *predicate = [NSPredicate predicateWithBlock:^BOOL(id<FBXCElementSnapshot> snapshot, NSDictionary *bindings) {
return [[FBXCElementSnapshotWrapper wdUIDWithSnapshot:snapshot] isEqualToString:uid];
}];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"%K = %@",FBStringify(FBXCElementSnapshotWrapper, fb_uid), uid];
return [query matchingPredicate:predicate].allElementsBoundByIndex.firstObject ?: self;
}

Expand Down
18 changes: 17 additions & 1 deletion WebDriverAgentLib/Categories/XCUIElement+FBUID.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/

#import <objc/runtime.h>

#import "XCUIElement+FBUID.h"

#import "FBElementUtils.h"
Expand All @@ -33,6 +35,17 @@ - (NSString *)fb_uid

@implementation FBXCElementSnapshotWrapper (FBUID)

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wobjc-load-method"
+ (void)load
{
Class XCElementSnapshotCls = objc_lookUpClass("XCElementSnapshot");
NSAssert(XCElementSnapshotCls != nil, @"Could not locate XCElementSnapshot class");
Method uidMethod = class_getInstanceMethod(self.class, @selector(fb_uid));
class_addMethod(XCElementSnapshotCls, @selector(fb_uid), method_getImplementation(uidMethod), method_getTypeEncoding(uidMethod));
}
#pragma diagnostic pop

- (unsigned long long)fb_accessibiltyId
{
return [FBElementUtils idWithAccessibilityElement:self.accessibilityElement];
Expand All @@ -45,7 +58,10 @@ + (nullable NSString *)wdUIDWithSnapshot:(id<FBXCElementSnapshot>)snapshot

- (NSString *)fb_uid
{
return [self.class wdUIDWithSnapshot:self.snapshot];
if ([self isKindOfClass:FBXCElementSnapshotWrapper.class]) {
return [self.class wdUIDWithSnapshot:self.snapshot];
}
return [FBElementUtils uidWithAccessibilityElement:[self accessibilityElement]];
}

@end
6 changes: 3 additions & 3 deletions WebDriverAgentLib/Categories/XCUIElement+FBUtilities.m
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,10 @@ @implementation XCUIElement (FBUtilities)
XCUIElementQuery *query = onlyChildren
? [self.fb_query childrenMatchingType:type]
: [self.fb_query descendantsMatchingType:type];
NSPredicate *predicate = [NSPredicate predicateWithBlock:^BOOL(id<FBXCElementSnapshot> snapshot, NSDictionary *bindings) {
return [matchedIds containsObject:[FBXCElementSnapshotWrapper wdUIDWithSnapshot:snapshot] ?: @""];
}];

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"%K IN %@",FBStringify(FBXCElementSnapshotWrapper, fb_uid), matchedIds];
[matchedElements addObjectsFromArray:[query matchingPredicate:predicate].allElementsBoundByIndex];

for (XCUIElement *el in matchedElements) {
el.fb_isResolvedNatively = @NO;
}
Expand Down