Skip to content

Commit 4265ccb

Browse files
Address comments
1 parent 635f387 commit 4265ccb

File tree

11 files changed

+120
-41
lines changed

11 files changed

+120
-41
lines changed

WebDriverAgent.xcodeproj/project.pbxproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,10 @@
451451
71A7EAFA1E224648001DA4F2 /* FBClassChainQueryParser.m in Sources */ = {isa = PBXBuildFile; fileRef = 71A7EAF81E224648001DA4F2 /* FBClassChainQueryParser.m */; };
452452
71A7EAFC1E229302001DA4F2 /* FBClassChainTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 71A7EAFB1E229302001DA4F2 /* FBClassChainTests.m */; };
453453
71ACF5B8242F2FDC00F0AAD4 /* FBSafariAlertTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 71ACF5B7242F2FDC00F0AAD4 /* FBSafariAlertTests.m */; };
454+
71AE3CF72D38EE8E0039FC36 /* XCUIElement+FBVisibleFrame.h in Headers */ = {isa = PBXBuildFile; fileRef = 71AE3CF52D38EE8E0039FC36 /* XCUIElement+FBVisibleFrame.h */; };
455+
71AE3CF82D38EE8E0039FC36 /* XCUIElement+FBVisibleFrame.m in Sources */ = {isa = PBXBuildFile; fileRef = 71AE3CF62D38EE8E0039FC36 /* XCUIElement+FBVisibleFrame.m */; };
456+
71AE3CF92D38EE8E0039FC36 /* XCUIElement+FBVisibleFrame.h in Headers */ = {isa = PBXBuildFile; fileRef = 71AE3CF52D38EE8E0039FC36 /* XCUIElement+FBVisibleFrame.h */; };
457+
71AE3CFA2D38EE8E0039FC36 /* XCUIElement+FBVisibleFrame.m in Sources */ = {isa = PBXBuildFile; fileRef = 71AE3CF62D38EE8E0039FC36 /* XCUIElement+FBVisibleFrame.m */; };
454458
71B155DA23070ECF00646AFB /* FBHTTPStatusCodes.h in Headers */ = {isa = PBXBuildFile; fileRef = 71B155D923070ECF00646AFB /* FBHTTPStatusCodes.h */; settings = {ATTRIBUTES = (Public, ); }; };
455459
71B155DC230711E900646AFB /* FBCommandStatus.m in Sources */ = {isa = PBXBuildFile; fileRef = 71B155DB230711E900646AFB /* FBCommandStatus.m */; };
456460
71B155DF23080CA600646AFB /* FBProtocolHelpers.h in Headers */ = {isa = PBXBuildFile; fileRef = 71B155DD23080CA600646AFB /* FBProtocolHelpers.h */; };
@@ -1050,6 +1054,8 @@
10501054
71A7EAF81E224648001DA4F2 /* FBClassChainQueryParser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FBClassChainQueryParser.m; sourceTree = "<group>"; };
10511055
71A7EAFB1E229302001DA4F2 /* FBClassChainTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FBClassChainTests.m; sourceTree = "<group>"; };
10521056
71ACF5B7242F2FDC00F0AAD4 /* FBSafariAlertTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FBSafariAlertTests.m; sourceTree = "<group>"; };
1057+
71AE3CF52D38EE8E0039FC36 /* XCUIElement+FBVisibleFrame.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "XCUIElement+FBVisibleFrame.h"; sourceTree = "<group>"; };
1058+
71AE3CF62D38EE8E0039FC36 /* XCUIElement+FBVisibleFrame.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "XCUIElement+FBVisibleFrame.m"; sourceTree = "<group>"; };
10531059
71B155D923070ECF00646AFB /* FBHTTPStatusCodes.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FBHTTPStatusCodes.h; sourceTree = "<group>"; };
10541060
71B155DB230711E900646AFB /* FBCommandStatus.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FBCommandStatus.m; sourceTree = "<group>"; };
10551061
71B155DD23080CA600646AFB /* FBProtocolHelpers.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FBProtocolHelpers.h; sourceTree = "<group>"; };
@@ -1781,6 +1787,8 @@
17811787
71B49EC61ED1A58100D51AD6 /* XCUIElement+FBUID.m */,
17821788
EEE3763F1D59F81400ED88DD /* XCUIElement+FBUtilities.h */,
17831789
EEE376401D59F81400ED88DD /* XCUIElement+FBUtilities.m */,
1790+
71AE3CF52D38EE8E0039FC36 /* XCUIElement+FBVisibleFrame.h */,
1791+
71AE3CF62D38EE8E0039FC36 /* XCUIElement+FBVisibleFrame.m */,
17841792
EEE376471D59FAE900ED88DD /* XCUIElement+FBWebDriverAttributes.h */,
17851793
EEE376481D59FAE900ED88DD /* XCUIElement+FBWebDriverAttributes.m */,
17861794
641EE7042240CDCF00173FCB /* XCUIElement+FBTVFocuse.h */,
@@ -2399,6 +2407,7 @@
23992407
641EE6A42240C5CA00173FCB /* FBCommandHandler.h in Headers */,
24002408
641EE6A52240C5CA00173FCB /* FBSessionCommands.h in Headers */,
24012409
641EE70C2240CE2D00173FCB /* FBTVNavigationTracker.h in Headers */,
2410+
71AE3CF72D38EE8E0039FC36 /* XCUIElement+FBVisibleFrame.h in Headers */,
24022411
641EE6A62240C5CA00173FCB /* FBImageProcessor.h in Headers */,
24032412
641EE6A72240C5CA00173FCB /* FBSession-Private.h in Headers */,
24042413
641EE6A82240C5CA00173FCB /* NSString+FBXMLSafeString.h in Headers */,
@@ -2585,6 +2594,7 @@
25852594
714EAA0D2673FDFE005C5B47 /* FBCapabilities.h in Headers */,
25862595
EE35AD5C1E3B77D600A02D78 /* XCTNSPredicateExpectation.h in Headers */,
25872596
EE35AD521E3B77D600A02D78 /* XCTestObservationCenter.h in Headers */,
2597+
71AE3CF92D38EE8E0039FC36 /* XCUIElement+FBVisibleFrame.h in Headers */,
25882598
EE35AD5B1E3B77D600A02D78 /* XCTNSNotificationExpectation.h in Headers */,
25892599
E444DC97249131D40060D7EB /* HTTPServer.h in Headers */,
25902600
E444DCAE24913C220060D7EB /* HTTPResponseProxy.h in Headers */,
@@ -3160,6 +3170,7 @@
31603170
641EE60E2240C5CA00173FCB /* XCUIElement+FBTyping.m in Sources */,
31613171
641EE60F2240C5CA00173FCB /* XCUIElement+FBAccessibility.m in Sources */,
31623172
641EE6102240C5CA00173FCB /* FBImageUtils.m in Sources */,
3173+
71AE3CF82D38EE8E0039FC36 /* XCUIElement+FBVisibleFrame.m in Sources */,
31633174
641EE6112240C5CA00173FCB /* FBSession.m in Sources */,
31643175
641EE6122240C5CA00173FCB /* FBFindElementCommands.m in Sources */,
31653176
71A5C67629A4F39600421C37 /* XCTIssue+FBPatcher.m in Sources */,
@@ -3232,6 +3243,7 @@
32323243
713AE576243A53BE0000D657 /* FBW3CActionsHelpers.m in Sources */,
32333244
71B155E123080CA600646AFB /* FBProtocolHelpers.m in Sources */,
32343245
EE158AB11CBD456F00A3E3F0 /* XCUIElement+FBIsVisible.m in Sources */,
3246+
71AE3CFA2D38EE8E0039FC36 /* XCUIElement+FBVisibleFrame.m in Sources */,
32353247
EEBBD48C1D47746D00656A81 /* XCUIElement+FBFind.m in Sources */,
32363248
EE158ADD1CBD456F00A3E3F0 /* FBResponsePayload.m in Sources */,
32373249
E444DCB524913C220060D7EB /* RouteRequest.m in Sources */,

WebDriverAgentLib/Categories/FBXCElementSnapshotWrapper+Helpers.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,6 @@ NS_ASSUME_NONNULL_BEGIN
9292
/**! Human-readable snapshot description */
9393
- (NSString *)fb_description;
9494

95-
/**
96-
Returns the snapshot visibleFrame with a fallback to direct attribute retrieval from FBXCAXClient in case of a snapshot fault (nil visibleFrame)
97-
98-
@return the snapshot visibleFrame
99-
*/
100-
- (CGRect)fb_visibleFrameWithFallback;
101-
10295
/**
10396
Wrapper for Apple's hitpoint, thats resolves few known issues
10497

WebDriverAgentLib/Categories/FBXCElementSnapshotWrapper+Helpers.m

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
#import "XCUIElement+FBWebDriverAttributes.h"
2323
#import "XCUIHitPointResult.h"
2424

25-
#define VisibleFrameFetchTimeout 0.3
26-
2725
inline static BOOL isSnapshotTypeAmongstGivenTypes(id<FBXCElementSnapshot> snapshot,
2826
NSArray<NSNumber *> *types);
2927

@@ -172,31 +170,6 @@ - (BOOL)fb_framelessFuzzyMatchesElement:(id<FBXCElementSnapshot>)snapshot
172170
return targetCellSnapshot;
173171
}
174172

175-
- (CGRect)fb_visibleFrameWithFallback
176-
{
177-
CGRect thisVisibleFrame = [self visibleFrame];
178-
if (!CGRectIsEmpty(thisVisibleFrame)) {
179-
return thisVisibleFrame;
180-
}
181-
182-
NSDictionary *visibleFrameDict = [self fb_attributeValue:FB_XCAXAVisibleFrameAttributeName
183-
timeout:VisibleFrameFetchTimeout
184-
error:nil];
185-
if (visibleFrameDict == nil) {
186-
return thisVisibleFrame;
187-
}
188-
189-
id x = [visibleFrameDict objectForKey:@"X"];
190-
id y = [visibleFrameDict objectForKey:@"Y"];
191-
id height = [visibleFrameDict objectForKey:@"Height"];
192-
id width = [visibleFrameDict objectForKey:@"Width"];
193-
if (x != nil && y != nil && height != nil && width != nil) {
194-
return CGRectMake([x doubleValue], [y doubleValue], [width doubleValue], [height doubleValue]);
195-
}
196-
197-
return thisVisibleFrame;
198-
}
199-
200173
- (NSValue *)fb_hitPoint
201174
{
202175
NSError *error;

WebDriverAgentLib/Categories/XCUIElement+FBAccessibility.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ - (BOOL)fb_isAccessibilityElement
4040
timeout:AX_FETCH_TIMEOUT
4141
error:&error];
4242
if (nil != attributeValue) {
43+
NSMutableDictionary *updatedValue = [NSMutableDictionary dictionaryWithDictionary:self.additionalAttributes ?: @{}];
44+
[updatedValue setObject:attributeValue forKey:FB_XCAXAIsElementAttribute];
45+
self.additionalAttributes = updatedValue.copy;
4346
return [attributeValue boolValue];
4447
}
4548

WebDriverAgentLib/Categories/XCUIElement+FBIsVisible.m

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#import "FBXCodeCompatibility.h"
1414
#import "FBXCElementSnapshotWrapper+Helpers.h"
1515
#import "XCUIElement+FBUtilities.h"
16+
#import "XCUIElement+FBVisibleFrame.h"
1617
#import "XCTestPrivateSymbols.h"
1718

1819
#define AX_FETCH_TIMEOUT 0.3
@@ -69,12 +70,15 @@ - (BOOL)fb_isVisible
6970
timeout:AX_FETCH_TIMEOUT
7071
error:&error];
7172
if (nil != attributeValue) {
73+
NSMutableDictionary *updatedValue = [NSMutableDictionary dictionaryWithDictionary:self.additionalAttributes ?: @{}];
74+
[updatedValue setObject:attributeValue forKey:FB_XCAXAIsVisibleAttribute];
75+
self.additionalAttributes = updatedValue.copy;
7276
return [attributeValue boolValue];
7377
}
7478

7579
// If we fail to fetch the "true" visibility from AX then fallback to
76-
// the lousy `hittable`-based detection method
77-
BOOL fallbackResult = nil != [self fb_hitPoint];
80+
// the lousy `visibleFrame`-based detection method
81+
BOOL fallbackResult = !CGRectIsEmpty(self.fb_visibleFrame);
7882
NSLog(@"Cannot determine '%@' visibility natively: %@. Defaulting to: %@",
7983
self.fb_description, error.description, @(fallbackResult));
8084
return fallbackResult;

WebDriverAgentLib/Categories/XCUIElement+FBScrolling.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#import "XCUIApplication.h"
2121
#import "XCUICoordinate.h"
2222
#import "XCUIElement+FBIsVisible.h"
23+
#import "XCUIElement+FBVisibleFrame.h"
2324
#import "XCUIElement.h"
2425
#import "XCUIElement+FBUtilities.h"
2526
#import "XCUIElement+FBWebDriverAttributes.h"
@@ -208,7 +209,7 @@ - (BOOL)fb_scrollToVisibleWithNormalizedScrollDistance:(CGFloat)normalizedScroll
208209
// Trying fb_cachedSnapshot first
209210
FBXCElementSnapshotWrapper *targetCellSnapshotWrapped = [FBXCElementSnapshotWrapper ensureWrapped:[self fb_takeSnapshot:YES]];
210211
targetCellSnapshot = [targetCellSnapshotWrapped fb_parentCellSnapshot];
211-
CGRect visibleFrame = [FBXCElementSnapshotWrapper ensureWrapped:targetCellSnapshot].fb_visibleFrameWithFallback;
212+
CGRect visibleFrame = [FBXCElementSnapshotWrapper ensureWrapped:targetCellSnapshot].fb_visibleFrame;
212213

213214
CGVector scrollVector = CGVectorMake(visibleFrame.size.width - targetCellSnapshot.frame.size.width,
214215
visibleFrame.size.height - targetCellSnapshot.frame.size.height
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Copyright (c) 2015-present, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
#import "FBXCElementSnapshotWrapper.h"
11+
12+
NS_ASSUME_NONNULL_BEGIN
13+
14+
@interface XCUIElement (FBVisibleFrame)
15+
16+
/**
17+
Returns the snapshot visibleFrame with a fallback to direct attribute retrieval from FBXCAXClient in case of a snapshot fault (nil visibleFrame)
18+
19+
@return the snapshot visibleFrame
20+
*/
21+
- (CGRect)fb_visibleFrame;
22+
23+
@end
24+
25+
@interface FBXCElementSnapshotWrapper (FBVisibleFrame)
26+
27+
/**
28+
Returns the snapshot visibleFrame with a fallback to direct attribute retrieval from FBXCAXClient in case of a snapshot fault (nil visibleFrame)
29+
30+
@return the snapshot visibleFrame
31+
*/
32+
- (CGRect)fb_visibleFrame;
33+
34+
@end
35+
36+
NS_ASSUME_NONNULL_END
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/**
2+
* Copyright (c) 2015-present, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
#import "XCUIElement+FBVisibleFrame.h"
11+
#import "FBElementUtils.h"
12+
#import "FBXCodeCompatibility.h"
13+
#import "FBXCElementSnapshotWrapper+Helpers.h"
14+
#import "XCUIElement+FBUtilities.h"
15+
#import "XCTestPrivateSymbols.h"
16+
17+
#define VisibleFrameFetchTimeout 0.3
18+
19+
@implementation XCUIElement (FBVisibleFrame)
20+
21+
- (CGRect)fb_visibleFrame
22+
{
23+
id<FBXCElementSnapshot> snapshot = [self fb_takeSnapshot:NO];
24+
return [FBXCElementSnapshotWrapper ensureWrapped:snapshot].fb_visibleFrame;
25+
}
26+
27+
@end
28+
29+
@implementation FBXCElementSnapshotWrapper (FBVisibleFrame)
30+
31+
- (CGRect)fb_visibleFrame
32+
{
33+
CGRect thisVisibleFrame = [self visibleFrame];
34+
if (!CGRectIsEmpty(thisVisibleFrame)) {
35+
return thisVisibleFrame;
36+
}
37+
38+
NSDictionary *visibleFrameDict = [self fb_attributeValue:FB_XCAXAVisibleFrameAttributeName
39+
timeout:VisibleFrameFetchTimeout
40+
error:nil];
41+
if (nil == visibleFrameDict) {
42+
return thisVisibleFrame;
43+
}
44+
45+
id x = [visibleFrameDict objectForKey:@"X"];
46+
id y = [visibleFrameDict objectForKey:@"Y"];
47+
id height = [visibleFrameDict objectForKey:@"Height"];
48+
id width = [visibleFrameDict objectForKey:@"Width"];
49+
if (x != nil && y != nil && height != nil && width != nil) {
50+
return CGRectMake([x doubleValue], [y doubleValue], [width doubleValue], [height doubleValue]);
51+
}
52+
53+
return thisVisibleFrame;
54+
}
55+
56+
@end

WebDriverAgentLib/Utilities/FBXCAXClientProxy.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
#import <XCTest/XCTest.h>
1111
#import "FBXCElementSnapshot.h"
1212

13-
extern const NSTimeInterval FBDefaultAxTimeout;
14-
1513
@protocol FBXCAccessibilityElement;
1614

1715
NS_ASSUME_NONNULL_BEGIN

WebDriverAgentLib/Utilities/FBXCAXClientProxy.m

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717

1818
static id FBAXClient = nil;
1919

20-
const NSTimeInterval FBDefaultAxTimeout = 60.0;
21-
2220
@implementation FBXCAXClientProxy
2321

2422
+ (instancetype)sharedClient

0 commit comments

Comments
 (0)