Skip to content

Commit 0fa4e74

Browse files
feat: Add includeHittableInSource setting for including real hittable attribute in XML source (#1026)
1 parent 06d7995 commit 0fa4e74

6 files changed

Lines changed: 37 additions & 4 deletions

File tree

WebDriverAgentLib/Commands/FBSessionCommands.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ + (NSArray *)routes
353353
FB_SETTING_MAX_TYPING_FREQUENCY: @([FBConfiguration maxTypingFrequency]),
354354
FB_SETTING_RESPECT_SYSTEM_ALERTS: @([FBConfiguration shouldRespectSystemAlerts]),
355355
FB_SETTING_USE_CLEAR_TEXT_SHORTCUT: @([FBConfiguration useClearTextShortcut]),
356+
FB_SETTING_INCLUDE_HITTABLE_IN_PAGE_SOURCE: @([FBConfiguration includeHittableInPageSource]),
356357
FB_SETTING_LIMIT_XPATH_CONTEXT_SCOPE: @([FBConfiguration limitXpathContextScope]),
357358
#if !TARGET_OS_TV
358359
FB_SETTING_SCREENSHOT_ORIENTATION: [FBConfiguration humanReadableScreenshotOrientation],
@@ -455,6 +456,9 @@ + (NSArray *)routes
455456
if (nil != [settings objectForKey:FB_SETTING_USE_CLEAR_TEXT_SHORTCUT]) {
456457
[FBConfiguration setUseClearTextShortcut:[[settings objectForKey:FB_SETTING_USE_CLEAR_TEXT_SHORTCUT] boolValue]];
457458
}
459+
if (nil != [settings objectForKey:FB_SETTING_INCLUDE_HITTABLE_IN_PAGE_SOURCE]) {
460+
[FBConfiguration setincludeHittableInPageSource:[[settings objectForKey:FB_SETTING_INCLUDE_HITTABLE_IN_PAGE_SOURCE] boolValue]];
461+
}
458462
if (nil != [settings objectForKey:FB_SETTING_LIMIT_XPATH_CONTEXT_SCOPE]) {
459463
[FBConfiguration setLimitXpathContextScope:[[settings objectForKey:FB_SETTING_LIMIT_XPATH_CONTEXT_SCOPE] boolValue]];
460464
}

WebDriverAgentLib/Utilities/FBConfiguration.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,17 @@ typedef NS_ENUM(NSInteger, FBConfigurationKeyboardPreference) {
332332
*/
333333
+ (void)resetSessionSettings;
334334

335+
/**
336+
* Whether to calculate `hittable` attribute using native APIs
337+
* instead of legacy heuristics.
338+
* This flag improves accuracy, but may affect performance.
339+
* Disabled by default.
340+
*
341+
* @param enabled Either YES or NO
342+
*/
343+
+ (void)setincludeHittableInPageSource:(BOOL)enabled;
344+
+ (BOOL)includeHittableInPageSource;
345+
335346
@end
336347

337348
NS_ASSUME_NONNULL_END

WebDriverAgentLib/Utilities/FBConfiguration.m

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
#if !TARGET_OS_TV
6262
static UIInterfaceOrientation FBScreenshotOrientation;
6363
#endif
64+
static BOOL FBShouldincludeHittableInPageSource = NO;
6465

6566
@implementation FBConfiguration
6667

@@ -642,4 +643,14 @@ + (BOOL)reduceMotionEnabled
642643
return NO;
643644
}
644645

646+
+ (void)setincludeHittableInPageSource:(BOOL)enabled
647+
{
648+
FBShouldincludeHittableInPageSource = enabled;
649+
}
650+
651+
+ (BOOL)includeHittableInPageSource
652+
{
653+
return FBShouldincludeHittableInPageSource;
654+
}
655+
645656
@end

WebDriverAgentLib/Utilities/FBSettings.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ extern NSString* const FB_SETTING_RESPECT_SYSTEM_ALERTS;
4040
extern NSString* const FB_SETTING_USE_CLEAR_TEXT_SHORTCUT;
4141
extern NSString* const FB_SETTING_LIMIT_XPATH_CONTEXT_SCOPE;
4242
extern NSString* const FB_SETTING_AUTO_CLICK_ALERT_SELECTOR;
43+
extern NSString *const FB_SETTING_INCLUDE_HITTABLE_IN_PAGE_SOURCE;
4344

4445

4546
NS_ASSUME_NONNULL_END

WebDriverAgentLib/Utilities/FBSettings.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,4 @@
3636
NSString* const FB_SETTING_USE_CLEAR_TEXT_SHORTCUT = @"useClearTextShortcut";
3737
NSString* const FB_SETTING_LIMIT_XPATH_CONTEXT_SCOPE = @"limitXPathContextScope";
3838
NSString* const FB_SETTING_AUTO_CLICK_ALERT_SELECTOR = @"autoClickAlertSelector";
39+
NSString* const FB_SETTING_INCLUDE_HITTABLE_IN_PAGE_SOURCE = @"includeHittableInPageSource";

WebDriverAgentLib/Utilities/FBXPath.m

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,10 @@ + (nullable NSString *)xmlStringWithRootElement:(id<FBElement>)root
147147

148148
if (rc >= 0) {
149149
[self waitUntilStableWithElement:root];
150-
rc = [self xmlRepresentationWithRootElement:[self snapshotWithRoot:root useNative:NO]
150+
// If 'includeHittableInPageSource' setting is enabled, then use native snapshots
151+
// to calculate a more accurate value for the 'hittable' attribute.
152+
rc = [self xmlRepresentationWithRootElement:[self snapshotWithRoot:root
153+
useNative:FBConfiguration.includeHittableInPageSource]
151154
writer:writer
152155
elementStore:nil
153156
query:nil
@@ -354,9 +357,11 @@ + (int)xmlRepresentationWithRootElement:(id<FBXCElementSnapshot>)root
354357
NSMutableSet<Class> *includedAttributes;
355358
if (nil == query) {
356359
includedAttributes = [NSMutableSet setWithArray:FBElementAttribute.supportedAttributes];
357-
// The hittable attribute is expensive to calculate for each snapshot item
358-
// thus we only include it when requested by an xPath query
359-
[includedAttributes removeObject:FBHittableAttribute.class];
360+
if (!FBConfiguration.includeHittableInPageSource) {
361+
// The hittable attribute is expensive to calculate for each snapshot item
362+
// thus we only include it when requested explicitly
363+
[includedAttributes removeObject:FBHittableAttribute.class];
364+
}
360365
if (nil != excludedAttributes) {
361366
for (NSString *excludedAttributeName in excludedAttributes) {
362367
for (Class supportedAttribute in FBElementAttribute.supportedAttributes) {

0 commit comments

Comments
 (0)