From fdc9790b6267bc88080a9ca36dcecef8a385c685 Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Tue, 24 Jan 2023 19:08:23 +0100 Subject: [PATCH 01/15] fix: Properly update maxDepth while fetching snapshots --- WebDriverAgentLib/Utilities/FBConfiguration.m | 5 +++++ WebDriverAgentLib/Utilities/FBXCAXClientProxy.m | 10 ++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/WebDriverAgentLib/Utilities/FBConfiguration.m b/WebDriverAgentLib/Utilities/FBConfiguration.m index d34d7d53d..dcf35ec01 100644 --- a/WebDriverAgentLib/Utilities/FBConfiguration.m +++ b/WebDriverAgentLib/Utilities/FBConfiguration.m @@ -64,6 +64,11 @@ + (void)initialize @"maxChildren": @INT_MAX, @"traverseFromParentsToChildren": @1 }]; + // Mimicking XCTest framework behavior (this attribute is added by default unless it is an excludingNonModalElements query) + // See https://github.com/appium/WebDriverAgent/pull/523 + if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"13.0")) { + FBSnapshotRequestParameters[@"snapshotKeyHonorModalViews"] = @(NO); + } [FBConfiguration resetSessionSettings]; } diff --git a/WebDriverAgentLib/Utilities/FBXCAXClientProxy.m b/WebDriverAgentLib/Utilities/FBXCAXClientProxy.m index f001ea91d..6ceea1aa2 100644 --- a/WebDriverAgentLib/Utilities/FBXCAXClientProxy.m +++ b/WebDriverAgentLib/Utilities/FBXCAXClientProxy.m @@ -73,13 +73,11 @@ - (BOOL)setAXTimeout:(NSTimeInterval)timeout error:(NSError **)error maxDepth:(nullable NSNumber *)maxDepth error:(NSError **)error { - NSMutableDictionary *parameters = [[NSMutableDictionary alloc] init]; - // Mimicking XCTest framework behavior (this attribute is added by default unless it is an excludingNonModalElements query) - // See https://github.com/appium/WebDriverAgent/pull/523 - if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"13.0")) { - parameters[@"snapshotKeyHonorModalViews"] = @(NO); - } + // Setting parameters argument to nil enforces `requestSnapshotForElement` to + // fetch default values using the swizzled API call above. + NSMutableDictionary *parameters = nil; if (nil != maxDepth) { + parameters = [NSMutableDictionary new]; [parameters addEntriesFromDictionary:self.defaultParameters]; parameters[FBSnapshotMaxDepthKey] = maxDepth; } From 1cf5d2576fe42fdc2886df4d92c10047fc9ff4b4 Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Tue, 24 Jan 2023 20:34:19 +0100 Subject: [PATCH 02/15] refactor --- WebDriverAgent.xcodeproj/project.pbxproj | 12 ++++ .../XCAXClient_iOS+WebDriverAgent.h | 24 +++++++ .../XCAXClient_iOS+WebDriverAgent.m | 64 +++++++++++++++++++ WebDriverAgentLib/Utilities/FBConfiguration.h | 7 -- WebDriverAgentLib/Utilities/FBConfiguration.m | 23 ++----- .../Utilities/FBXCAXClientProxy.m | 29 --------- 6 files changed, 104 insertions(+), 55 deletions(-) create mode 100644 WebDriverAgentLib/Categories/XCAXClient_iOS+WebDriverAgent.h create mode 100644 WebDriverAgentLib/Categories/XCAXClient_iOS+WebDriverAgent.m diff --git a/WebDriverAgent.xcodeproj/project.pbxproj b/WebDriverAgent.xcodeproj/project.pbxproj index ea7ae19e0..c89f38a62 100644 --- a/WebDriverAgent.xcodeproj/project.pbxproj +++ b/WebDriverAgent.xcodeproj/project.pbxproj @@ -359,6 +359,10 @@ 714D88CD2733FB970074A925 /* FBXMLGenerationOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 714D88CA2733FB970074A925 /* FBXMLGenerationOptions.h */; }; 714D88CE2733FB970074A925 /* FBXMLGenerationOptions.m in Sources */ = {isa = PBXBuildFile; fileRef = 714D88CB2733FB970074A925 /* FBXMLGenerationOptions.m */; }; 714D88CF2733FB970074A925 /* FBXMLGenerationOptions.m in Sources */ = {isa = PBXBuildFile; fileRef = 714D88CB2733FB970074A925 /* FBXMLGenerationOptions.m */; }; + 714E14B829805CAE00375DD7 /* XCAXClient_iOS+WebDriverAgent.h in Headers */ = {isa = PBXBuildFile; fileRef = 714E14B629805CAE00375DD7 /* XCAXClient_iOS+WebDriverAgent.h */; }; + 714E14B929805CAE00375DD7 /* XCAXClient_iOS+WebDriverAgent.h in Headers */ = {isa = PBXBuildFile; fileRef = 714E14B629805CAE00375DD7 /* XCAXClient_iOS+WebDriverAgent.h */; }; + 714E14BA29805CAE00375DD7 /* XCAXClient_iOS+WebDriverAgent.m in Sources */ = {isa = PBXBuildFile; fileRef = 714E14B729805CAE00375DD7 /* XCAXClient_iOS+WebDriverAgent.m */; }; + 714E14BB29805CAE00375DD7 /* XCAXClient_iOS+WebDriverAgent.m in Sources */ = {isa = PBXBuildFile; fileRef = 714E14B729805CAE00375DD7 /* XCAXClient_iOS+WebDriverAgent.m */; }; 714EAA0D2673FDFE005C5B47 /* FBCapabilities.h in Headers */ = {isa = PBXBuildFile; fileRef = 714EAA0B2673FDFE005C5B47 /* FBCapabilities.h */; }; 714EAA0E2673FDFE005C5B47 /* FBCapabilities.h in Headers */ = {isa = PBXBuildFile; fileRef = 714EAA0B2673FDFE005C5B47 /* FBCapabilities.h */; }; 714EAA0F2673FDFE005C5B47 /* FBCapabilities.m in Sources */ = {isa = PBXBuildFile; fileRef = 714EAA0C2673FDFE005C5B47 /* FBCapabilities.m */; }; @@ -975,6 +979,8 @@ 714CA3C61DC23186000F12C9 /* FBXPathIntegrationTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FBXPathIntegrationTests.m; sourceTree = ""; }; 714D88CA2733FB970074A925 /* FBXMLGenerationOptions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FBXMLGenerationOptions.h; sourceTree = ""; }; 714D88CB2733FB970074A925 /* FBXMLGenerationOptions.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FBXMLGenerationOptions.m; sourceTree = ""; }; + 714E14B629805CAE00375DD7 /* XCAXClient_iOS+WebDriverAgent.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "XCAXClient_iOS+WebDriverAgent.h"; sourceTree = ""; }; + 714E14B729805CAE00375DD7 /* XCAXClient_iOS+WebDriverAgent.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "XCAXClient_iOS+WebDriverAgent.m"; sourceTree = ""; }; 714EAA0B2673FDFE005C5B47 /* FBCapabilities.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FBCapabilities.h; sourceTree = ""; }; 714EAA0C2673FDFE005C5B47 /* FBCapabilities.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FBCapabilities.m; sourceTree = ""; }; 7150348521A6DAD600A0F4BA /* FBImageUtils.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FBImageUtils.h; sourceTree = ""; }; @@ -1719,6 +1725,8 @@ EE0D1F601EBCDCF7006A3123 /* NSString+FBVisualLength.m */, 716E0BCC1E917E810087A825 /* NSString+FBXMLSafeString.h */, 716E0BCD1E917E810087A825 /* NSString+FBXMLSafeString.m */, + 714E14B629805CAE00375DD7 /* XCAXClient_iOS+WebDriverAgent.h */, + 714E14B729805CAE00375DD7 /* XCAXClient_iOS+WebDriverAgent.m */, AD6C269A1CF2494200F8B5FF /* XCUIApplication+FBHelpers.h */, AD6C269B1CF2494200F8B5FF /* XCUIApplication+FBHelpers.m */, 71C8E54F25399A6B008572C1 /* XCUIApplication+FBQuiescence.h */, @@ -2284,6 +2292,7 @@ 641EE64B2240C5CA00173FCB /* XCTAsyncActivity.h in Headers */, 641EE64C2240C5CA00173FCB /* XCTestMisuseObserver.h in Headers */, 641EE64D2240C5CA00173FCB /* XCTRunnerDaemonSession.h in Headers */, + 714E14B929805CAE00375DD7 /* XCAXClient_iOS+WebDriverAgent.h in Headers */, 64B2650B228CE4FF002A5025 /* FBTVNavigationTracker-Private.h in Headers */, 641EE64E2240C5CA00173FCB /* FBApplication.h in Headers */, 641EE64F2240C5CA00173FCB /* XCTestExpectationWaiter.h in Headers */, @@ -2525,6 +2534,7 @@ 6496A5D9230D6EB30087F8CB /* AXSettings.h in Headers */, EE35AD301E3B77D600A02D78 /* XCKeyboardKeyMap.h in Headers */, EE35AD5D1E3B77D600A02D78 /* XCTNSPredicateExpectationObject-Protocol.h in Headers */, + 714E14B829805CAE00375DD7 /* XCAXClient_iOS+WebDriverAgent.h in Headers */, EE158B5F1CBD47A000A3E3F0 /* WebDriverAgentLib.h in Headers */, EE158AC01CBD456F00A3E3F0 /* FBFindElementCommands.h in Headers */, 71D475C22538F5A8008D9401 /* XCUIApplicationProcess+FBQuiescence.h in Headers */, @@ -3082,6 +3092,7 @@ 641EE70F2240CE4800173FCB /* FBTVNavigationTracker.m in Sources */, 714D88CF2733FB970074A925 /* FBXMLGenerationOptions.m in Sources */, 641EE5DE2240C5CA00173FCB /* XCUIApplication+FBTouchAction.m in Sources */, + 714E14BB29805CAE00375DD7 /* XCAXClient_iOS+WebDriverAgent.m in Sources */, 641EE5DF2240C5CA00173FCB /* FBWebServer.m in Sources */, 641EE5E02240C5CA00173FCB /* FBTCPSocket.m in Sources */, 641EE5E12240C5CA00173FCB /* FBErrorBuilder.m in Sources */, @@ -3260,6 +3271,7 @@ EE6B64FE1D0F86EF00E85F5D /* XCTestPrivateSymbols.m in Sources */, AD76723E1D6B7CC000610457 /* XCUIElement+FBTyping.m in Sources */, EE158AAF1CBD456F00A3E3F0 /* XCUIElement+FBAccessibility.m in Sources */, + 714E14BA29805CAE00375DD7 /* XCAXClient_iOS+WebDriverAgent.m in Sources */, 7150348821A6DAD600A0F4BA /* FBImageUtils.m in Sources */, E444DCAB24913C220060D7EB /* HTTPResponseProxy.m in Sources */, E444DC6D249131890060D7EB /* HTTPErrorResponse.m in Sources */, diff --git a/WebDriverAgentLib/Categories/XCAXClient_iOS+WebDriverAgent.h b/WebDriverAgentLib/Categories/XCAXClient_iOS+WebDriverAgent.h new file mode 100644 index 000000000..a22416139 --- /dev/null +++ b/WebDriverAgentLib/Categories/XCAXClient_iOS+WebDriverAgent.h @@ -0,0 +1,24 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +#import + +#import "XCAXClient_iOS.h" + +NS_ASSUME_NONNULL_BEGIN + +void FBSetCustomParameterForElementSnapshot (NSString* name, id value); + +id __nullable FBGetCustomParameterForElementSnapshot (NSString *name); + +@interface XCAXClient_iOS (WebDriverAgent) + +@end + +NS_ASSUME_NONNULL_END diff --git a/WebDriverAgentLib/Categories/XCAXClient_iOS+WebDriverAgent.m b/WebDriverAgentLib/Categories/XCAXClient_iOS+WebDriverAgent.m new file mode 100644 index 000000000..1f1bd20f5 --- /dev/null +++ b/WebDriverAgentLib/Categories/XCAXClient_iOS+WebDriverAgent.m @@ -0,0 +1,64 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +#import "XCAXClient_iOS+WebDriverAgent.h" + +#import + +#import "FBReflectionUtils.h" + +static id (*original_defaultParameters)(id, SEL); +static NSMutableDictionary *customRequestParameters; + +void FBSetCustomParameterForElementSnapshot (NSString *name, id value) +{ + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + customRequestParameters = [NSMutableDictionary new]; + }); + customRequestParameters[name] = value; +} + +id FBGetCustomParameterForElementSnapshot (NSString *name) +{ + return customRequestParameters[name]; +} + +static id swizzleDefaultParameters(id self, SEL _cmd) +{ + if (nil == customRequestParameters || 0 == customRequestParameters.count) { + return original_defaultParameters(self, _cmd); + } + + NSMutableDictionary *result = [NSMutableDictionary new]; + [result addEntriesFromDictionary:original_defaultParameters(self, _cmd)]; + [result addEntriesFromDictionary:customRequestParameters]; + return [result copy]; +} + +@implementation XCAXClient_iOS (WebDriverAgent) + +- (NSDictionary *)fb_initialParametersForElementSnapshot +{ + return original_defaultParameters(self, _cmd); +} + +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wobjc-load-method" + ++ (void)load +{ + Method original_defaultParametersMethod = class_getInstanceMethod(self.class, @selector(defaultParameters)); + IMP swizzledImp = (IMP)swizzleDefaultParameters; + original_defaultParameters = (id (*)(id, SEL)) method_setImplementation(original_defaultParametersMethod, swizzledImp); +} + +#pragma clang diagnostic pop + +@end diff --git a/WebDriverAgentLib/Utilities/FBConfiguration.h b/WebDriverAgentLib/Utilities/FBConfiguration.h index 72c01d9c2..7bfbccc43 100644 --- a/WebDriverAgentLib/Utilities/FBConfiguration.h +++ b/WebDriverAgentLib/Utilities/FBConfiguration.h @@ -183,13 +183,6 @@ typedef NS_ENUM(NSInteger, FBConfigurationKeyboardPreference) { */ + (int)snapshotMaxDepth; -/** - Returns parameters for traversing elements tree from parents to children while requesting XCElementSnapshot. - - @return dictionary with parameters for element's snapshot request -*/ -+ (NSDictionary *)snapshotRequestParameters; - /** * 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 dcf35ec01..04c75b1e6 100644 --- a/WebDriverAgentLib/Utilities/FBConfiguration.m +++ b/WebDriverAgentLib/Utilities/FBConfiguration.m @@ -14,6 +14,7 @@ #include "TargetConditionals.h" #import "FBXCodeCompatibility.h" +#import "XCAXClient_iOS+WebDriverAgent.h" #import "XCTestPrivateSymbols.h" #import "XCTestConfiguration.h" #import "XCUIApplication+FBUIInterruptions.h" @@ -53,22 +54,11 @@ #if !TARGET_OS_TV static UIInterfaceOrientation FBScreenshotOrientation; #endif -static NSMutableDictionary *FBSnapshotRequestParameters; @implementation FBConfiguration + (void)initialize { - FBSnapshotRequestParameters = [NSMutableDictionary dictionaryWithDictionary:@{ - @"maxArrayCount": @INT_MAX, - @"maxChildren": @INT_MAX, - @"traverseFromParentsToChildren": @1 - }]; - // Mimicking XCTest framework behavior (this attribute is added by default unless it is an excludingNonModalElements query) - // See https://github.com/appium/WebDriverAgent/pull/523 - if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"13.0")) { - FBSnapshotRequestParameters[@"snapshotKeyHonorModalViews"] = @(NO); - } [FBConfiguration resetSessionSettings]; } @@ -346,17 +336,12 @@ + (NSTimeInterval)customSnapshotTimeout + (void)setSnapshotMaxDepth:(int)maxDepth { - FBSnapshotRequestParameters[FBSnapshotMaxDepthKey] = @(maxDepth); + FBSetCustomParameterForElementSnapshot(FBSnapshotMaxDepthKey, @(maxDepth)); } + (int)snapshotMaxDepth { - return [FBSnapshotRequestParameters[FBSnapshotMaxDepthKey] intValue]; -} - -+ (NSDictionary *)snapshotRequestParameters -{ - return FBSnapshotRequestParameters; + return [FBGetCustomParameterForElementSnapshot(FBSnapshotMaxDepthKey) intValue]; } + (void)setUseFirstMatch:(BOOL)enabled @@ -473,7 +458,7 @@ + (void)resetSessionSettings FBWaitForIdleTimeout = 10.; FBAnimationCoolOffTimeout = 2.; // 50 should be enough for the majority of the cases. The performance is acceptable for values up to 100. - FBSnapshotRequestParameters[FBSnapshotMaxDepthKey] = @50; + FBSetCustomParameterForElementSnapshot(FBSnapshotMaxDepthKey, @50); #if !TARGET_OS_TV FBScreenshotOrientation = UIInterfaceOrientationUnknown; #endif diff --git a/WebDriverAgentLib/Utilities/FBXCAXClientProxy.m b/WebDriverAgentLib/Utilities/FBXCAXClientProxy.m index 6ceea1aa2..5417c70bb 100644 --- a/WebDriverAgentLib/Utilities/FBXCAXClientProxy.m +++ b/WebDriverAgentLib/Utilities/FBXCAXClientProxy.m @@ -21,35 +21,6 @@ static id FBAXClient = nil; -@implementation XCAXClient_iOS (WebDriverAgent) - -/** - Parameters for traversing elements tree from parents to children while requesting XCElementSnapshot. - - @return dictionary with parameters for element's snapshot request - */ -- (NSDictionary *)fb_getParametersForElementSnapshot -{ - return FBConfiguration.snapshotRequestParameters; -} - -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wobjc-load-method" - -+ (void)load -{ - static dispatch_once_t onceToken; - dispatch_once(&onceToken, ^{ - SEL originalParametersSelector = @selector(defaultParameters); - SEL swizzledParametersSelector = @selector(fb_getParametersForElementSnapshot); - FBReplaceMethod([self class], originalParametersSelector, swizzledParametersSelector); - }); -} - -#pragma clang diagnostic pop - -@end - @implementation FBXCAXClientProxy + (instancetype)sharedClient From 7f4b617306aa23c0188d11068f7ae9a5bbf98c41 Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Tue, 24 Jan 2023 20:35:55 +0100 Subject: [PATCH 03/15] Tune the comment --- WebDriverAgentLib/Utilities/FBXCAXClientProxy.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WebDriverAgentLib/Utilities/FBXCAXClientProxy.m b/WebDriverAgentLib/Utilities/FBXCAXClientProxy.m index 5417c70bb..3d1729bb8 100644 --- a/WebDriverAgentLib/Utilities/FBXCAXClientProxy.m +++ b/WebDriverAgentLib/Utilities/FBXCAXClientProxy.m @@ -45,7 +45,7 @@ - (BOOL)setAXTimeout:(NSTimeInterval)timeout error:(NSError **)error error:(NSError **)error { // Setting parameters argument to nil enforces `requestSnapshotForElement` to - // fetch default values using the swizzled API call above. + // fetch default values using the swizzled API call. NSMutableDictionary *parameters = nil; if (nil != maxDepth) { parameters = [NSMutableDictionary new]; From c5ab8a446c3d52d4527af5edd645c9d4d41246c1 Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Tue, 24 Jan 2023 20:36:41 +0100 Subject: [PATCH 04/15] comment --- WebDriverAgentLib/Utilities/FBXCAXClientProxy.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WebDriverAgentLib/Utilities/FBXCAXClientProxy.m b/WebDriverAgentLib/Utilities/FBXCAXClientProxy.m index 3d1729bb8..219bb36e2 100644 --- a/WebDriverAgentLib/Utilities/FBXCAXClientProxy.m +++ b/WebDriverAgentLib/Utilities/FBXCAXClientProxy.m @@ -45,7 +45,7 @@ - (BOOL)setAXTimeout:(NSTimeInterval)timeout error:(NSError **)error error:(NSError **)error { // Setting parameters argument to nil enforces `requestSnapshotForElement` to - // fetch default values using the swizzled API call. + // fetch default values using the swizzled [XCAXClient_iOS defaultParameters] API call. NSMutableDictionary *parameters = nil; if (nil != maxDepth) { parameters = [NSMutableDictionary new]; From 06fbb63af7242fd543e5f1e4238ae5470c7c1287 Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Tue, 24 Jan 2023 20:39:20 +0100 Subject: [PATCH 05/15] Delete extra method --- WebDriverAgentLib/Categories/XCAXClient_iOS+WebDriverAgent.m | 5 ----- 1 file changed, 5 deletions(-) diff --git a/WebDriverAgentLib/Categories/XCAXClient_iOS+WebDriverAgent.m b/WebDriverAgentLib/Categories/XCAXClient_iOS+WebDriverAgent.m index 1f1bd20f5..31561c142 100644 --- a/WebDriverAgentLib/Categories/XCAXClient_iOS+WebDriverAgent.m +++ b/WebDriverAgentLib/Categories/XCAXClient_iOS+WebDriverAgent.m @@ -44,11 +44,6 @@ static id swizzleDefaultParameters(id self, SEL _cmd) @implementation XCAXClient_iOS (WebDriverAgent) -- (NSDictionary *)fb_initialParametersForElementSnapshot -{ - return original_defaultParameters(self, _cmd); -} - #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wobjc-load-method" From 176ac41ed3e74f7c4264f2150470d7cc77c38893 Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Tue, 24 Jan 2023 20:42:43 +0100 Subject: [PATCH 06/15] Rename modules --- WebDriverAgent.xcodeproj/project.pbxproj | 24 +++++++++---------- ...h => XCAXClient_iOS+FBSnapshotReqParams.h} | 0 ...m => XCAXClient_iOS+FBSnapshotReqParams.m} | 2 +- WebDriverAgentLib/Utilities/FBConfiguration.m | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) rename WebDriverAgentLib/Categories/{XCAXClient_iOS+WebDriverAgent.h => XCAXClient_iOS+FBSnapshotReqParams.h} (100%) rename WebDriverAgentLib/Categories/{XCAXClient_iOS+WebDriverAgent.m => XCAXClient_iOS+FBSnapshotReqParams.m} (97%) diff --git a/WebDriverAgent.xcodeproj/project.pbxproj b/WebDriverAgent.xcodeproj/project.pbxproj index c89f38a62..125c26ef0 100644 --- a/WebDriverAgent.xcodeproj/project.pbxproj +++ b/WebDriverAgent.xcodeproj/project.pbxproj @@ -359,10 +359,10 @@ 714D88CD2733FB970074A925 /* FBXMLGenerationOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 714D88CA2733FB970074A925 /* FBXMLGenerationOptions.h */; }; 714D88CE2733FB970074A925 /* FBXMLGenerationOptions.m in Sources */ = {isa = PBXBuildFile; fileRef = 714D88CB2733FB970074A925 /* FBXMLGenerationOptions.m */; }; 714D88CF2733FB970074A925 /* FBXMLGenerationOptions.m in Sources */ = {isa = PBXBuildFile; fileRef = 714D88CB2733FB970074A925 /* FBXMLGenerationOptions.m */; }; - 714E14B829805CAE00375DD7 /* XCAXClient_iOS+WebDriverAgent.h in Headers */ = {isa = PBXBuildFile; fileRef = 714E14B629805CAE00375DD7 /* XCAXClient_iOS+WebDriverAgent.h */; }; - 714E14B929805CAE00375DD7 /* XCAXClient_iOS+WebDriverAgent.h in Headers */ = {isa = PBXBuildFile; fileRef = 714E14B629805CAE00375DD7 /* XCAXClient_iOS+WebDriverAgent.h */; }; - 714E14BA29805CAE00375DD7 /* XCAXClient_iOS+WebDriverAgent.m in Sources */ = {isa = PBXBuildFile; fileRef = 714E14B729805CAE00375DD7 /* XCAXClient_iOS+WebDriverAgent.m */; }; - 714E14BB29805CAE00375DD7 /* XCAXClient_iOS+WebDriverAgent.m in Sources */ = {isa = PBXBuildFile; fileRef = 714E14B729805CAE00375DD7 /* XCAXClient_iOS+WebDriverAgent.m */; }; + 714E14B829805CAE00375DD7 /* XCAXClient_iOS+FBSnapshotReqParams.h in Headers */ = {isa = PBXBuildFile; fileRef = 714E14B629805CAE00375DD7 /* XCAXClient_iOS+FBSnapshotReqParams.h */; }; + 714E14B929805CAE00375DD7 /* XCAXClient_iOS+FBSnapshotReqParams.h in Headers */ = {isa = PBXBuildFile; fileRef = 714E14B629805CAE00375DD7 /* XCAXClient_iOS+FBSnapshotReqParams.h */; }; + 714E14BA29805CAE00375DD7 /* XCAXClient_iOS+FBSnapshotReqParams.m in Sources */ = {isa = PBXBuildFile; fileRef = 714E14B729805CAE00375DD7 /* XCAXClient_iOS+FBSnapshotReqParams.m */; }; + 714E14BB29805CAE00375DD7 /* XCAXClient_iOS+FBSnapshotReqParams.m in Sources */ = {isa = PBXBuildFile; fileRef = 714E14B729805CAE00375DD7 /* XCAXClient_iOS+FBSnapshotReqParams.m */; }; 714EAA0D2673FDFE005C5B47 /* FBCapabilities.h in Headers */ = {isa = PBXBuildFile; fileRef = 714EAA0B2673FDFE005C5B47 /* FBCapabilities.h */; }; 714EAA0E2673FDFE005C5B47 /* FBCapabilities.h in Headers */ = {isa = PBXBuildFile; fileRef = 714EAA0B2673FDFE005C5B47 /* FBCapabilities.h */; }; 714EAA0F2673FDFE005C5B47 /* FBCapabilities.m in Sources */ = {isa = PBXBuildFile; fileRef = 714EAA0C2673FDFE005C5B47 /* FBCapabilities.m */; }; @@ -979,8 +979,8 @@ 714CA3C61DC23186000F12C9 /* FBXPathIntegrationTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FBXPathIntegrationTests.m; sourceTree = ""; }; 714D88CA2733FB970074A925 /* FBXMLGenerationOptions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FBXMLGenerationOptions.h; sourceTree = ""; }; 714D88CB2733FB970074A925 /* FBXMLGenerationOptions.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FBXMLGenerationOptions.m; sourceTree = ""; }; - 714E14B629805CAE00375DD7 /* XCAXClient_iOS+WebDriverAgent.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "XCAXClient_iOS+WebDriverAgent.h"; sourceTree = ""; }; - 714E14B729805CAE00375DD7 /* XCAXClient_iOS+WebDriverAgent.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "XCAXClient_iOS+WebDriverAgent.m"; sourceTree = ""; }; + 714E14B629805CAE00375DD7 /* XCAXClient_iOS+FBSnapshotReqParams.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "XCAXClient_iOS+FBSnapshotReqParams.h"; sourceTree = ""; }; + 714E14B729805CAE00375DD7 /* XCAXClient_iOS+FBSnapshotReqParams.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "XCAXClient_iOS+FBSnapshotReqParams.m"; sourceTree = ""; }; 714EAA0B2673FDFE005C5B47 /* FBCapabilities.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FBCapabilities.h; sourceTree = ""; }; 714EAA0C2673FDFE005C5B47 /* FBCapabilities.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FBCapabilities.m; sourceTree = ""; }; 7150348521A6DAD600A0F4BA /* FBImageUtils.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FBImageUtils.h; sourceTree = ""; }; @@ -1725,8 +1725,8 @@ EE0D1F601EBCDCF7006A3123 /* NSString+FBVisualLength.m */, 716E0BCC1E917E810087A825 /* NSString+FBXMLSafeString.h */, 716E0BCD1E917E810087A825 /* NSString+FBXMLSafeString.m */, - 714E14B629805CAE00375DD7 /* XCAXClient_iOS+WebDriverAgent.h */, - 714E14B729805CAE00375DD7 /* XCAXClient_iOS+WebDriverAgent.m */, + 714E14B629805CAE00375DD7 /* XCAXClient_iOS+FBSnapshotReqParams.h */, + 714E14B729805CAE00375DD7 /* XCAXClient_iOS+FBSnapshotReqParams.m */, AD6C269A1CF2494200F8B5FF /* XCUIApplication+FBHelpers.h */, AD6C269B1CF2494200F8B5FF /* XCUIApplication+FBHelpers.m */, 71C8E54F25399A6B008572C1 /* XCUIApplication+FBQuiescence.h */, @@ -2292,7 +2292,7 @@ 641EE64B2240C5CA00173FCB /* XCTAsyncActivity.h in Headers */, 641EE64C2240C5CA00173FCB /* XCTestMisuseObserver.h in Headers */, 641EE64D2240C5CA00173FCB /* XCTRunnerDaemonSession.h in Headers */, - 714E14B929805CAE00375DD7 /* XCAXClient_iOS+WebDriverAgent.h in Headers */, + 714E14B929805CAE00375DD7 /* XCAXClient_iOS+FBSnapshotReqParams.h in Headers */, 64B2650B228CE4FF002A5025 /* FBTVNavigationTracker-Private.h in Headers */, 641EE64E2240C5CA00173FCB /* FBApplication.h in Headers */, 641EE64F2240C5CA00173FCB /* XCTestExpectationWaiter.h in Headers */, @@ -2534,7 +2534,7 @@ 6496A5D9230D6EB30087F8CB /* AXSettings.h in Headers */, EE35AD301E3B77D600A02D78 /* XCKeyboardKeyMap.h in Headers */, EE35AD5D1E3B77D600A02D78 /* XCTNSPredicateExpectationObject-Protocol.h in Headers */, - 714E14B829805CAE00375DD7 /* XCAXClient_iOS+WebDriverAgent.h in Headers */, + 714E14B829805CAE00375DD7 /* XCAXClient_iOS+FBSnapshotReqParams.h in Headers */, EE158B5F1CBD47A000A3E3F0 /* WebDriverAgentLib.h in Headers */, EE158AC01CBD456F00A3E3F0 /* FBFindElementCommands.h in Headers */, 71D475C22538F5A8008D9401 /* XCUIApplicationProcess+FBQuiescence.h in Headers */, @@ -3092,7 +3092,7 @@ 641EE70F2240CE4800173FCB /* FBTVNavigationTracker.m in Sources */, 714D88CF2733FB970074A925 /* FBXMLGenerationOptions.m in Sources */, 641EE5DE2240C5CA00173FCB /* XCUIApplication+FBTouchAction.m in Sources */, - 714E14BB29805CAE00375DD7 /* XCAXClient_iOS+WebDriverAgent.m in Sources */, + 714E14BB29805CAE00375DD7 /* XCAXClient_iOS+FBSnapshotReqParams.m in Sources */, 641EE5DF2240C5CA00173FCB /* FBWebServer.m in Sources */, 641EE5E02240C5CA00173FCB /* FBTCPSocket.m in Sources */, 641EE5E12240C5CA00173FCB /* FBErrorBuilder.m in Sources */, @@ -3271,7 +3271,7 @@ EE6B64FE1D0F86EF00E85F5D /* XCTestPrivateSymbols.m in Sources */, AD76723E1D6B7CC000610457 /* XCUIElement+FBTyping.m in Sources */, EE158AAF1CBD456F00A3E3F0 /* XCUIElement+FBAccessibility.m in Sources */, - 714E14BA29805CAE00375DD7 /* XCAXClient_iOS+WebDriverAgent.m in Sources */, + 714E14BA29805CAE00375DD7 /* XCAXClient_iOS+FBSnapshotReqParams.m in Sources */, 7150348821A6DAD600A0F4BA /* FBImageUtils.m in Sources */, E444DCAB24913C220060D7EB /* HTTPResponseProxy.m in Sources */, E444DC6D249131890060D7EB /* HTTPErrorResponse.m in Sources */, diff --git a/WebDriverAgentLib/Categories/XCAXClient_iOS+WebDriverAgent.h b/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.h similarity index 100% rename from WebDriverAgentLib/Categories/XCAXClient_iOS+WebDriverAgent.h rename to WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.h diff --git a/WebDriverAgentLib/Categories/XCAXClient_iOS+WebDriverAgent.m b/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.m similarity index 97% rename from WebDriverAgentLib/Categories/XCAXClient_iOS+WebDriverAgent.m rename to WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.m index 31561c142..33ada5872 100644 --- a/WebDriverAgentLib/Categories/XCAXClient_iOS+WebDriverAgent.m +++ b/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.m @@ -7,7 +7,7 @@ * of patent rights can be found in the PATENTS file in the same directory. */ -#import "XCAXClient_iOS+WebDriverAgent.h" +#import "XCAXClient_iOS+FBSnapshotReqParams.h" #import diff --git a/WebDriverAgentLib/Utilities/FBConfiguration.m b/WebDriverAgentLib/Utilities/FBConfiguration.m index 04c75b1e6..cc1cb1c17 100644 --- a/WebDriverAgentLib/Utilities/FBConfiguration.m +++ b/WebDriverAgentLib/Utilities/FBConfiguration.m @@ -14,7 +14,7 @@ #include "TargetConditionals.h" #import "FBXCodeCompatibility.h" -#import "XCAXClient_iOS+WebDriverAgent.h" +#import "XCAXClient_iOS+FBSnapshotReqParams.h" #import "XCTestPrivateSymbols.h" #import "XCTestConfiguration.h" #import "XCUIApplication+FBUIInterruptions.h" From d45c95c834ea529117ce2fb747e059f6ebd848cf Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Tue, 24 Jan 2023 20:43:35 +0100 Subject: [PATCH 07/15] Rename imp --- .../Categories/XCAXClient_iOS+FBSnapshotReqParams.h | 2 +- .../Categories/XCAXClient_iOS+FBSnapshotReqParams.m | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.h b/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.h index a22416139..13c0c0805 100644 --- a/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.h +++ b/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.h @@ -17,7 +17,7 @@ void FBSetCustomParameterForElementSnapshot (NSString* name, id value); id __nullable FBGetCustomParameterForElementSnapshot (NSString *name); -@interface XCAXClient_iOS (WebDriverAgent) +@interface XCAXClient_iOS (FBSnapshotReqParams) @end diff --git a/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.m b/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.m index 33ada5872..3a1141f28 100644 --- a/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.m +++ b/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.m @@ -42,7 +42,7 @@ static id swizzleDefaultParameters(id self, SEL _cmd) return [result copy]; } -@implementation XCAXClient_iOS (WebDriverAgent) +@implementation XCAXClient_iOS (FBSnapshotReqParams) #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wobjc-load-method" From 1aa6c35f4407fe19218c24cc7434dd4275f146e3 Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Tue, 24 Jan 2023 20:51:20 +0100 Subject: [PATCH 08/15] Add imports --- WebDriverAgentLib/Utilities/FBXCAXClientProxy.m | 1 + 1 file changed, 1 insertion(+) diff --git a/WebDriverAgentLib/Utilities/FBXCAXClientProxy.m b/WebDriverAgentLib/Utilities/FBXCAXClientProxy.m index 219bb36e2..b6e7a024b 100644 --- a/WebDriverAgentLib/Utilities/FBXCAXClientProxy.m +++ b/WebDriverAgentLib/Utilities/FBXCAXClientProxy.m @@ -17,6 +17,7 @@ #import "FBMacros.h" #import "FBReflectionUtils.h" #import "XCAXClient_iOS.h" +#import "XCAXClient_iOS+FBSnapshotReqParams.h" #import "XCUIDevice.h" static id FBAXClient = nil; From 9d627d1eec8469bfe43594b06d7ff3847fbaf94c Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Tue, 24 Jan 2023 20:52:16 +0100 Subject: [PATCH 09/15] Moar imports --- WebDriverAgentLib/Utilities/FBXCAXClientProxy.m | 4 ---- 1 file changed, 4 deletions(-) diff --git a/WebDriverAgentLib/Utilities/FBXCAXClientProxy.m b/WebDriverAgentLib/Utilities/FBXCAXClientProxy.m index b6e7a024b..e12b2d7e5 100644 --- a/WebDriverAgentLib/Utilities/FBXCAXClientProxy.m +++ b/WebDriverAgentLib/Utilities/FBXCAXClientProxy.m @@ -9,14 +9,10 @@ #import "FBXCAXClientProxy.h" -#import - #import "FBXCAccessibilityElement.h" #import "FBConfiguration.h" #import "FBLogger.h" #import "FBMacros.h" -#import "FBReflectionUtils.h" -#import "XCAXClient_iOS.h" #import "XCAXClient_iOS+FBSnapshotReqParams.h" #import "XCUIDevice.h" From 00475495163e5b9f89c529ff1721de44e2ae3499 Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Tue, 24 Jan 2023 20:55:12 +0100 Subject: [PATCH 10/15] Move the constant --- .../Categories/XCAXClient_iOS+FBSnapshotReqParams.h | 2 ++ .../Categories/XCAXClient_iOS+FBSnapshotReqParams.m | 2 ++ WebDriverAgentLib/Utilities/FBConfiguration.m | 1 - WebDriverAgentLib/Utilities/FBXCAXClientProxy.m | 1 - 4 files changed, 4 insertions(+), 2 deletions(-) diff --git a/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.h b/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.h index 13c0c0805..8080f2097 100644 --- a/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.h +++ b/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.h @@ -13,6 +13,8 @@ NS_ASSUME_NONNULL_BEGIN +extern NSString *const FBSnapshotMaxDepthKey; + void FBSetCustomParameterForElementSnapshot (NSString* name, id value); id __nullable FBGetCustomParameterForElementSnapshot (NSString *name); diff --git a/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.m b/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.m index 3a1141f28..4027386c7 100644 --- a/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.m +++ b/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.m @@ -13,6 +13,8 @@ #import "FBReflectionUtils.h" +NSString *const FBSnapshotMaxDepthKey = @"maxDepth"; + static id (*original_defaultParameters)(id, SEL); static NSMutableDictionary *customRequestParameters; diff --git a/WebDriverAgentLib/Utilities/FBConfiguration.m b/WebDriverAgentLib/Utilities/FBConfiguration.m index cc1cb1c17..59cd5eb9b 100644 --- a/WebDriverAgentLib/Utilities/FBConfiguration.m +++ b/WebDriverAgentLib/Utilities/FBConfiguration.m @@ -31,7 +31,6 @@ static BOOL FBShouldUseTestManagerForVisibilityDetection = NO; static BOOL FBShouldUseSingletonTestManager = YES; -NSString *const FBSnapshotMaxDepthKey = @"maxDepth"; static NSUInteger FBMjpegScalingFactor = 100; static NSUInteger FBMjpegServerScreenshotQuality = 25; diff --git a/WebDriverAgentLib/Utilities/FBXCAXClientProxy.m b/WebDriverAgentLib/Utilities/FBXCAXClientProxy.m index e12b2d7e5..8781a7c5e 100644 --- a/WebDriverAgentLib/Utilities/FBXCAXClientProxy.m +++ b/WebDriverAgentLib/Utilities/FBXCAXClientProxy.m @@ -10,7 +10,6 @@ #import "FBXCAXClientProxy.h" #import "FBXCAccessibilityElement.h" -#import "FBConfiguration.h" #import "FBLogger.h" #import "FBMacros.h" #import "XCAXClient_iOS+FBSnapshotReqParams.h" From 423d988d0ff05aedf6ef8f29eedaacdc28300186 Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Wed, 25 Jan 2023 18:18:06 +0100 Subject: [PATCH 11/15] Add missing key --- .../Categories/XCAXClient_iOS+FBSnapshotReqParams.h | 1 + .../Categories/XCAXClient_iOS+FBSnapshotReqParams.m | 1 + WebDriverAgentLib/Utilities/FBXCAXClientProxy.m | 9 ++++----- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.h b/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.h index 8080f2097..bad043399 100644 --- a/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.h +++ b/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.h @@ -14,6 +14,7 @@ NS_ASSUME_NONNULL_BEGIN extern NSString *const FBSnapshotMaxDepthKey; +extern NSString *const FBSnapshotHonorModalViewsKey; void FBSetCustomParameterForElementSnapshot (NSString* name, id value); diff --git a/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.m b/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.m index 4027386c7..2e1236eed 100644 --- a/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.m +++ b/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.m @@ -14,6 +14,7 @@ #import "FBReflectionUtils.h" NSString *const FBSnapshotMaxDepthKey = @"maxDepth"; +NSString *const FBSnapshotHonorModalViewsKey = @"snapshotKeyHonorModalViews"; static id (*original_defaultParameters)(id, SEL); static NSMutableDictionary *customRequestParameters; diff --git a/WebDriverAgentLib/Utilities/FBXCAXClientProxy.m b/WebDriverAgentLib/Utilities/FBXCAXClientProxy.m index 8781a7c5e..3a9607440 100644 --- a/WebDriverAgentLib/Utilities/FBXCAXClientProxy.m +++ b/WebDriverAgentLib/Utilities/FBXCAXClientProxy.m @@ -40,12 +40,11 @@ - (BOOL)setAXTimeout:(NSTimeInterval)timeout error:(NSError **)error maxDepth:(nullable NSNumber *)maxDepth error:(NSError **)error { - // Setting parameters argument to nil enforces `requestSnapshotForElement` to - // fetch default values using the swizzled [XCAXClient_iOS defaultParameters] API call. - NSMutableDictionary *parameters = nil; + NSMutableDictionary *parameters = [NSMutableDictionary dictionaryWithDictionary:self.defaultParameters]; + // Mimicking XCTest framework behavior (this attribute is added by default unless it is an excludingNonModalElements query) + // See https://github.com/appium/WebDriverAgent/pull/523 + parameters[FBSnapshotHonorModalViewsKey] = @(NO); if (nil != maxDepth) { - parameters = [NSMutableDictionary new]; - [parameters addEntriesFromDictionary:self.defaultParameters]; parameters[FBSnapshotMaxDepthKey] = maxDepth; } From e61c27553198f4662893571fd791b666545dc03d Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Wed, 25 Jan 2023 18:24:48 +0100 Subject: [PATCH 12/15] Add more comments --- WebDriverAgentLib/Utilities/FBXCAXClientProxy.m | 3 +++ 1 file changed, 3 insertions(+) diff --git a/WebDriverAgentLib/Utilities/FBXCAXClientProxy.m b/WebDriverAgentLib/Utilities/FBXCAXClientProxy.m index 3a9607440..49b980b99 100644 --- a/WebDriverAgentLib/Utilities/FBXCAXClientProxy.m +++ b/WebDriverAgentLib/Utilities/FBXCAXClientProxy.m @@ -42,6 +42,9 @@ - (BOOL)setAXTimeout:(NSTimeInterval)timeout error:(NSError **)error { NSMutableDictionary *parameters = [NSMutableDictionary dictionaryWithDictionary:self.defaultParameters]; // Mimicking XCTest framework behavior (this attribute is added by default unless it is an excludingNonModalElements query) + // A regular snapshot retrieval path as part of resolving a query goes through [XCUIElementQuery _snapshotForElement:error:] + // before calling requestSnapshotForElement, and this is the part where the snapshotKeyHonorModalViews is added (as part of + // calling [XCTElementQuery snapshotParameters]) // See https://github.com/appium/WebDriverAgent/pull/523 parameters[FBSnapshotHonorModalViewsKey] = @(NO); if (nil != maxDepth) { From 3e9e32699185b319a5cfc8d1f3f8c1f0232f7cf8 Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Wed, 25 Jan 2023 21:47:27 +0100 Subject: [PATCH 13/15] Simplify swizzled method --- .../Categories/XCAXClient_iOS+FBSnapshotReqParams.m | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.m b/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.m index 2e1236eed..2f06555be 100644 --- a/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.m +++ b/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.m @@ -35,14 +35,11 @@ id FBGetCustomParameterForElementSnapshot (NSString *name) static id swizzleDefaultParameters(id self, SEL _cmd) { - if (nil == customRequestParameters || 0 == customRequestParameters.count) { - return original_defaultParameters(self, _cmd); + NSMutableDictionary *result = [NSMutableDictionary dictionaryWithDictionary:original_defaultParameters(self, _cmd)]; + if (nil != customRequestParameters && customRequestParameters.count > 0) { + [result addEntriesFromDictionary:customRequestParameters]; } - - NSMutableDictionary *result = [NSMutableDictionary new]; - [result addEntriesFromDictionary:original_defaultParameters(self, _cmd)]; - [result addEntriesFromDictionary:customRequestParameters]; - return [result copy]; + return result.copy; } @implementation XCAXClient_iOS (FBSnapshotReqParams) From 52aad4bebc45710e47ad7853c97f21414de7abdc Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Thu, 26 Jan 2023 10:26:41 +0100 Subject: [PATCH 14/15] Properly fetch additional params --- .../XCAXClient_iOS+FBSnapshotReqParams.h | 1 - .../XCAXClient_iOS+FBSnapshotReqParams.m | 45 ++++++++++++++++--- .../Utilities/FBXCAXClientProxy.m | 6 --- 3 files changed, 40 insertions(+), 12 deletions(-) diff --git a/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.h b/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.h index bad043399..8080f2097 100644 --- a/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.h +++ b/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.h @@ -14,7 +14,6 @@ NS_ASSUME_NONNULL_BEGIN extern NSString *const FBSnapshotMaxDepthKey; -extern NSString *const FBSnapshotHonorModalViewsKey; void FBSetCustomParameterForElementSnapshot (NSString* name, id value); diff --git a/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.m b/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.m index 2f06555be..e74b16a23 100644 --- a/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.m +++ b/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.m @@ -12,11 +12,23 @@ #import #import "FBReflectionUtils.h" +#import "FBApplication.h" +#import "XCUIElementQuery.h" +/** + Available parameters with their default values for XCTest: + @"maxChildren" : (int)2147483647 + @"traverseFromParentsToChildren" : YES + @"maxArrayCount" : (int)2147483647 + @"snapshotKeyHonorModalViews" : NO + @"maxDepth" : (int)2147483647 + */ NSString *const FBSnapshotMaxDepthKey = @"maxDepth"; -NSString *const FBSnapshotHonorModalViewsKey = @"snapshotKeyHonorModalViews"; static id (*original_defaultParameters)(id, SEL); +static id (*original_snapshotParameters)(id, SEL); +static NSDictionary *defaultRequestParameters; +static NSDictionary *defaultAdditionalRequestParameters; static NSMutableDictionary *customRequestParameters; void FBSetCustomParameterForElementSnapshot (NSString *name, id value) @@ -33,15 +45,34 @@ id FBGetCustomParameterForElementSnapshot (NSString *name) return customRequestParameters[name]; } -static id swizzleDefaultParameters(id self, SEL _cmd) +static id swizzledDefaultParameters(id self, SEL _cmd) { - NSMutableDictionary *result = [NSMutableDictionary dictionaryWithDictionary:original_defaultParameters(self, _cmd)]; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:original_defaultParameters(self, _cmd)]; + [params addEntriesFromDictionary:defaultAdditionalRequestParameters]; + defaultRequestParameters = params.copy; + }); + if (nil == defaultRequestParameters) { + return original_defaultParameters(self, _cmd); + } + NSMutableDictionary *result = [NSMutableDictionary dictionaryWithDictionary:defaultRequestParameters]; if (nil != customRequestParameters && customRequestParameters.count > 0) { [result addEntriesFromDictionary:customRequestParameters]; } return result.copy; } +static id swizzledSnapshotParameters(id self, SEL _cmd) +{ + NSDictionary *result = original_snapshotParameters(self, _cmd); + if (nil == defaultAdditionalRequestParameters) { + defaultAdditionalRequestParameters = result; + } + return result; +} + + @implementation XCAXClient_iOS (FBSnapshotReqParams) #pragma clang diagnostic push @@ -50,8 +81,12 @@ @implementation XCAXClient_iOS (FBSnapshotReqParams) + (void)load { Method original_defaultParametersMethod = class_getInstanceMethod(self.class, @selector(defaultParameters)); - IMP swizzledImp = (IMP)swizzleDefaultParameters; - original_defaultParameters = (id (*)(id, SEL)) method_setImplementation(original_defaultParametersMethod, swizzledImp); + IMP swizzledDefaultParametersImp = (IMP)swizzledDefaultParameters; + original_defaultParameters = (id (*)(id, SEL)) method_setImplementation(original_defaultParametersMethod, swizzledDefaultParametersImp); + + Method original_snapshotParametersMethod = class_getInstanceMethod(NSClassFromString(@"XCTElementQuery"), NSSelectorFromString(@"snapshotParameters")); + IMP swizzledSnapshotParametersImp = (IMP)swizzledSnapshotParameters; + original_snapshotParameters = (id (*)(id, SEL)) method_setImplementation(original_snapshotParametersMethod, swizzledSnapshotParametersImp); } #pragma clang diagnostic pop diff --git a/WebDriverAgentLib/Utilities/FBXCAXClientProxy.m b/WebDriverAgentLib/Utilities/FBXCAXClientProxy.m index 49b980b99..907bb25b1 100644 --- a/WebDriverAgentLib/Utilities/FBXCAXClientProxy.m +++ b/WebDriverAgentLib/Utilities/FBXCAXClientProxy.m @@ -41,12 +41,6 @@ - (BOOL)setAXTimeout:(NSTimeInterval)timeout error:(NSError **)error error:(NSError **)error { NSMutableDictionary *parameters = [NSMutableDictionary dictionaryWithDictionary:self.defaultParameters]; - // Mimicking XCTest framework behavior (this attribute is added by default unless it is an excludingNonModalElements query) - // A regular snapshot retrieval path as part of resolving a query goes through [XCUIElementQuery _snapshotForElement:error:] - // before calling requestSnapshotForElement, and this is the part where the snapshotKeyHonorModalViews is added (as part of - // calling [XCTElementQuery snapshotParameters]) - // See https://github.com/appium/WebDriverAgent/pull/523 - parameters[FBSnapshotHonorModalViewsKey] = @(NO); if (nil != maxDepth) { parameters[FBSnapshotMaxDepthKey] = maxDepth; } From 81a3f8a5faecfc7d71304f6c5ecdafa65354ff84 Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Thu, 26 Jan 2023 17:21:03 +0100 Subject: [PATCH 15/15] Remove extra imports --- .../Categories/XCAXClient_iOS+FBSnapshotReqParams.m | 4 ---- 1 file changed, 4 deletions(-) diff --git a/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.m b/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.m index e74b16a23..e8ee55560 100644 --- a/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.m +++ b/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.m @@ -11,10 +11,6 @@ #import -#import "FBReflectionUtils.h" -#import "FBApplication.h" -#import "XCUIElementQuery.h" - /** Available parameters with their default values for XCTest: @"maxChildren" : (int)2147483647