Skip to content

Commit 57dd6dc

Browse files
authored
feat: make maxChildren configuable (#1117)
* feat: make maxChildren configuable * add docstring * update docstring * simplify * remove a line * add nil check * remove last line * use INT_MAX * add type * remove a line
1 parent f426738 commit 57dd6dc

8 files changed

Lines changed: 38 additions & 0 deletions

File tree

WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
NS_ASSUME_NONNULL_BEGIN
1414

15+
extern NSString *const FBSnapshotMaxChildrenKey;
1516
extern NSString *const FBSnapshotMaxDepthKey;
1617

1718
void FBSetCustomParameterForElementSnapshot (NSString* name, id value);

WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
@"maxDepth" : (int)2147483647
2020
*/
2121
NSString *const FBSnapshotMaxDepthKey = @"maxDepth";
22+
NSString *const FBSnapshotMaxChildrenKey = @"maxChildren";
2223

2324
static id (*original_defaultParameters)(id, SEL);
2425
static id (*original_snapshotParameters)(id, SEL);

WebDriverAgentLib/Commands/FBSessionCommands.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ + (NSArray *)routes
337337
FB_SETTING_KEYBOARD_AUTOCORRECTION: @([FBConfiguration keyboardAutocorrection]),
338338
FB_SETTING_KEYBOARD_PREDICTION: @([FBConfiguration keyboardPrediction]),
339339
FB_SETTING_SNAPSHOT_MAX_DEPTH: @([FBConfiguration snapshotMaxDepth]),
340+
FB_SETTING_SNAPSHOT_MAX_CHILDREN: @([FBConfiguration snapshotMaxChildren]),
340341
FB_SETTING_USE_FIRST_MATCH: @([FBConfiguration useFirstMatch]),
341342
FB_SETTING_WAIT_FOR_IDLE_TIMEOUT: @([FBConfiguration waitForIdleTimeout]),
342343
FB_SETTING_ANIMATION_COOL_OFF_TIMEOUT: @([FBConfiguration animationCoolOffTimeout]),
@@ -404,6 +405,9 @@ + (NSArray *)routes
404405
if (nil != [settings objectForKey:FB_SETTING_SNAPSHOT_MAX_DEPTH]) {
405406
[FBConfiguration setSnapshotMaxDepth:[[settings objectForKey:FB_SETTING_SNAPSHOT_MAX_DEPTH] intValue]];
406407
}
408+
if (nil != [settings objectForKey:FB_SETTING_SNAPSHOT_MAX_CHILDREN]) {
409+
[FBConfiguration setSnapshotMaxChildren:[[settings objectForKey:FB_SETTING_SNAPSHOT_MAX_CHILDREN] intValue]];
410+
}
407411
if (nil != [settings objectForKey:FB_SETTING_USE_FIRST_MATCH]) {
408412
[FBConfiguration setUseFirstMatch:[[settings objectForKey:FB_SETTING_USE_FIRST_MATCH] boolValue]];
409413
}

WebDriverAgentLib/Utilities/FBConfiguration.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
NS_ASSUME_NONNULL_BEGIN
1212

13+
extern NSString *const FBSnapshotMaxChildrenKey;
1314
extern NSString *const FBSnapshotMaxDepthKey;
1415

1516
/**
@@ -206,6 +207,22 @@ typedef NS_ENUM(NSInteger, FBConfigurationKeyboardPreference) {
206207
*/
207208
+ (int)snapshotMaxDepth;
208209

210+
/**
211+
Sets the maximum number of element children to traverse in each snapshot
212+
while requesting XCElementSnapshot.
213+
Used to set the `maxChildren` value in a dictionary provided by
214+
XCAXClient_iOS's `defaultParameters` method.
215+
The original XCAXClient_iOS `maxChildren` value is `INT_MAX`.
216+
217+
@param maxChildren The number of maximum element children for traversing elements tree
218+
*/
219+
+ (void)setSnapshotMaxChildren:(int)maxChildren;
220+
221+
/**
222+
@return The maximum number of element children for traversing elements tree
223+
*/
224+
+ (int)snapshotMaxChildren;
225+
209226
/**
210227
* Whether to use fast search result matching while searching for elements.
211228
* By default this is disabled due to https://github.com/appium/appium/issues/10101

WebDriverAgentLib/Utilities/FBConfiguration.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#import "TIPreferencesController.h"
1414

1515
#include <dlfcn.h>
16+
#include <limits.h>
1617
#import <UIKit/UIKit.h>
1718

1819
#include "TargetConditionals.h"
@@ -385,6 +386,16 @@ + (int)snapshotMaxDepth
385386
return [FBGetCustomParameterForElementSnapshot(FBSnapshotMaxDepthKey) intValue];
386387
}
387388

389+
+ (void)setSnapshotMaxChildren:(int)maxChildren
390+
{
391+
FBSetCustomParameterForElementSnapshot(FBSnapshotMaxChildrenKey, @(maxChildren));
392+
}
393+
394+
+ (int)snapshotMaxChildren
395+
{
396+
return [FBGetCustomParameterForElementSnapshot(FBSnapshotMaxChildrenKey) intValue];
397+
}
398+
388399
+ (void)setShouldRespectSystemAlerts:(BOOL)value
389400
{
390401
FBShouldRespectSystemAlerts = value;
@@ -541,6 +552,7 @@ + (void)resetSessionSettings
541552
FBAnimationCoolOffTimeout = 2.;
542553
// 50 should be enough for the majority of the cases. The performance is acceptable for values up to 100.
543554
FBSetCustomParameterForElementSnapshot(FBSnapshotMaxDepthKey, @50);
555+
FBSetCustomParameterForElementSnapshot(FBSnapshotMaxChildrenKey, @INT_MAX);
544556
FBUseClearTextShortcut = YES;
545557
FBLimitXpathContextScope = YES;
546558
#if !TARGET_OS_TV

WebDriverAgentLib/Utilities/FBSettings.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ extern NSString* const FB_SETTING_SCREENSHOT_QUALITY;
2222
extern NSString* const FB_SETTING_KEYBOARD_AUTOCORRECTION;
2323
extern NSString* const FB_SETTING_KEYBOARD_PREDICTION;
2424
extern NSString* const FB_SETTING_SNAPSHOT_MAX_DEPTH;
25+
extern NSString* const FB_SETTING_SNAPSHOT_MAX_CHILDREN;
2526
extern NSString* const FB_SETTING_USE_FIRST_MATCH;
2627
extern NSString* const FB_SETTING_BOUND_ELEMENTS_BY_INDEX;
2728
extern NSString* const FB_SETTING_REDUCE_MOTION;

WebDriverAgentLib/Utilities/FBSettings.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
NSString* const FB_SETTING_KEYBOARD_AUTOCORRECTION = @"keyboardAutocorrection";
1919
NSString* const FB_SETTING_KEYBOARD_PREDICTION = @"keyboardPrediction";
2020
NSString* const FB_SETTING_SNAPSHOT_MAX_DEPTH = @"snapshotMaxDepth";
21+
NSString* const FB_SETTING_SNAPSHOT_MAX_CHILDREN = @"snapshotMaxChildren";
2122
NSString* const FB_SETTING_USE_FIRST_MATCH = @"useFirstMatch";
2223
NSString* const FB_SETTING_BOUND_ELEMENTS_BY_INDEX = @"boundElementsByIndex";
2324
NSString* const FB_SETTING_REDUCE_MOTION = @"reduceMotion";

lib/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export interface WDASettings {
1212
keyboardPrediction?: boolean;
1313
customSnapshotTimeout?: number;
1414
snapshotMaxDepth?: number;
15+
snapshotMaxChildren?: number;
1516
useFirstMatch?: boolean;
1617
boundElementsByIndex?: boolean;
1718
reduceMotion?: boolean;

0 commit comments

Comments
 (0)