Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mykola-mokhnach committed Jan 16, 2025
1 parent 635f387 commit 4265ccb
Show file tree
Hide file tree
Showing 11 changed files with 120 additions and 41 deletions.
12 changes: 12 additions & 0 deletions WebDriverAgent.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,10 @@
71A7EAFA1E224648001DA4F2 /* FBClassChainQueryParser.m in Sources */ = {isa = PBXBuildFile; fileRef = 71A7EAF81E224648001DA4F2 /* FBClassChainQueryParser.m */; };
71A7EAFC1E229302001DA4F2 /* FBClassChainTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 71A7EAFB1E229302001DA4F2 /* FBClassChainTests.m */; };
71ACF5B8242F2FDC00F0AAD4 /* FBSafariAlertTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 71ACF5B7242F2FDC00F0AAD4 /* FBSafariAlertTests.m */; };
71AE3CF72D38EE8E0039FC36 /* XCUIElement+FBVisibleFrame.h in Headers */ = {isa = PBXBuildFile; fileRef = 71AE3CF52D38EE8E0039FC36 /* XCUIElement+FBVisibleFrame.h */; };
71AE3CF82D38EE8E0039FC36 /* XCUIElement+FBVisibleFrame.m in Sources */ = {isa = PBXBuildFile; fileRef = 71AE3CF62D38EE8E0039FC36 /* XCUIElement+FBVisibleFrame.m */; };
71AE3CF92D38EE8E0039FC36 /* XCUIElement+FBVisibleFrame.h in Headers */ = {isa = PBXBuildFile; fileRef = 71AE3CF52D38EE8E0039FC36 /* XCUIElement+FBVisibleFrame.h */; };
71AE3CFA2D38EE8E0039FC36 /* XCUIElement+FBVisibleFrame.m in Sources */ = {isa = PBXBuildFile; fileRef = 71AE3CF62D38EE8E0039FC36 /* XCUIElement+FBVisibleFrame.m */; };
71B155DA23070ECF00646AFB /* FBHTTPStatusCodes.h in Headers */ = {isa = PBXBuildFile; fileRef = 71B155D923070ECF00646AFB /* FBHTTPStatusCodes.h */; settings = {ATTRIBUTES = (Public, ); }; };
71B155DC230711E900646AFB /* FBCommandStatus.m in Sources */ = {isa = PBXBuildFile; fileRef = 71B155DB230711E900646AFB /* FBCommandStatus.m */; };
71B155DF23080CA600646AFB /* FBProtocolHelpers.h in Headers */ = {isa = PBXBuildFile; fileRef = 71B155DD23080CA600646AFB /* FBProtocolHelpers.h */; };
Expand Down Expand Up @@ -1050,6 +1054,8 @@
71A7EAF81E224648001DA4F2 /* FBClassChainQueryParser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FBClassChainQueryParser.m; sourceTree = "<group>"; };
71A7EAFB1E229302001DA4F2 /* FBClassChainTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FBClassChainTests.m; sourceTree = "<group>"; };
71ACF5B7242F2FDC00F0AAD4 /* FBSafariAlertTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FBSafariAlertTests.m; sourceTree = "<group>"; };
71AE3CF52D38EE8E0039FC36 /* XCUIElement+FBVisibleFrame.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "XCUIElement+FBVisibleFrame.h"; sourceTree = "<group>"; };
71AE3CF62D38EE8E0039FC36 /* XCUIElement+FBVisibleFrame.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "XCUIElement+FBVisibleFrame.m"; sourceTree = "<group>"; };
71B155D923070ECF00646AFB /* FBHTTPStatusCodes.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FBHTTPStatusCodes.h; sourceTree = "<group>"; };
71B155DB230711E900646AFB /* FBCommandStatus.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FBCommandStatus.m; sourceTree = "<group>"; };
71B155DD23080CA600646AFB /* FBProtocolHelpers.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FBProtocolHelpers.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1781,6 +1787,8 @@
71B49EC61ED1A58100D51AD6 /* XCUIElement+FBUID.m */,
EEE3763F1D59F81400ED88DD /* XCUIElement+FBUtilities.h */,
EEE376401D59F81400ED88DD /* XCUIElement+FBUtilities.m */,
71AE3CF52D38EE8E0039FC36 /* XCUIElement+FBVisibleFrame.h */,
71AE3CF62D38EE8E0039FC36 /* XCUIElement+FBVisibleFrame.m */,
EEE376471D59FAE900ED88DD /* XCUIElement+FBWebDriverAttributes.h */,
EEE376481D59FAE900ED88DD /* XCUIElement+FBWebDriverAttributes.m */,
641EE7042240CDCF00173FCB /* XCUIElement+FBTVFocuse.h */,
Expand Down Expand Up @@ -2399,6 +2407,7 @@
641EE6A42240C5CA00173FCB /* FBCommandHandler.h in Headers */,
641EE6A52240C5CA00173FCB /* FBSessionCommands.h in Headers */,
641EE70C2240CE2D00173FCB /* FBTVNavigationTracker.h in Headers */,
71AE3CF72D38EE8E0039FC36 /* XCUIElement+FBVisibleFrame.h in Headers */,
641EE6A62240C5CA00173FCB /* FBImageProcessor.h in Headers */,
641EE6A72240C5CA00173FCB /* FBSession-Private.h in Headers */,
641EE6A82240C5CA00173FCB /* NSString+FBXMLSafeString.h in Headers */,
Expand Down Expand Up @@ -2585,6 +2594,7 @@
714EAA0D2673FDFE005C5B47 /* FBCapabilities.h in Headers */,
EE35AD5C1E3B77D600A02D78 /* XCTNSPredicateExpectation.h in Headers */,
EE35AD521E3B77D600A02D78 /* XCTestObservationCenter.h in Headers */,
71AE3CF92D38EE8E0039FC36 /* XCUIElement+FBVisibleFrame.h in Headers */,
EE35AD5B1E3B77D600A02D78 /* XCTNSNotificationExpectation.h in Headers */,
E444DC97249131D40060D7EB /* HTTPServer.h in Headers */,
E444DCAE24913C220060D7EB /* HTTPResponseProxy.h in Headers */,
Expand Down Expand Up @@ -3160,6 +3170,7 @@
641EE60E2240C5CA00173FCB /* XCUIElement+FBTyping.m in Sources */,
641EE60F2240C5CA00173FCB /* XCUIElement+FBAccessibility.m in Sources */,
641EE6102240C5CA00173FCB /* FBImageUtils.m in Sources */,
71AE3CF82D38EE8E0039FC36 /* XCUIElement+FBVisibleFrame.m in Sources */,
641EE6112240C5CA00173FCB /* FBSession.m in Sources */,
641EE6122240C5CA00173FCB /* FBFindElementCommands.m in Sources */,
71A5C67629A4F39600421C37 /* XCTIssue+FBPatcher.m in Sources */,
Expand Down Expand Up @@ -3232,6 +3243,7 @@
713AE576243A53BE0000D657 /* FBW3CActionsHelpers.m in Sources */,
71B155E123080CA600646AFB /* FBProtocolHelpers.m in Sources */,
EE158AB11CBD456F00A3E3F0 /* XCUIElement+FBIsVisible.m in Sources */,
71AE3CFA2D38EE8E0039FC36 /* XCUIElement+FBVisibleFrame.m in Sources */,
EEBBD48C1D47746D00656A81 /* XCUIElement+FBFind.m in Sources */,
EE158ADD1CBD456F00A3E3F0 /* FBResponsePayload.m in Sources */,
E444DCB524913C220060D7EB /* RouteRequest.m in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,6 @@ NS_ASSUME_NONNULL_BEGIN
/**! Human-readable snapshot description */
- (NSString *)fb_description;

/**
Returns the snapshot visibleFrame with a fallback to direct attribute retrieval from FBXCAXClient in case of a snapshot fault (nil visibleFrame)
@return the snapshot visibleFrame
*/
- (CGRect)fb_visibleFrameWithFallback;

/**
Wrapper for Apple's hitpoint, thats resolves few known issues
Expand Down
27 changes: 0 additions & 27 deletions WebDriverAgentLib/Categories/FBXCElementSnapshotWrapper+Helpers.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
#import "XCUIElement+FBWebDriverAttributes.h"
#import "XCUIHitPointResult.h"

#define VisibleFrameFetchTimeout 0.3

inline static BOOL isSnapshotTypeAmongstGivenTypes(id<FBXCElementSnapshot> snapshot,
NSArray<NSNumber *> *types);

Expand Down Expand Up @@ -172,31 +170,6 @@ - (BOOL)fb_framelessFuzzyMatchesElement:(id<FBXCElementSnapshot>)snapshot
return targetCellSnapshot;
}

- (CGRect)fb_visibleFrameWithFallback
{
CGRect thisVisibleFrame = [self visibleFrame];
if (!CGRectIsEmpty(thisVisibleFrame)) {
return thisVisibleFrame;
}

NSDictionary *visibleFrameDict = [self fb_attributeValue:FB_XCAXAVisibleFrameAttributeName
timeout:VisibleFrameFetchTimeout
error:nil];
if (visibleFrameDict == nil) {
return thisVisibleFrame;
}

id x = [visibleFrameDict objectForKey:@"X"];
id y = [visibleFrameDict objectForKey:@"Y"];
id height = [visibleFrameDict objectForKey:@"Height"];
id width = [visibleFrameDict objectForKey:@"Width"];
if (x != nil && y != nil && height != nil && width != nil) {
return CGRectMake([x doubleValue], [y doubleValue], [width doubleValue], [height doubleValue]);
}

return thisVisibleFrame;
}

- (NSValue *)fb_hitPoint
{
NSError *error;
Expand Down
3 changes: 3 additions & 0 deletions WebDriverAgentLib/Categories/XCUIElement+FBAccessibility.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ - (BOOL)fb_isAccessibilityElement
timeout:AX_FETCH_TIMEOUT
error:&error];
if (nil != attributeValue) {
NSMutableDictionary *updatedValue = [NSMutableDictionary dictionaryWithDictionary:self.additionalAttributes ?: @{}];
[updatedValue setObject:attributeValue forKey:FB_XCAXAIsElementAttribute];
self.additionalAttributes = updatedValue.copy;
return [attributeValue boolValue];
}

Expand Down
8 changes: 6 additions & 2 deletions WebDriverAgentLib/Categories/XCUIElement+FBIsVisible.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#import "FBXCodeCompatibility.h"
#import "FBXCElementSnapshotWrapper+Helpers.h"
#import "XCUIElement+FBUtilities.h"
#import "XCUIElement+FBVisibleFrame.h"
#import "XCTestPrivateSymbols.h"

#define AX_FETCH_TIMEOUT 0.3
Expand Down Expand Up @@ -69,12 +70,15 @@ - (BOOL)fb_isVisible
timeout:AX_FETCH_TIMEOUT
error:&error];
if (nil != attributeValue) {
NSMutableDictionary *updatedValue = [NSMutableDictionary dictionaryWithDictionary:self.additionalAttributes ?: @{}];
[updatedValue setObject:attributeValue forKey:FB_XCAXAIsVisibleAttribute];
self.additionalAttributes = updatedValue.copy;
return [attributeValue boolValue];
}

// If we fail to fetch the "true" visibility from AX then fallback to
// the lousy `hittable`-based detection method
BOOL fallbackResult = nil != [self fb_hitPoint];
// the lousy `visibleFrame`-based detection method
BOOL fallbackResult = !CGRectIsEmpty(self.fb_visibleFrame);
NSLog(@"Cannot determine '%@' visibility natively: %@. Defaulting to: %@",
self.fb_description, error.description, @(fallbackResult));
return fallbackResult;
Expand Down
3 changes: 2 additions & 1 deletion WebDriverAgentLib/Categories/XCUIElement+FBScrolling.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#import "XCUIApplication.h"
#import "XCUICoordinate.h"
#import "XCUIElement+FBIsVisible.h"
#import "XCUIElement+FBVisibleFrame.h"
#import "XCUIElement.h"
#import "XCUIElement+FBUtilities.h"
#import "XCUIElement+FBWebDriverAttributes.h"
Expand Down Expand Up @@ -208,7 +209,7 @@ - (BOOL)fb_scrollToVisibleWithNormalizedScrollDistance:(CGFloat)normalizedScroll
// Trying fb_cachedSnapshot first
FBXCElementSnapshotWrapper *targetCellSnapshotWrapped = [FBXCElementSnapshotWrapper ensureWrapped:[self fb_takeSnapshot:YES]];
targetCellSnapshot = [targetCellSnapshotWrapped fb_parentCellSnapshot];
CGRect visibleFrame = [FBXCElementSnapshotWrapper ensureWrapped:targetCellSnapshot].fb_visibleFrameWithFallback;
CGRect visibleFrame = [FBXCElementSnapshotWrapper ensureWrapped:targetCellSnapshot].fb_visibleFrame;

CGVector scrollVector = CGVectorMake(visibleFrame.size.width - targetCellSnapshot.frame.size.width,
visibleFrame.size.height - targetCellSnapshot.frame.size.height
Expand Down
36 changes: 36 additions & 0 deletions WebDriverAgentLib/Categories/XCUIElement+FBVisibleFrame.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/

#import "FBXCElementSnapshotWrapper.h"

NS_ASSUME_NONNULL_BEGIN

@interface XCUIElement (FBVisibleFrame)

/**
Returns the snapshot visibleFrame with a fallback to direct attribute retrieval from FBXCAXClient in case of a snapshot fault (nil visibleFrame)
@return the snapshot visibleFrame
*/
- (CGRect)fb_visibleFrame;

@end

@interface FBXCElementSnapshotWrapper (FBVisibleFrame)

/**
Returns the snapshot visibleFrame with a fallback to direct attribute retrieval from FBXCAXClient in case of a snapshot fault (nil visibleFrame)
@return the snapshot visibleFrame
*/
- (CGRect)fb_visibleFrame;

@end

NS_ASSUME_NONNULL_END
56 changes: 56 additions & 0 deletions WebDriverAgentLib/Categories/XCUIElement+FBVisibleFrame.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/

#import "XCUIElement+FBVisibleFrame.h"
#import "FBElementUtils.h"
#import "FBXCodeCompatibility.h"
#import "FBXCElementSnapshotWrapper+Helpers.h"
#import "XCUIElement+FBUtilities.h"
#import "XCTestPrivateSymbols.h"

#define VisibleFrameFetchTimeout 0.3

@implementation XCUIElement (FBVisibleFrame)

- (CGRect)fb_visibleFrame
{
id<FBXCElementSnapshot> snapshot = [self fb_takeSnapshot:NO];
return [FBXCElementSnapshotWrapper ensureWrapped:snapshot].fb_visibleFrame;
}

@end

@implementation FBXCElementSnapshotWrapper (FBVisibleFrame)

- (CGRect)fb_visibleFrame
{
CGRect thisVisibleFrame = [self visibleFrame];
if (!CGRectIsEmpty(thisVisibleFrame)) {
return thisVisibleFrame;
}

NSDictionary *visibleFrameDict = [self fb_attributeValue:FB_XCAXAVisibleFrameAttributeName
timeout:VisibleFrameFetchTimeout
error:nil];
if (nil == visibleFrameDict) {
return thisVisibleFrame;
}

id x = [visibleFrameDict objectForKey:@"X"];
id y = [visibleFrameDict objectForKey:@"Y"];
id height = [visibleFrameDict objectForKey:@"Height"];
id width = [visibleFrameDict objectForKey:@"Width"];
if (x != nil && y != nil && height != nil && width != nil) {
return CGRectMake([x doubleValue], [y doubleValue], [width doubleValue], [height doubleValue]);
}

return thisVisibleFrame;
}

@end
2 changes: 0 additions & 2 deletions WebDriverAgentLib/Utilities/FBXCAXClientProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
#import <XCTest/XCTest.h>
#import "FBXCElementSnapshot.h"

extern const NSTimeInterval FBDefaultAxTimeout;

@protocol FBXCAccessibilityElement;

NS_ASSUME_NONNULL_BEGIN
Expand Down
2 changes: 0 additions & 2 deletions WebDriverAgentLib/Utilities/FBXCAXClientProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

static id FBAXClient = nil;

const NSTimeInterval FBDefaultAxTimeout = 60.0;

@implementation FBXCAXClientProxy

+ (instancetype)sharedClient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,9 @@ - (NSArray *)_allDescendants
return @[];
}

- (CGRect)visibleFrame
{
return CGRectZero;
}

@end

0 comments on commit 4265ccb

Please sign in to comment.