Skip to content

Commit fa1a7c5

Browse files
Marek Cirkosfacebook-github-bot
authored andcommitted
Replace isVisible implementation
Summary: Current isVisible implementation calls testmanagerd and at some conditions holds for over 60s. Since isVisible is pretty common call at times this can be really problematic. This implementation is based on frame intersection and hitpoint checking. In performance of both approaches is firmly similar, correctness looks the same as well. However, hitpoint does make connection to testmanagerd as well so it may have same issues as isVisible querry. Because isVisible was only call that caused the problem we have a good chance of fixing it, so let's try. Reviewed By: lawrencelomax Differential Revision: D4762527 fbshipit-source-id: 49f3b140a923877be5fea04a168f1b69d6084b01
1 parent e72c9d3 commit fa1a7c5

File tree

5 files changed

+33
-11
lines changed

5 files changed

+33
-11
lines changed

PrivateHeaders/XCTest/XCElementSnapshot.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
- (id)_uniquelyIdentifyingSwiftCode;
7070
- (BOOL)_isAncestorOfElement:(id)arg1;
7171
- (BOOL)_isDescendantOfElement:(id)arg1;
72-
- (id)_rootElement;
72+
- (XCElementSnapshot *)_rootElement;
7373
- (BOOL)_frameFuzzyMatchesElement:(id)arg1;
7474
- (BOOL)_fuzzyMatchesElement:(id)arg1;
7575
- (BOOL)_matchesElement:(id)arg1;

WebDriverAgentLib/Categories/XCUIElement+FBIsVisible.m

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,13 @@
99

1010
#import "XCUIElement+FBIsVisible.h"
1111

12+
#import "FBApplication.h"
13+
#import "FBConfiguration.h"
14+
#import "FBMathUtils.h"
1215
#import "XCElementSnapshot+FBHelpers.h"
1316
#import "XCTestPrivateSymbols.h"
17+
#import <XCTest/XCUIDevice.h>
18+
1419

1520
@implementation XCUIElement (FBIsVisible)
1621

@@ -29,18 +34,17 @@ @implementation XCElementSnapshot (FBIsVisible)
2934
- (BOOL)fb_isVisible
3035
{
3136
if (CGRectIsEmpty(self.frame) || CGRectIsEmpty(self.visibleFrame)) {
32-
/*
33-
It turns out, that XCTest triggers
34-
Enqueue Failure: UI Testing Failure - Failure fetching attributes for element
35-
<XCAccessibilityElement: 0x60000025f9e0> Device element: Error Domain=XCTestManagerErrorDomain Code=13
36-
"Error copying attributes -25202" UserInfo={NSLocalizedDescription=Error copying attributes -25202} <unknown> 0 1
37-
error in the log if we try to get visibility attribute for an element snapshot, which does not intersect with visible appication area
38-
or if it has zero width/height. Also, XCTest waits for 15 seconds after this line appears in the log, which makes /source command
39-
execution extremely slow for some applications.
40-
*/
4137
return NO;
4238
}
43-
return [(NSNumber *)[self fb_attributeValue:FB_XCAXAIsVisibleAttribute] boolValue];
39+
if ([FBConfiguration shouldUseTestManagerForVisibilityDetection]) {
40+
return [(NSNumber *)[self fb_attributeValue:FB_XCAXAIsVisibleAttribute] boolValue];
41+
}
42+
XCElementSnapshot *app = [self _rootElement];
43+
CGSize screenSize = FBAdjustDimensionsForApplication(app.frame.size, (UIInterfaceOrientation)[XCUIDevice sharedDevice].orientation);
44+
CGRect screenFrame = CGRectMake(0, 0, screenSize.width, screenSize.height);
45+
BOOL rectIntersects = CGRectIntersectsRect(self.visibleFrame, screenFrame);
46+
BOOL isActionable = CGRectContainsPoint(screenFrame, self.hitPoint);
47+
return rectIntersects && isActionable;
4448
}
4549

4650
@end

WebDriverAgentLib/Commands/FBSessionCommands.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#import "FBSessionCommands.h"
1111

1212
#import "FBApplication.h"
13+
#import "FBConfiguration.h"
1314
#import "FBRouteRequest.h"
1415
#import "FBSession.h"
1516
#import "FBApplication.h"
@@ -66,6 +67,8 @@ + (NSArray *)routes
6667
if (!bundleID) {
6768
return FBResponseWithErrorFormat(@"'bundleId' desired capability not provided");
6869
}
70+
[FBConfiguration setShouldUseTestManagerForVisibilityDetection:[requirements[@"shouldUseTestManagerForVisibilityDetection"] boolValue]];
71+
6972
FBApplication *app = [[FBApplication alloc] initPrivateWithPath:appPath bundleID:bundleID];
7073
app.fb_shouldWaitForQuiescence = [requirements[@"shouldWaitForQuiescence"] boolValue];
7174
app.launchArguments = (NSArray<NSString *> *)requirements[@"arguments"] ?: @[];

WebDriverAgentLib/Utilities/FBConfiguration.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ NS_ASSUME_NONNULL_BEGIN
1616
*/
1717
@interface FBConfiguration : NSObject
1818

19+
/*! If set to YES will ask TestManagerDaemon for element visibility */
20+
@property (class, nonatomic, assign) BOOL shouldUseTestManagerForVisibilityDetection;
21+
1922
/**
2023
Switch for enabling/disabling reporting fake collection view cells by Accessibility framework.
2124
If set to YES it will report also invisible cells.

WebDriverAgentLib/Utilities/FBConfiguration.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
static NSUInteger const DefaultStartingPort = 8100;
2020
static NSUInteger const DefaultPortRange = 100;
2121

22+
static BOOL FBShouldUseTestManagerForVisibilityDetection = NO;
23+
2224
@implementation FBConfiguration
2325

2426
#pragma mark Public
@@ -48,6 +50,16 @@ + (BOOL)verboseLoggingEnabled
4850
return [NSProcessInfo.processInfo.environment[@"VERBOSE_LOGGING"] boolValue];
4951
}
5052

53+
+ (void)setShouldUseTestManagerForVisibilityDetection:(BOOL)value
54+
{
55+
FBShouldUseTestManagerForVisibilityDetection = value;
56+
}
57+
58+
+ (BOOL)shouldUseTestManagerForVisibilityDetection
59+
{
60+
return FBShouldUseTestManagerForVisibilityDetection;
61+
}
62+
5163
#pragma mark Private
5264

5365
+ (NSRange)bindingPortRangeFromArguments

0 commit comments

Comments
 (0)