diff --git a/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.h b/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.h index d984e0b9e..d15aeba68 100644 --- a/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.h +++ b/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.h @@ -12,6 +12,7 @@ NS_ASSUME_NONNULL_BEGIN +extern NSString *const FBSnapshotMaxChildrenKey; extern NSString *const FBSnapshotMaxDepthKey; void FBSetCustomParameterForElementSnapshot (NSString* name, id value); diff --git a/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.m b/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.m index 0d39ba0b2..8698eb734 100644 --- a/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.m +++ b/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.m @@ -19,6 +19,7 @@ @"maxDepth" : (int)2147483647 */ NSString *const FBSnapshotMaxDepthKey = @"maxDepth"; +NSString *const FBSnapshotMaxChildrenKey = @"maxChildren"; static id (*original_defaultParameters)(id, SEL); static id (*original_snapshotParameters)(id, SEL); diff --git a/WebDriverAgentLib/Commands/FBSessionCommands.m b/WebDriverAgentLib/Commands/FBSessionCommands.m index 86535eb7f..c70465073 100644 --- a/WebDriverAgentLib/Commands/FBSessionCommands.m +++ b/WebDriverAgentLib/Commands/FBSessionCommands.m @@ -337,6 +337,7 @@ + (NSArray *)routes FB_SETTING_KEYBOARD_AUTOCORRECTION: @([FBConfiguration keyboardAutocorrection]), FB_SETTING_KEYBOARD_PREDICTION: @([FBConfiguration keyboardPrediction]), FB_SETTING_SNAPSHOT_MAX_DEPTH: @([FBConfiguration snapshotMaxDepth]), + FB_SETTING_SNAPSHOT_MAX_CHILDREN: @([FBConfiguration snapshotMaxChildren]), FB_SETTING_USE_FIRST_MATCH: @([FBConfiguration useFirstMatch]), FB_SETTING_WAIT_FOR_IDLE_TIMEOUT: @([FBConfiguration waitForIdleTimeout]), FB_SETTING_ANIMATION_COOL_OFF_TIMEOUT: @([FBConfiguration animationCoolOffTimeout]), @@ -404,6 +405,9 @@ + (NSArray *)routes if (nil != [settings objectForKey:FB_SETTING_SNAPSHOT_MAX_DEPTH]) { [FBConfiguration setSnapshotMaxDepth:[[settings objectForKey:FB_SETTING_SNAPSHOT_MAX_DEPTH] intValue]]; } + if (nil != [settings objectForKey:FB_SETTING_SNAPSHOT_MAX_CHILDREN]) { + [FBConfiguration setSnapshotMaxChildren:[[settings objectForKey:FB_SETTING_SNAPSHOT_MAX_CHILDREN] intValue]]; + } if (nil != [settings objectForKey:FB_SETTING_USE_FIRST_MATCH]) { [FBConfiguration setUseFirstMatch:[[settings objectForKey:FB_SETTING_USE_FIRST_MATCH] boolValue]]; } diff --git a/WebDriverAgentLib/Utilities/FBConfiguration.h b/WebDriverAgentLib/Utilities/FBConfiguration.h index 20aa0a9d5..35fbf165a 100644 --- a/WebDriverAgentLib/Utilities/FBConfiguration.h +++ b/WebDriverAgentLib/Utilities/FBConfiguration.h @@ -10,6 +10,7 @@ NS_ASSUME_NONNULL_BEGIN +extern NSString *const FBSnapshotMaxChildrenKey; extern NSString *const FBSnapshotMaxDepthKey; /** @@ -206,6 +207,22 @@ typedef NS_ENUM(NSInteger, FBConfigurationKeyboardPreference) { */ + (int)snapshotMaxDepth; +/** + Sets the maximum number of element children to traverse in each snapshot + while requesting XCElementSnapshot. + Used to set the `maxChildren` value in a dictionary provided by + XCAXClient_iOS's `defaultParameters` method. + The original XCAXClient_iOS `maxChildren` value is `INT_MAX`. + + @param maxChildren The number of maximum element children for traversing elements tree + */ ++ (void)setSnapshotMaxChildren:(int)maxChildren; + +/** + @return The maximum number of element children for traversing elements tree + */ ++ (int)snapshotMaxChildren; + /** * Whether to use fast search result matching while searching for elements. * By default this is disabled due to https://github.com/appium/appium/issues/10101 diff --git a/WebDriverAgentLib/Utilities/FBConfiguration.m b/WebDriverAgentLib/Utilities/FBConfiguration.m index 1bae66e85..e6ce8d52f 100644 --- a/WebDriverAgentLib/Utilities/FBConfiguration.m +++ b/WebDriverAgentLib/Utilities/FBConfiguration.m @@ -13,6 +13,7 @@ #import "TIPreferencesController.h" #include +#include #import #include "TargetConditionals.h" @@ -385,6 +386,16 @@ + (int)snapshotMaxDepth return [FBGetCustomParameterForElementSnapshot(FBSnapshotMaxDepthKey) intValue]; } ++ (void)setSnapshotMaxChildren:(int)maxChildren +{ + FBSetCustomParameterForElementSnapshot(FBSnapshotMaxChildrenKey, @(maxChildren)); +} + ++ (int)snapshotMaxChildren +{ + return [FBGetCustomParameterForElementSnapshot(FBSnapshotMaxChildrenKey) intValue]; +} + + (void)setShouldRespectSystemAlerts:(BOOL)value { FBShouldRespectSystemAlerts = value; @@ -541,6 +552,7 @@ + (void)resetSessionSettings FBAnimationCoolOffTimeout = 2.; // 50 should be enough for the majority of the cases. The performance is acceptable for values up to 100. FBSetCustomParameterForElementSnapshot(FBSnapshotMaxDepthKey, @50); + FBSetCustomParameterForElementSnapshot(FBSnapshotMaxChildrenKey, @INT_MAX); FBUseClearTextShortcut = YES; FBLimitXpathContextScope = YES; #if !TARGET_OS_TV diff --git a/WebDriverAgentLib/Utilities/FBSettings.h b/WebDriverAgentLib/Utilities/FBSettings.h index afd37df97..08d8a7963 100644 --- a/WebDriverAgentLib/Utilities/FBSettings.h +++ b/WebDriverAgentLib/Utilities/FBSettings.h @@ -22,6 +22,7 @@ extern NSString* const FB_SETTING_SCREENSHOT_QUALITY; extern NSString* const FB_SETTING_KEYBOARD_AUTOCORRECTION; extern NSString* const FB_SETTING_KEYBOARD_PREDICTION; extern NSString* const FB_SETTING_SNAPSHOT_MAX_DEPTH; +extern NSString* const FB_SETTING_SNAPSHOT_MAX_CHILDREN; extern NSString* const FB_SETTING_USE_FIRST_MATCH; extern NSString* const FB_SETTING_BOUND_ELEMENTS_BY_INDEX; extern NSString* const FB_SETTING_REDUCE_MOTION; diff --git a/WebDriverAgentLib/Utilities/FBSettings.m b/WebDriverAgentLib/Utilities/FBSettings.m index 89f77a69c..65c6ed82f 100644 --- a/WebDriverAgentLib/Utilities/FBSettings.m +++ b/WebDriverAgentLib/Utilities/FBSettings.m @@ -18,6 +18,7 @@ NSString* const FB_SETTING_KEYBOARD_AUTOCORRECTION = @"keyboardAutocorrection"; NSString* const FB_SETTING_KEYBOARD_PREDICTION = @"keyboardPrediction"; NSString* const FB_SETTING_SNAPSHOT_MAX_DEPTH = @"snapshotMaxDepth"; +NSString* const FB_SETTING_SNAPSHOT_MAX_CHILDREN = @"snapshotMaxChildren"; NSString* const FB_SETTING_USE_FIRST_MATCH = @"useFirstMatch"; NSString* const FB_SETTING_BOUND_ELEMENTS_BY_INDEX = @"boundElementsByIndex"; NSString* const FB_SETTING_REDUCE_MOTION = @"reduceMotion"; diff --git a/lib/types.ts b/lib/types.ts index a592b37d4..57524388d 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -12,6 +12,7 @@ export interface WDASettings { keyboardPrediction?: boolean; customSnapshotTimeout?: number; snapshotMaxDepth?: number; + snapshotMaxChildren?: number; useFirstMatch?: boolean; boundElementsByIndex?: boolean; reduceMotion?: boolean;