Skip to content

Commit 045ddb1

Browse files
moar
1 parent e957b5f commit 045ddb1

File tree

5 files changed

+13
-47
lines changed

5 files changed

+13
-47
lines changed

WebDriverAgentLib/Categories/FBXCElementSnapshotWrapper+Helpers.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,10 @@ NS_ASSUME_NONNULL_BEGIN
5858
5959
@param attribute attribute's accessibility identifier. Can be one of
6060
`XC_kAXXCAttribute`-prefixed attribute names.
61-
@param timeout The maximum time is flota seconds to wait until XCTest/Accessbility framework
62-
returns the value of the requested attribute
6361
@param error Error instance in case of a failure
6462
@return value for given accessibility property identifier or nil in case of failure
6563
*/
6664
- (nullable id)fb_attributeValue:(NSString *)attribute
67-
timeout:(NSTimeInterval)timeout
6865
error:(NSError **)error;
6966

7067
/**

WebDriverAgentLib/Categories/FBXCElementSnapshotWrapper+Helpers.m

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

25+
#define ATTRIBUTE_FETCH_WARN_TIME_LIMIT 0.05
26+
2527
inline static BOOL isSnapshotTypeAmongstGivenTypes(id<FBXCElementSnapshot> snapshot,
2628
NSArray<NSNumber *> *types);
2729

@@ -67,38 +69,17 @@ - (NSString *)fb_description
6769
}
6870

6971
- (id)fb_attributeValue:(NSString *)attribute
70-
timeout:(NSTimeInterval)timeout
7172
error:(NSError **)error
7273
{
73-
id<XCTestManager_ManagerInterface> proxy = [FBXCTestDaemonsProxy testRunnerProxy];
74-
dispatch_semaphore_t sem = dispatch_semaphore_create(0);
75-
__block NSDictionary *result = nil;
76-
__block NSError *blockError;
77-
[proxy _XCT_fetchAttributes:@[attribute]
78-
forElement:[self accessibilityElement]
79-
reply:^(NSDictionary *innerResult, NSError *innerError) {
80-
if (nil == innerError) {
81-
result = innerResult;
82-
} else {
83-
blockError = innerError;
84-
}
85-
dispatch_semaphore_signal(sem);
86-
}];
87-
if (0 != dispatch_semaphore_wait(sem, dispatch_time(DISPATCH_TIME_NOW, (int64_t)(timeout * NSEC_PER_SEC)))) {
88-
NSString *timeoutMsg = [NSString stringWithFormat:@"Cannot fetch %@ attribute of '%@' within %@s timeout",
89-
attribute, self.fb_description, @(timeout)];
90-
[[[FBErrorBuilder builder]
91-
withDescription:timeoutMsg]
92-
buildError:error];
93-
return nil;
94-
}
95-
if (nil != result) {
96-
return [result objectForKey:attribute];
97-
}
98-
if (error) {
99-
*error = blockError;
74+
NSDate *start = [NSDate date];
75+
NSDictionary *result = [FBXCAXClientProxy.sharedClient attributesForElement:[self accessibilityElement]
76+
attributes:@[attribute]
77+
error:error];
78+
NSTimeInterval elapsed = ABS([start timeIntervalSinceNow]);
79+
if (elapsed > ATTRIBUTE_FETCH_WARN_TIME_LIMIT) {
80+
NSLog(@"! Fetching of %@ value for %@ took %@s", attribute, self.fb_description, @(elapsed));
10081
}
101-
return nil;
82+
return [result objectForKey:attribute];
10283
}
10384

10485
inline static BOOL areValuesEqual(id value1, id value2);

WebDriverAgentLib/Categories/XCUIElement+FBAccessibility.m

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
#import "XCUIElement+FBUtilities.h"
1515
#import "FBXCElementSnapshotWrapper+Helpers.h"
1616

17-
#define AX_FETCH_TIMEOUT 0.3
18-
1917
@implementation XCUIElement (FBAccessibility)
2018

2119
- (BOOL)fb_isAccessibilityElement
@@ -37,7 +35,6 @@ - (BOOL)fb_isAccessibilityElement
3735

3836
NSError *error;
3937
NSNumber *attributeValue = [self fb_attributeValue:FB_XCAXAIsElementAttributeName
40-
timeout:AX_FETCH_TIMEOUT
4138
error:&error];
4239
if (nil != attributeValue) {
4340
NSMutableDictionary *updatedValue = [NSMutableDictionary dictionaryWithDictionary:self.additionalAttributes ?: @{}];

WebDriverAgentLib/Categories/XCUIElement+FBIsVisible.m

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
#import "XCUIElement+FBVisibleFrame.h"
1717
#import "XCTestPrivateSymbols.h"
1818

19-
#define AX_FETCH_TIMEOUT 0.3
20-
2119
NSNumber* _Nullable fetchSnapshotVisibility(id<FBXCElementSnapshot> snapshot)
2220
{
2321
return nil == snapshot.additionalAttributes ? nil : snapshot.additionalAttributes[FB_XCAXAIsVisibleAttribute];
@@ -61,7 +59,6 @@ - (BOOL)fb_isVisible
6159

6260
NSError *error;
6361
NSNumber *attributeValue = [self fb_attributeValue:FB_XCAXAIsVisibleAttributeName
64-
timeout:AX_FETCH_TIMEOUT
6562
error:&error];
6663
if (nil != attributeValue) {
6764
NSMutableDictionary *updatedValue = [NSMutableDictionary dictionaryWithDictionary:self.additionalAttributes ?: @{}];
@@ -70,12 +67,9 @@ - (BOOL)fb_isVisible
7067
return [attributeValue boolValue];
7168
}
7269

73-
// If we fail to fetch the "true" visibility from AX then fallback to
74-
// the lousy `visibleFrame`-based detection method
75-
BOOL fallbackResult = !CGRectIsEmpty(self.fb_visibleFrame);
76-
NSLog(@"Cannot determine visibility of '%@' natively: %@. Defaulting to: %@",
77-
self.fb_description, error.description, @(fallbackResult));
78-
return fallbackResult;
70+
NSLog(@"Cannot determine visiblity of %@ natively: %@. Defaulting to: %@",
71+
self.fb_description, error.description, @(NO));
72+
return NO;
7973
}
8074

8175
@end

WebDriverAgentLib/Categories/XCUIElement+FBVisibleFrame.m

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
#import "XCUIElement+FBUtilities.h"
1515
#import "XCTestPrivateSymbols.h"
1616

17-
#define VisibleFrameFetchTimeout 0.3
18-
1917
@implementation XCUIElement (FBVisibleFrame)
2018

2119
- (CGRect)fb_visibleFrame
@@ -36,7 +34,6 @@ - (CGRect)fb_visibleFrame
3634
}
3735

3836
NSDictionary *visibleFrameDict = [self fb_attributeValue:FB_XCAXAVisibleFrameAttributeName
39-
timeout:VisibleFrameFetchTimeout
4037
error:nil];
4138
if (nil == visibleFrameDict) {
4239
return thisVisibleFrame;

0 commit comments

Comments
 (0)