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

fix: Respect 'snapshotMaxDepth' setting while fetching visibility and accessibility #975

Closed
wants to merge 4 commits into from
Closed
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: 4 additions & 0 deletions WebDriverAgentLib/Categories/XCUIElement+FBAccessibility.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ - (BOOL)fb_isAccessibilityElement
return isAccessibilityElement.boolValue;
}

if (nil != self.parent && FBConfiguration.snapshotMaxDepth > 0 && self.depth > FBConfiguration.snapshotMaxDepth) {
return NO;
}

NSError *error;
NSNumber *attributeValue = [self fb_attributeValue:FB_XCAXAIsElementAttributeName
error:&error];
Expand Down
8 changes: 5 additions & 3 deletions WebDriverAgentLib/Categories/XCUIElement+FBIsVisible.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@

#import "XCUIElement+FBIsVisible.h"

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

NSNumber* _Nullable fetchSnapshotVisibility(id<FBXCElementSnapshot> snapshot)
Expand Down Expand Up @@ -50,6 +48,10 @@ - (BOOL)fb_isVisible
return isVisible.boolValue;
}

if (nil != self.parent && FBConfiguration.snapshotMaxDepth > 0 && self.depth > FBConfiguration.snapshotMaxDepth) {
return NO;
}

// Fetching the attribute value is expensive.
// Shortcircuit here to save time and assume if any of descendants
// is already determined as visible then the container should be visible as well
Expand Down
2 changes: 1 addition & 1 deletion WebDriverAgentLib/Categories/XCUIElement+FBResolve.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ NS_ASSUME_NONNULL_BEGIN
@return Either the same element instance if `fb_isResolvedNatively` was set to NO (usually the cache for elements
matched by xpath locators) or the stable instance of the self element based on the query by element's UUID.
*/
- (XCUIElement *)fb_stableInstanceWithUid:(NSString *)uid;
- (XCUIElement *)fb_stableInstanceWithUid:(nullable NSString *)uid;

@end

Expand Down
2 changes: 1 addition & 1 deletion WebDriverAgentLib/Utilities/FBConfiguration.m
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ + (void)resetSessionSettings
FBDismissAlertButtonSelector = @"";
FBWaitForIdleTimeout = 10.;
FBAnimationCoolOffTimeout = 2.;
// 50 should be enough for the majority of the cases. The performance is acceptable for values up to 100.
// 60 should be enough for the majority of the cases. The performance is acceptable for values up to 100.
FBSetCustomParameterForElementSnapshot(FBSnapshotMaxDepthKey, @50);
FBUseClearTextShortcut = YES;
#if !TARGET_OS_TV
Expand Down
5 changes: 0 additions & 5 deletions WebDriverAgentLib/Utilities/FBXCAXClientProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ NS_ASSUME_NONNULL_BEGIN

- (BOOL)setAXTimeout:(NSTimeInterval)timeout error:(NSError **)error;

- (nullable id<FBXCElementSnapshot>)snapshotForElement:(id<FBXCAccessibilityElement>)element
attributes:(nullable NSArray<NSString *> *)attributes
inDepth:(BOOL)inDepth
error:(NSError **)error;

- (NSArray<id<FBXCAccessibilityElement>> *)activeApplications;

- (id<FBXCAccessibilityElement>)systemApplication;
Expand Down
18 changes: 0 additions & 18 deletions WebDriverAgentLib/Utilities/FBXCAXClientProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,6 @@ - (BOOL)setAXTimeout:(NSTimeInterval)timeout error:(NSError **)error
return [FBAXClient _setAXTimeout:timeout error:error];
}

- (id<FBXCElementSnapshot>)snapshotForElement:(id<FBXCAccessibilityElement>)element
attributes:(NSArray<NSString *> *)attributes
inDepth:(BOOL)inDepth
error:(NSError **)error
{
NSMutableDictionary *parameters = [NSMutableDictionary dictionaryWithDictionary:self.defaultParameters];
if (!inDepth) {
parameters[FBSnapshotMaxDepthKey] = @1;
}

id result = [FBAXClient requestSnapshotForElement:element
attributes:attributes
parameters:[parameters copy]
error:error];
id<FBXCElementSnapshot> snapshot = [result valueForKey:@"_rootElementSnapshot"];
return nil == snapshot ? result : snapshot;
}

- (NSArray<id<FBXCAccessibilityElement>> *)activeApplications
{
return [FBAXClient activeApplications];
Expand Down
Loading