From 4510b4afba294508b3a086b50bdf48cfe4442f20 Mon Sep 17 00:00:00 2001 From: Ilia Kharebashvili Date: Fri, 30 May 2025 17:27:00 +0300 Subject: [PATCH 1/6] feat: Add useNativeHittable option for including real hittable attribute in XML source --- WebDriverAgentLib/Commands/FBDebugCommands.m | 11 +++++-- .../Utilities/FBXMLGenerationOptions.h | 14 ++++++++ .../Utilities/FBXMLGenerationOptions.m | 7 ++++ WebDriverAgentLib/Utilities/FBXPath-Private.h | 32 ++++++++++--------- WebDriverAgentLib/Utilities/FBXPath.m | 20 ++++++------ 5 files changed, 57 insertions(+), 27 deletions(-) diff --git a/WebDriverAgentLib/Commands/FBDebugCommands.m b/WebDriverAgentLib/Commands/FBDebugCommands.m index c3f9a7816..4fff8ab5e 100644 --- a/WebDriverAgentLib/Commands/FBDebugCommands.m +++ b/WebDriverAgentLib/Commands/FBDebugCommands.m @@ -49,10 +49,15 @@ + (NSArray *)routes NSArray *excludedAttributes = nil == request.parameters[@"excluded_attributes"] ? nil : [request.parameters[@"excluded_attributes"] componentsSeparatedByString:@","]; + + BOOL useNativeHittable = [request.parameters[@"useNativeHittable"] boolValue]; + result = [application fb_xmlRepresentationWithOptions: - [[[FBXMLGenerationOptions new] - withExcludedAttributes:excludedAttributes] - withScope:sourceScope]]; + [[[[FBXMLGenerationOptions new] + withExcludedAttributes:excludedAttributes] + withScope:sourceScope] + withUseNativeHittable:useNativeHittable]]; + } else if ([sourceType caseInsensitiveCompare:SOURCE_FORMAT_JSON] == NSOrderedSame) { NSString *excludedAttributesString = request.parameters[@"excluded_attributes"]; NSSet *excludedAttributes = (excludedAttributesString == nil) diff --git a/WebDriverAgentLib/Utilities/FBXMLGenerationOptions.h b/WebDriverAgentLib/Utilities/FBXMLGenerationOptions.h index 0fd71e139..381bf0bf5 100644 --- a/WebDriverAgentLib/Utilities/FBXMLGenerationOptions.h +++ b/WebDriverAgentLib/Utilities/FBXMLGenerationOptions.h @@ -24,6 +24,12 @@ NS_ASSUME_NONNULL_BEGIN Passing nil means all the available attributes should be included */ @property (nonatomic, nullable) NSArray *excludedAttributes; +/** + Determines whether to calculate `hittable` attribute using native snapshots. + Defaults to NO. When enabled, generates more accurate `hittable` values, + but may affect performance. + */ +@property (nonatomic, assign) BOOL useNativeHittable; /** Allows to provide XML scope. @@ -41,6 +47,14 @@ NS_ASSUME_NONNULL_BEGIN */ - (FBXMLGenerationOptions *)withExcludedAttributes:(nullable NSArray *)excludedAttributes; +/** + Allows to enable accurate `hittable` attribute calculation using native snapshots. + + @param useNativeHittable See the property description above + @return self instance for chaining + */ +- (FBXMLGenerationOptions *)withUseNativeHittable:(BOOL)useNativeHittable; + @end NS_ASSUME_NONNULL_END diff --git a/WebDriverAgentLib/Utilities/FBXMLGenerationOptions.m b/WebDriverAgentLib/Utilities/FBXMLGenerationOptions.m index 23bfa5892..a3429d570 100644 --- a/WebDriverAgentLib/Utilities/FBXMLGenerationOptions.m +++ b/WebDriverAgentLib/Utilities/FBXMLGenerationOptions.m @@ -23,4 +23,11 @@ - (FBXMLGenerationOptions *)withExcludedAttributes:(NSArray *)exclud return self; } + +- (FBXMLGenerationOptions *)withUseNativeHittable:(BOOL)useNativeHittable +{ + self.useNativeHittable = useNativeHittable; + return self; +} + @end diff --git a/WebDriverAgentLib/Utilities/FBXPath-Private.h b/WebDriverAgentLib/Utilities/FBXPath-Private.h index 7346b2c3f..bc4c56520 100644 --- a/WebDriverAgentLib/Utilities/FBXPath-Private.h +++ b/WebDriverAgentLib/Utilities/FBXPath-Private.h @@ -15,21 +15,23 @@ NS_ASSUME_NONNULL_BEGIN /** Gets xmllib2-compatible XML representation of n XCElementSnapshot instance - - @param root the root element to execute XPath query for - @param writer the correspondig libxml2 writer object - @param elementStore an empty dictionary to store indexes mapping or nil if no mappings should be stored - @param query Optional XPath query value. By analyzing this query we may optimize the lookup speed. - @param excludedAttributes The list of XML attribute names to be excluded from the generated XML representation. - Setting nil to this argument means that none of the known attributes must be excluded. - If `query` argument is assigned then `excludedAttributes` argument is effectively ignored. - @return zero if the method has completed successfully - */ -+ (int)xmlRepresentationWithRootElement:(id)root - writer:(xmlTextWriterPtr)writer - elementStore:(nullable NSMutableDictionary *)elementStore - query:(nullable NSString*)query - excludingAttributes:(nullable NSArray *)excludedAttributes; + + @param root The root element to generate XML from. + @param writer The corresponding libxml2 writer object. + @param elementStore An optional mutable dictionary used to store index path to snapshot mappings. Pass nil to skip mapping. + @param query An optional XPath query string. If provided, it will be used to optimize the list of included attributes. + @param options Optional configuration object that allows fine-tuning of the XML generation process. + If `query` is provided, options.excludedAttributes and useNativeHittable will be ignored. + If `query` is nil: + - `options.excludedAttributes` can be used to exclude specific XML attributes from the output. + - `options.useNativeHittable` enables the calculation of true `hittable` values using native snapshots (expensive). + @return Zero if the method completes successfully, or a negative libxml2 error code otherwise. + */ + + (int)xmlRepresentationWithRootElement:(id)root + writer:(xmlTextWriterPtr)writer + elementStore:(nullable NSMutableDictionary *)elementStore + query:(nullable NSString*)query + options:(nullable FBXMLGenerationOptions *)options; /** Gets the list of matched snapshots from xmllib2-compatible xmlNodeSetPtr structure diff --git a/WebDriverAgentLib/Utilities/FBXPath.m b/WebDriverAgentLib/Utilities/FBXPath.m index e11b52d85..3b5a90d3c 100644 --- a/WebDriverAgentLib/Utilities/FBXPath.m +++ b/WebDriverAgentLib/Utilities/FBXPath.m @@ -147,11 +147,11 @@ + (nullable NSString *)xmlStringWithRootElement:(id)root if (rc >= 0) { [self waitUntilStableWithElement:root]; - rc = [self xmlRepresentationWithRootElement:[self snapshotWithRoot:root useNative:NO] + rc = [self xmlRepresentationWithRootElement:[self snapshotWithRoot:root useNative:options.useNativeHittable] writer:writer elementStore:nil query:nil - excludingAttributes:options.excludedAttributes]; + options:options]; } if (rc >= 0 && hasScope) { @@ -227,7 +227,7 @@ + (nullable NSString *)xmlStringWithRootElement:(id)root writer:writer elementStore:elementStore query:xpathQuery - excludingAttributes:nil]; + options:nil]; if (rc >= 0) { rc = xmlTextWriterEndDocument(writer); if (rc < 0) { @@ -347,18 +347,20 @@ + (int)xmlRepresentationWithRootElement:(id)root writer:(xmlTextWriterPtr)writer elementStore:(nullable NSMutableDictionary *)elementStore query:(nullable NSString*)query - excludingAttributes:(nullable NSArray *)excludedAttributes + options:(nullable FBXMLGenerationOptions *)options { // Trying to be smart here and only including attributes, that were asked in the query, to the resulting document. // This may speed up the lookup significantly in some cases NSMutableSet *includedAttributes; if (nil == query) { includedAttributes = [NSMutableSet setWithArray:FBElementAttribute.supportedAttributes]; - // The hittable attribute is expensive to calculate for each snapshot item - // thus we only include it when requested by an xPath query - [includedAttributes removeObject:FBHittableAttribute.class]; - if (nil != excludedAttributes) { - for (NSString *excludedAttributeName in excludedAttributes) { + if (options == nil || !options.useNativeHittable) { + // The hittable attribute is expensive to calculate for each snapshot item + // thus we only include it when requested explicitly + [includedAttributes removeObject:FBHittableAttribute.class]; + } + if (nil != options.excludedAttributes) { + for (NSString *excludedAttributeName in options.excludedAttributes) { for (Class supportedAttribute in FBElementAttribute.supportedAttributes) { if ([[supportedAttribute name] caseInsensitiveCompare:excludedAttributeName] == NSOrderedSame) { [includedAttributes removeObject:supportedAttribute]; From 65e0d762fed27c72f595c9b5cb5f2ec70552393b Mon Sep 17 00:00:00 2001 From: Ilia Kharebashvili Date: Mon, 2 Jun 2025 15:01:52 +0300 Subject: [PATCH 2/6] refactor: add includeHittableInSource to FBSettings --- WebDriverAgentLib/Commands/FBDebugCommands.m | 9 +++------ WebDriverAgentLib/Commands/FBSessionCommands.m | 4 ++++ WebDriverAgentLib/Utilities/FBConfiguration.h | 11 +++++++++++ WebDriverAgentLib/Utilities/FBConfiguration.m | 12 ++++++++++++ WebDriverAgentLib/Utilities/FBSettings.h | 1 + WebDriverAgentLib/Utilities/FBSettings.m | 1 + .../Utilities/FBXMLGenerationOptions.h | 14 -------------- .../Utilities/FBXMLGenerationOptions.m | 7 ------- WebDriverAgentLib/Utilities/FBXPath.m | 6 ++++-- 9 files changed, 36 insertions(+), 29 deletions(-) diff --git a/WebDriverAgentLib/Commands/FBDebugCommands.m b/WebDriverAgentLib/Commands/FBDebugCommands.m index 4fff8ab5e..2fbbe760c 100644 --- a/WebDriverAgentLib/Commands/FBDebugCommands.m +++ b/WebDriverAgentLib/Commands/FBDebugCommands.m @@ -50,13 +50,10 @@ + (NSArray *)routes ? nil : [request.parameters[@"excluded_attributes"] componentsSeparatedByString:@","]; - BOOL useNativeHittable = [request.parameters[@"useNativeHittable"] boolValue]; - result = [application fb_xmlRepresentationWithOptions: - [[[[FBXMLGenerationOptions new] - withExcludedAttributes:excludedAttributes] - withScope:sourceScope] - withUseNativeHittable:useNativeHittable]]; + [[[FBXMLGenerationOptions new] + withExcludedAttributes:excludedAttributes] + withScope:sourceScope]]; } else if ([sourceType caseInsensitiveCompare:SOURCE_FORMAT_JSON] == NSOrderedSame) { NSString *excludedAttributesString = request.parameters[@"excluded_attributes"]; diff --git a/WebDriverAgentLib/Commands/FBSessionCommands.m b/WebDriverAgentLib/Commands/FBSessionCommands.m index 4f10ce95a..37beb206b 100644 --- a/WebDriverAgentLib/Commands/FBSessionCommands.m +++ b/WebDriverAgentLib/Commands/FBSessionCommands.m @@ -353,6 +353,7 @@ + (NSArray *)routes FB_SETTING_MAX_TYPING_FREQUENCY: @([FBConfiguration maxTypingFrequency]), FB_SETTING_RESPECT_SYSTEM_ALERTS: @([FBConfiguration shouldRespectSystemAlerts]), FB_SETTING_USE_CLEAR_TEXT_SHORTCUT: @([FBConfiguration useClearTextShortcut]), + FB_SETTING_INCLUDE_HITTABLE_IN_SOURCE: @([FBConfiguration includeHittableInSource]), FB_SETTING_LIMIT_XPATH_CONTEXT_SCOPE: @([FBConfiguration limitXpathContextScope]), #if !TARGET_OS_TV FB_SETTING_SCREENSHOT_ORIENTATION: [FBConfiguration humanReadableScreenshotOrientation], @@ -455,6 +456,9 @@ + (NSArray *)routes if (nil != [settings objectForKey:FB_SETTING_USE_CLEAR_TEXT_SHORTCUT]) { [FBConfiguration setUseClearTextShortcut:[[settings objectForKey:FB_SETTING_USE_CLEAR_TEXT_SHORTCUT] boolValue]]; } + if (nil != [settings objectForKey:FB_SETTING_INCLUDE_HITTABLE_IN_SOURCE]) { + [FBConfiguration setIncludeHittableInSource:[[settings objectForKey:FB_SETTING_INCLUDE_HITTABLE_IN_SOURCE] boolValue]]; + } if (nil != [settings objectForKey:FB_SETTING_LIMIT_XPATH_CONTEXT_SCOPE]) { [FBConfiguration setLimitXpathContextScope:[[settings objectForKey:FB_SETTING_LIMIT_XPATH_CONTEXT_SCOPE] boolValue]]; } diff --git a/WebDriverAgentLib/Utilities/FBConfiguration.h b/WebDriverAgentLib/Utilities/FBConfiguration.h index c2a3f117c..a9bc552a9 100644 --- a/WebDriverAgentLib/Utilities/FBConfiguration.h +++ b/WebDriverAgentLib/Utilities/FBConfiguration.h @@ -332,6 +332,17 @@ typedef NS_ENUM(NSInteger, FBConfigurationKeyboardPreference) { */ + (void)resetSessionSettings; +/** + * Whether to calculate `hittable` attribute using native APIs + * instead of legacy heuristics. + * This flag improves accuracy, but may affect performance. + * Disabled by default. + * + * @param enabled Either YES or NO + */ ++ (void)setIncludeHittableInSource:(BOOL)enabled; ++ (BOOL)includeHittableInSource; + @end NS_ASSUME_NONNULL_END diff --git a/WebDriverAgentLib/Utilities/FBConfiguration.m b/WebDriverAgentLib/Utilities/FBConfiguration.m index 3dff6442d..7442b9b4c 100644 --- a/WebDriverAgentLib/Utilities/FBConfiguration.m +++ b/WebDriverAgentLib/Utilities/FBConfiguration.m @@ -61,6 +61,7 @@ #if !TARGET_OS_TV static UIInterfaceOrientation FBScreenshotOrientation; #endif +static BOOL FBShouldIncludeHittableInSource = NO; @implementation FBConfiguration @@ -642,4 +643,15 @@ + (BOOL)reduceMotionEnabled return NO; } ++ (void)setIncludeHittableInSource:(BOOL)enabled +{ + FBShouldIncludeHittableInSource = enabled; +} + ++ (BOOL)includeHittableInSource +{ + return FBShouldIncludeHittableInSource; +} + + @end diff --git a/WebDriverAgentLib/Utilities/FBSettings.h b/WebDriverAgentLib/Utilities/FBSettings.h index cc25fe50c..60c870110 100644 --- a/WebDriverAgentLib/Utilities/FBSettings.h +++ b/WebDriverAgentLib/Utilities/FBSettings.h @@ -40,6 +40,7 @@ extern NSString* const FB_SETTING_RESPECT_SYSTEM_ALERTS; extern NSString* const FB_SETTING_USE_CLEAR_TEXT_SHORTCUT; extern NSString* const FB_SETTING_LIMIT_XPATH_CONTEXT_SCOPE; extern NSString* const FB_SETTING_AUTO_CLICK_ALERT_SELECTOR; +extern NSString *const FB_SETTING_INCLUDE_HITTABLE_IN_SOURCE; NS_ASSUME_NONNULL_END diff --git a/WebDriverAgentLib/Utilities/FBSettings.m b/WebDriverAgentLib/Utilities/FBSettings.m index 09badf744..f948f2c0b 100644 --- a/WebDriverAgentLib/Utilities/FBSettings.m +++ b/WebDriverAgentLib/Utilities/FBSettings.m @@ -36,3 +36,4 @@ NSString* const FB_SETTING_USE_CLEAR_TEXT_SHORTCUT = @"useClearTextShortcut"; NSString* const FB_SETTING_LIMIT_XPATH_CONTEXT_SCOPE = @"limitXPathContextScope"; NSString* const FB_SETTING_AUTO_CLICK_ALERT_SELECTOR = @"autoClickAlertSelector"; +NSString* const FB_SETTING_INCLUDE_HITTABLE_IN_SOURCE = @"includeHittableInSource"; diff --git a/WebDriverAgentLib/Utilities/FBXMLGenerationOptions.h b/WebDriverAgentLib/Utilities/FBXMLGenerationOptions.h index 381bf0bf5..0fd71e139 100644 --- a/WebDriverAgentLib/Utilities/FBXMLGenerationOptions.h +++ b/WebDriverAgentLib/Utilities/FBXMLGenerationOptions.h @@ -24,12 +24,6 @@ NS_ASSUME_NONNULL_BEGIN Passing nil means all the available attributes should be included */ @property (nonatomic, nullable) NSArray *excludedAttributes; -/** - Determines whether to calculate `hittable` attribute using native snapshots. - Defaults to NO. When enabled, generates more accurate `hittable` values, - but may affect performance. - */ -@property (nonatomic, assign) BOOL useNativeHittable; /** Allows to provide XML scope. @@ -47,14 +41,6 @@ NS_ASSUME_NONNULL_BEGIN */ - (FBXMLGenerationOptions *)withExcludedAttributes:(nullable NSArray *)excludedAttributes; -/** - Allows to enable accurate `hittable` attribute calculation using native snapshots. - - @param useNativeHittable See the property description above - @return self instance for chaining - */ -- (FBXMLGenerationOptions *)withUseNativeHittable:(BOOL)useNativeHittable; - @end NS_ASSUME_NONNULL_END diff --git a/WebDriverAgentLib/Utilities/FBXMLGenerationOptions.m b/WebDriverAgentLib/Utilities/FBXMLGenerationOptions.m index a3429d570..23bfa5892 100644 --- a/WebDriverAgentLib/Utilities/FBXMLGenerationOptions.m +++ b/WebDriverAgentLib/Utilities/FBXMLGenerationOptions.m @@ -23,11 +23,4 @@ - (FBXMLGenerationOptions *)withExcludedAttributes:(NSArray *)exclud return self; } - -- (FBXMLGenerationOptions *)withUseNativeHittable:(BOOL)useNativeHittable -{ - self.useNativeHittable = useNativeHittable; - return self; -} - @end diff --git a/WebDriverAgentLib/Utilities/FBXPath.m b/WebDriverAgentLib/Utilities/FBXPath.m index 3b5a90d3c..e2e288cbc 100644 --- a/WebDriverAgentLib/Utilities/FBXPath.m +++ b/WebDriverAgentLib/Utilities/FBXPath.m @@ -147,7 +147,9 @@ + (nullable NSString *)xmlStringWithRootElement:(id)root if (rc >= 0) { [self waitUntilStableWithElement:root]; - rc = [self xmlRepresentationWithRootElement:[self snapshotWithRoot:root useNative:options.useNativeHittable] + // If 'includeHittableInSource' setting is enabled, then use native snapshots + // to calculate a more accurate value for the 'hittable' attribute. + rc = [self xmlRepresentationWithRootElement:[self snapshotWithRoot:root useNative:FBConfiguration.includeHittableInSource] writer:writer elementStore:nil query:nil @@ -354,7 +356,7 @@ + (int)xmlRepresentationWithRootElement:(id)root NSMutableSet *includedAttributes; if (nil == query) { includedAttributes = [NSMutableSet setWithArray:FBElementAttribute.supportedAttributes]; - if (options == nil || !options.useNativeHittable) { + if (options == nil || !FBConfiguration.includeHittableInSource) { // The hittable attribute is expensive to calculate for each snapshot item // thus we only include it when requested explicitly [includedAttributes removeObject:FBHittableAttribute.class]; From 2092fe27df63a158129f4da4db92a3a5b3a23a5e Mon Sep 17 00:00:00 2001 From: Ilia Kharebashvili Date: Mon, 2 Jun 2025 23:17:09 +0300 Subject: [PATCH 3/6] Reverted the original version of the xmlRepresentationWithRootElement method, since the hittable attribute setting has been moved to another location --- WebDriverAgentLib/Utilities/FBXPath-Private.h | 30 +++++++++---------- WebDriverAgentLib/Utilities/FBXPath.m | 12 ++++---- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/WebDriverAgentLib/Utilities/FBXPath-Private.h b/WebDriverAgentLib/Utilities/FBXPath-Private.h index bc4c56520..e803b3fa1 100644 --- a/WebDriverAgentLib/Utilities/FBXPath-Private.h +++ b/WebDriverAgentLib/Utilities/FBXPath-Private.h @@ -16,22 +16,20 @@ NS_ASSUME_NONNULL_BEGIN /** Gets xmllib2-compatible XML representation of n XCElementSnapshot instance - @param root The root element to generate XML from. - @param writer The corresponding libxml2 writer object. - @param elementStore An optional mutable dictionary used to store index path to snapshot mappings. Pass nil to skip mapping. - @param query An optional XPath query string. If provided, it will be used to optimize the list of included attributes. - @param options Optional configuration object that allows fine-tuning of the XML generation process. - If `query` is provided, options.excludedAttributes and useNativeHittable will be ignored. - If `query` is nil: - - `options.excludedAttributes` can be used to exclude specific XML attributes from the output. - - `options.useNativeHittable` enables the calculation of true `hittable` values using native snapshots (expensive). - @return Zero if the method completes successfully, or a negative libxml2 error code otherwise. - */ - + (int)xmlRepresentationWithRootElement:(id)root - writer:(xmlTextWriterPtr)writer - elementStore:(nullable NSMutableDictionary *)elementStore - query:(nullable NSString*)query - options:(nullable FBXMLGenerationOptions *)options; + @param root the root element to execute XPath query for + @param writer the correspondig libxml2 writer object + @param elementStore an empty dictionary to store indexes mapping or nil if no mappings should be stored + @param query Optional XPath query value. By analyzing this query we may optimize the lookup speed. + @param excludedAttributes The list of XML attribute names to be excluded from the generated XML representation. + Setting nil to this argument means that none of the known attributes must be excluded. + If `query` argument is assigned then `excludedAttributes` argument is effectively ignored. + @return zero if the method has completed successfully + */ ++ (int)xmlRepresentationWithRootElement:(id)root + writer:(xmlTextWriterPtr)writer + elementStore:(nullable NSMutableDictionary *)elementStore + query:(nullable NSString*)query + excludingAttributes:(nullable NSArray *)excludedAttributes; /** Gets the list of matched snapshots from xmllib2-compatible xmlNodeSetPtr structure diff --git a/WebDriverAgentLib/Utilities/FBXPath.m b/WebDriverAgentLib/Utilities/FBXPath.m index e2e288cbc..c7e3e11b3 100644 --- a/WebDriverAgentLib/Utilities/FBXPath.m +++ b/WebDriverAgentLib/Utilities/FBXPath.m @@ -153,7 +153,7 @@ + (nullable NSString *)xmlStringWithRootElement:(id)root writer:writer elementStore:nil query:nil - options:options]; + excludingAttributes:options.excludedAttributes]; } if (rc >= 0 && hasScope) { @@ -229,7 +229,7 @@ + (nullable NSString *)xmlStringWithRootElement:(id)root writer:writer elementStore:elementStore query:xpathQuery - options:nil]; + excludingAttributes:nil]; if (rc >= 0) { rc = xmlTextWriterEndDocument(writer); if (rc < 0) { @@ -349,20 +349,20 @@ + (int)xmlRepresentationWithRootElement:(id)root writer:(xmlTextWriterPtr)writer elementStore:(nullable NSMutableDictionary *)elementStore query:(nullable NSString*)query - options:(nullable FBXMLGenerationOptions *)options + excludingAttributes:(nullable NSArray *)excludedAttributes { // Trying to be smart here and only including attributes, that were asked in the query, to the resulting document. // This may speed up the lookup significantly in some cases NSMutableSet *includedAttributes; if (nil == query) { includedAttributes = [NSMutableSet setWithArray:FBElementAttribute.supportedAttributes]; - if (options == nil || !FBConfiguration.includeHittableInSource) { + if (!FBConfiguration.includeHittableInSource) { // The hittable attribute is expensive to calculate for each snapshot item // thus we only include it when requested explicitly [includedAttributes removeObject:FBHittableAttribute.class]; } - if (nil != options.excludedAttributes) { - for (NSString *excludedAttributeName in options.excludedAttributes) { + if (nil != excludedAttributes) { + for (NSString *excludedAttributeName in excludedAttributes) { for (Class supportedAttribute in FBElementAttribute.supportedAttributes) { if ([[supportedAttribute name] caseInsensitiveCompare:excludedAttributeName] == NSOrderedSame) { [includedAttributes removeObject:supportedAttribute]; From 3b08c2bc2b90d8eeb7b9c928b3586cb82c200b9f Mon Sep 17 00:00:00 2001 From: Ilia Kharebashvili Date: Mon, 2 Jun 2025 23:33:16 +0300 Subject: [PATCH 4/6] refactor --- WebDriverAgentLib/Commands/FBDebugCommands.m | 8 +++----- WebDriverAgentLib/Utilities/FBConfiguration.m | 1 - WebDriverAgentLib/Utilities/FBXPath-Private.h | 2 +- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/WebDriverAgentLib/Commands/FBDebugCommands.m b/WebDriverAgentLib/Commands/FBDebugCommands.m index 2fbbe760c..c3f9a7816 100644 --- a/WebDriverAgentLib/Commands/FBDebugCommands.m +++ b/WebDriverAgentLib/Commands/FBDebugCommands.m @@ -49,12 +49,10 @@ + (NSArray *)routes NSArray *excludedAttributes = nil == request.parameters[@"excluded_attributes"] ? nil : [request.parameters[@"excluded_attributes"] componentsSeparatedByString:@","]; - result = [application fb_xmlRepresentationWithOptions: - [[[FBXMLGenerationOptions new] - withExcludedAttributes:excludedAttributes] - withScope:sourceScope]]; - + [[[FBXMLGenerationOptions new] + withExcludedAttributes:excludedAttributes] + withScope:sourceScope]]; } else if ([sourceType caseInsensitiveCompare:SOURCE_FORMAT_JSON] == NSOrderedSame) { NSString *excludedAttributesString = request.parameters[@"excluded_attributes"]; NSSet *excludedAttributes = (excludedAttributesString == nil) diff --git a/WebDriverAgentLib/Utilities/FBConfiguration.m b/WebDriverAgentLib/Utilities/FBConfiguration.m index 7442b9b4c..7d42f68bf 100644 --- a/WebDriverAgentLib/Utilities/FBConfiguration.m +++ b/WebDriverAgentLib/Utilities/FBConfiguration.m @@ -653,5 +653,4 @@ + (BOOL)includeHittableInSource return FBShouldIncludeHittableInSource; } - @end diff --git a/WebDriverAgentLib/Utilities/FBXPath-Private.h b/WebDriverAgentLib/Utilities/FBXPath-Private.h index e803b3fa1..7346b2c3f 100644 --- a/WebDriverAgentLib/Utilities/FBXPath-Private.h +++ b/WebDriverAgentLib/Utilities/FBXPath-Private.h @@ -15,7 +15,7 @@ NS_ASSUME_NONNULL_BEGIN /** Gets xmllib2-compatible XML representation of n XCElementSnapshot instance - + @param root the root element to execute XPath query for @param writer the correspondig libxml2 writer object @param elementStore an empty dictionary to store indexes mapping or nil if no mappings should be stored From f1a394978a66ecc19ede45eba1bf63870028c164 Mon Sep 17 00:00:00 2001 From: Ilia Kharebashvili Date: Tue, 3 Jun 2025 11:00:09 +0300 Subject: [PATCH 5/6] refactor: renamed hittable setting --- WebDriverAgentLib/Commands/FBSessionCommands.m | 6 +++--- WebDriverAgentLib/Utilities/FBConfiguration.h | 4 ++-- WebDriverAgentLib/Utilities/FBConfiguration.m | 10 +++++----- WebDriverAgentLib/Utilities/FBSettings.h | 2 +- WebDriverAgentLib/Utilities/FBSettings.m | 2 +- WebDriverAgentLib/Utilities/FBXPath.m | 6 +++--- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/WebDriverAgentLib/Commands/FBSessionCommands.m b/WebDriverAgentLib/Commands/FBSessionCommands.m index 37beb206b..9782c3b08 100644 --- a/WebDriverAgentLib/Commands/FBSessionCommands.m +++ b/WebDriverAgentLib/Commands/FBSessionCommands.m @@ -353,7 +353,7 @@ + (NSArray *)routes FB_SETTING_MAX_TYPING_FREQUENCY: @([FBConfiguration maxTypingFrequency]), FB_SETTING_RESPECT_SYSTEM_ALERTS: @([FBConfiguration shouldRespectSystemAlerts]), FB_SETTING_USE_CLEAR_TEXT_SHORTCUT: @([FBConfiguration useClearTextShortcut]), - FB_SETTING_INCLUDE_HITTABLE_IN_SOURCE: @([FBConfiguration includeHittableInSource]), + FB_SETTING_INCLUDE_HITTABLE_IN_PAGE_SOURCE: @([FBConfiguration includeHittableInPageSource]), FB_SETTING_LIMIT_XPATH_CONTEXT_SCOPE: @([FBConfiguration limitXpathContextScope]), #if !TARGET_OS_TV FB_SETTING_SCREENSHOT_ORIENTATION: [FBConfiguration humanReadableScreenshotOrientation], @@ -456,8 +456,8 @@ + (NSArray *)routes if (nil != [settings objectForKey:FB_SETTING_USE_CLEAR_TEXT_SHORTCUT]) { [FBConfiguration setUseClearTextShortcut:[[settings objectForKey:FB_SETTING_USE_CLEAR_TEXT_SHORTCUT] boolValue]]; } - if (nil != [settings objectForKey:FB_SETTING_INCLUDE_HITTABLE_IN_SOURCE]) { - [FBConfiguration setIncludeHittableInSource:[[settings objectForKey:FB_SETTING_INCLUDE_HITTABLE_IN_SOURCE] boolValue]]; + if (nil != [settings objectForKey:FB_SETTING_INCLUDE_HITTABLE_IN_PAGE_SOURCE]) { + [FBConfiguration setincludeHittableInPageSource:[[settings objectForKey:FB_SETTING_INCLUDE_HITTABLE_IN_PAGE_SOURCE] boolValue]]; } if (nil != [settings objectForKey:FB_SETTING_LIMIT_XPATH_CONTEXT_SCOPE]) { [FBConfiguration setLimitXpathContextScope:[[settings objectForKey:FB_SETTING_LIMIT_XPATH_CONTEXT_SCOPE] boolValue]]; diff --git a/WebDriverAgentLib/Utilities/FBConfiguration.h b/WebDriverAgentLib/Utilities/FBConfiguration.h index a9bc552a9..743d48850 100644 --- a/WebDriverAgentLib/Utilities/FBConfiguration.h +++ b/WebDriverAgentLib/Utilities/FBConfiguration.h @@ -340,8 +340,8 @@ typedef NS_ENUM(NSInteger, FBConfigurationKeyboardPreference) { * * @param enabled Either YES or NO */ -+ (void)setIncludeHittableInSource:(BOOL)enabled; -+ (BOOL)includeHittableInSource; ++ (void)setincludeHittableInPageSource:(BOOL)enabled; ++ (BOOL)includeHittableInPageSource; @end diff --git a/WebDriverAgentLib/Utilities/FBConfiguration.m b/WebDriverAgentLib/Utilities/FBConfiguration.m index 7d42f68bf..a28290237 100644 --- a/WebDriverAgentLib/Utilities/FBConfiguration.m +++ b/WebDriverAgentLib/Utilities/FBConfiguration.m @@ -61,7 +61,7 @@ #if !TARGET_OS_TV static UIInterfaceOrientation FBScreenshotOrientation; #endif -static BOOL FBShouldIncludeHittableInSource = NO; +static BOOL FBShouldincludeHittableInPageSource = NO; @implementation FBConfiguration @@ -643,14 +643,14 @@ + (BOOL)reduceMotionEnabled return NO; } -+ (void)setIncludeHittableInSource:(BOOL)enabled ++ (void)setincludeHittableInPageSource:(BOOL)enabled { - FBShouldIncludeHittableInSource = enabled; + FBShouldincludeHittableInPageSource = enabled; } -+ (BOOL)includeHittableInSource ++ (BOOL)includeHittableInPageSource { - return FBShouldIncludeHittableInSource; + return FBShouldincludeHittableInPageSource; } @end diff --git a/WebDriverAgentLib/Utilities/FBSettings.h b/WebDriverAgentLib/Utilities/FBSettings.h index 60c870110..2b259563b 100644 --- a/WebDriverAgentLib/Utilities/FBSettings.h +++ b/WebDriverAgentLib/Utilities/FBSettings.h @@ -40,7 +40,7 @@ extern NSString* const FB_SETTING_RESPECT_SYSTEM_ALERTS; extern NSString* const FB_SETTING_USE_CLEAR_TEXT_SHORTCUT; extern NSString* const FB_SETTING_LIMIT_XPATH_CONTEXT_SCOPE; extern NSString* const FB_SETTING_AUTO_CLICK_ALERT_SELECTOR; -extern NSString *const FB_SETTING_INCLUDE_HITTABLE_IN_SOURCE; +extern NSString *const FB_SETTING_INCLUDE_HITTABLE_IN_PAGE_SOURCE; NS_ASSUME_NONNULL_END diff --git a/WebDriverAgentLib/Utilities/FBSettings.m b/WebDriverAgentLib/Utilities/FBSettings.m index f948f2c0b..6a019b2d7 100644 --- a/WebDriverAgentLib/Utilities/FBSettings.m +++ b/WebDriverAgentLib/Utilities/FBSettings.m @@ -36,4 +36,4 @@ NSString* const FB_SETTING_USE_CLEAR_TEXT_SHORTCUT = @"useClearTextShortcut"; NSString* const FB_SETTING_LIMIT_XPATH_CONTEXT_SCOPE = @"limitXPathContextScope"; NSString* const FB_SETTING_AUTO_CLICK_ALERT_SELECTOR = @"autoClickAlertSelector"; -NSString* const FB_SETTING_INCLUDE_HITTABLE_IN_SOURCE = @"includeHittableInSource"; +NSString* const FB_SETTING_INCLUDE_HITTABLE_IN_PAGE_SOURCE = @"includeHittableInPageSource"; diff --git a/WebDriverAgentLib/Utilities/FBXPath.m b/WebDriverAgentLib/Utilities/FBXPath.m index c7e3e11b3..87689a7cf 100644 --- a/WebDriverAgentLib/Utilities/FBXPath.m +++ b/WebDriverAgentLib/Utilities/FBXPath.m @@ -147,9 +147,9 @@ + (nullable NSString *)xmlStringWithRootElement:(id)root if (rc >= 0) { [self waitUntilStableWithElement:root]; - // If 'includeHittableInSource' setting is enabled, then use native snapshots + // If 'includeHittableInPageSource' setting is enabled, then use native snapshots // to calculate a more accurate value for the 'hittable' attribute. - rc = [self xmlRepresentationWithRootElement:[self snapshotWithRoot:root useNative:FBConfiguration.includeHittableInSource] + rc = [self xmlRepresentationWithRootElement:[self snapshotWithRoot:root useNative:FBConfiguration.includeHittableInPageSource] writer:writer elementStore:nil query:nil @@ -356,7 +356,7 @@ + (int)xmlRepresentationWithRootElement:(id)root NSMutableSet *includedAttributes; if (nil == query) { includedAttributes = [NSMutableSet setWithArray:FBElementAttribute.supportedAttributes]; - if (!FBConfiguration.includeHittableInSource) { + if (!FBConfiguration.includeHittableInPageSource) { // The hittable attribute is expensive to calculate for each snapshot item // thus we only include it when requested explicitly [includedAttributes removeObject:FBHittableAttribute.class]; From 651b9fd8442afac73d641df1fab8e1bc9d436058 Mon Sep 17 00:00:00 2001 From: Ilia Kharebashvili Date: Tue, 3 Jun 2025 11:03:41 +0300 Subject: [PATCH 6/6] minor refactoring --- WebDriverAgentLib/Utilities/FBXPath.m | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/WebDriverAgentLib/Utilities/FBXPath.m b/WebDriverAgentLib/Utilities/FBXPath.m index 87689a7cf..f851cf8f8 100644 --- a/WebDriverAgentLib/Utilities/FBXPath.m +++ b/WebDriverAgentLib/Utilities/FBXPath.m @@ -149,7 +149,8 @@ + (nullable NSString *)xmlStringWithRootElement:(id)root [self waitUntilStableWithElement:root]; // If 'includeHittableInPageSource' setting is enabled, then use native snapshots // to calculate a more accurate value for the 'hittable' attribute. - rc = [self xmlRepresentationWithRootElement:[self snapshotWithRoot:root useNative:FBConfiguration.includeHittableInPageSource] + rc = [self xmlRepresentationWithRootElement:[self snapshotWithRoot:root + useNative:FBConfiguration.includeHittableInPageSource] writer:writer elementStore:nil query:nil