From ca1ffe581cd83783c71df9e28f97ce202e6837b8 Mon Sep 17 00:00:00 2001 From: ppken <27220367+ppken@users.noreply.github.com> Date: Wed, 6 Nov 2024 12:49:03 +0900 Subject: [PATCH 1/4] feat: add useHIDClear capability and setting --- WebDriverAgentLib/Categories/XCUIElement+FBTyping.m | 2 +- WebDriverAgentLib/Commands/FBSessionCommands.m | 8 ++++++++ WebDriverAgentLib/Utilities/FBCapabilities.h | 2 ++ WebDriverAgentLib/Utilities/FBCapabilities.m | 1 + WebDriverAgentLib/Utilities/FBConfiguration.h | 9 +++++++++ WebDriverAgentLib/Utilities/FBConfiguration.m | 12 ++++++++++++ WebDriverAgentLib/Utilities/FBSettings.h | 1 + WebDriverAgentLib/Utilities/FBSettings.m | 1 + lib/types.ts | 2 ++ 9 files changed, 37 insertions(+), 1 deletion(-) diff --git a/WebDriverAgentLib/Categories/XCUIElement+FBTyping.m b/WebDriverAgentLib/Categories/XCUIElement+FBTyping.m index db516a220..8a3f1f16b 100644 --- a/WebDriverAgentLib/Categories/XCUIElement+FBTyping.m +++ b/WebDriverAgentLib/Categories/XCUIElement+FBTyping.m @@ -166,7 +166,7 @@ - (BOOL)fb_clearTextWithSnapshot:(FBXCElementSnapshotWrapper *)snapshot [self fb_prepareForTextInputWithSnapshot:snapshot]; } - if (retry == 0) { + if (retry == 0 && FBConfiguration.useHIDClear) { // 1st attempt is via the IOHIDEvent as the fastest operation // https://github.com/appium/appium/issues/19389 [[XCUIDevice sharedDevice] fb_performIOHIDEventWithPage:0x07 // kHIDPage_KeyboardOrKeypad diff --git a/WebDriverAgentLib/Commands/FBSessionCommands.m b/WebDriverAgentLib/Commands/FBSessionCommands.m index c11c5eabb..b59735839 100644 --- a/WebDriverAgentLib/Commands/FBSessionCommands.m +++ b/WebDriverAgentLib/Commands/FBSessionCommands.m @@ -141,6 +141,10 @@ + (NSArray *)routes [FBConfiguration forceSimulatorSoftwareKeyboardPresence]; } + if (capabilities[FB_CAP_USE_HID_CLEAR]) { + [FBConfiguration setUseHIDClear:[capabilities[FB_CAP_USE_HID_CLEAR] boolValue]]; + } + NSString *bundleID = capabilities[FB_CAP_BUNDLE_ID]; NSString *initialUrl = capabilities[FB_CAP_INITIAL_URL]; XCUIApplication *app = nil; @@ -351,6 +355,7 @@ + (NSArray *)routes FB_SETTING_DEFAULT_ALERT_ACTION: request.session.defaultAlertAction ?: @"", FB_SETTING_MAX_TYPING_FREQUENCY: @([FBConfiguration maxTypingFrequency]), FB_SETTING_RESPECT_SYSTEM_ALERTS: @([FBConfiguration shouldRespectSystemAlerts]), + FB_SETTING_USE_HID_CLEAR: @([FBConfiguration useHIDClear]), #if !TARGET_OS_TV FB_SETTING_SCREENSHOT_ORIENTATION: [FBConfiguration humanReadableScreenshotOrientation], #endif @@ -449,6 +454,9 @@ + (NSArray *)routes if (nil != [settings objectForKey:FB_SETTING_MAX_TYPING_FREQUENCY]) { [FBConfiguration setMaxTypingFrequency:[[settings objectForKey:FB_SETTING_MAX_TYPING_FREQUENCY] unsignedIntegerValue]]; } + if (nil != [settings objectForKey:FB_SETTING_USE_HID_CLEAR]) { + [FBConfiguration setUseHIDClear:[[settings objectForKey:FB_SETTING_USE_HID_CLEAR] boolValue]]; + } #if !TARGET_OS_TV if (nil != [settings objectForKey:FB_SETTING_SCREENSHOT_ORIENTATION]) { diff --git a/WebDriverAgentLib/Utilities/FBCapabilities.h b/WebDriverAgentLib/Utilities/FBCapabilities.h index 20dad743e..f639be12d 100644 --- a/WebDriverAgentLib/Utilities/FBCapabilities.h +++ b/WebDriverAgentLib/Utilities/FBCapabilities.h @@ -44,3 +44,5 @@ extern NSString* const FB_CAP_USE_NATIVE_CACHING_STRATEGY; extern NSString* const FB_CAP_FORCE_SIMULATOR_SOFTWARE_KEYBOARD_PRESENCE; /** Sets the application state change timeout for the initial app startup */ extern NSString* const FB_CAP_APP_LAUNCH_STATE_TIMEOUT_SEC; +/** Whether to use HIDEvent for text clear */ +extern NSString* const FB_CAP_USE_HID_CLEAR; \ No newline at end of file diff --git a/WebDriverAgentLib/Utilities/FBCapabilities.m b/WebDriverAgentLib/Utilities/FBCapabilities.m index b6ccc9ce4..5256ae2f7 100644 --- a/WebDriverAgentLib/Utilities/FBCapabilities.m +++ b/WebDriverAgentLib/Utilities/FBCapabilities.m @@ -24,3 +24,4 @@ NSString* const FB_CAP_USE_NATIVE_CACHING_STRATEGY = @"useNativeCachingStrategy"; NSString* const FB_CAP_FORCE_SIMULATOR_SOFTWARE_KEYBOARD_PRESENCE = @"forceSimulatorSoftwareKeyboardPresence"; NSString* const FB_CAP_APP_LAUNCH_STATE_TIMEOUT_SEC = @"appLaunchStateTimeoutSec"; +NSString* const FB_CAP_USE_HID_CLEAR = @"useHIDClear"; diff --git a/WebDriverAgentLib/Utilities/FBConfiguration.h b/WebDriverAgentLib/Utilities/FBConfiguration.h index 75275ccf6..9925bd9df 100644 --- a/WebDriverAgentLib/Utilities/FBConfiguration.h +++ b/WebDriverAgentLib/Utilities/FBConfiguration.h @@ -283,6 +283,15 @@ typedef NS_ENUM(NSInteger, FBConfigurationKeyboardPreference) { + (void)setDismissAlertButtonSelector:(NSString *)classChainSelector; + (NSString *)dismissAlertButtonSelector; +/** + * Whether to use HIDEvent for text clear. + * By default this is enabled and HIDEvent is used for text clear. + * + * @param enabled Either YES or NO + */ ++ (void)setUseHIDClear:(BOOL)enabled; ++ (BOOL)useHIDClear; + #if !TARGET_OS_TV /** Set the screenshot orientation for iOS diff --git a/WebDriverAgentLib/Utilities/FBConfiguration.m b/WebDriverAgentLib/Utilities/FBConfiguration.m index e91717b2d..3930ddd57 100644 --- a/WebDriverAgentLib/Utilities/FBConfiguration.m +++ b/WebDriverAgentLib/Utilities/FBConfiguration.m @@ -56,6 +56,7 @@ static NSTimeInterval FBAnimationCoolOffTimeout; static BOOL FBShouldUseCompactResponses; static NSString *FBElementResponseAttributes; +static BOOL FBUseHIDClear; #if !TARGET_OS_TV static UIInterfaceOrientation FBScreenshotOrientation; #endif @@ -438,6 +439,16 @@ + (NSString *)dismissAlertButtonSelector return FBDismissAlertButtonSelector; } ++ (void)setUseHIDClear:(BOOL)enabled +{ + FBUseHIDClear = enabled; +} + ++ (BOOL)useHIDClear +{ + return FBUseHIDClear; +} + #if !TARGET_OS_TV + (BOOL)setScreenshotOrientation:(NSString *)orientation error:(NSError **)error { @@ -503,6 +514,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); + FBUseHIDClear = YES; #if !TARGET_OS_TV FBScreenshotOrientation = UIInterfaceOrientationUnknown; #endif diff --git a/WebDriverAgentLib/Utilities/FBSettings.h b/WebDriverAgentLib/Utilities/FBSettings.h index 5f4450110..2736e9f57 100644 --- a/WebDriverAgentLib/Utilities/FBSettings.h +++ b/WebDriverAgentLib/Utilities/FBSettings.h @@ -40,6 +40,7 @@ extern NSString* const FB_SETTING_WAIT_FOR_IDLE_TIMEOUT; extern NSString* const FB_SETTING_ANIMATION_COOL_OFF_TIMEOUT; extern NSString* const FB_SETTING_MAX_TYPING_FREQUENCY; extern NSString* const FB_SETTING_RESPECT_SYSTEM_ALERTS; +extern NSString* const FB_SETTING_USE_HID_CLEAR; NS_ASSUME_NONNULL_END diff --git a/WebDriverAgentLib/Utilities/FBSettings.m b/WebDriverAgentLib/Utilities/FBSettings.m index a45afeb90..d9fe494a2 100644 --- a/WebDriverAgentLib/Utilities/FBSettings.m +++ b/WebDriverAgentLib/Utilities/FBSettings.m @@ -35,3 +35,4 @@ NSString* const FB_SETTING_ANIMATION_COOL_OFF_TIMEOUT = @"animationCoolOffTimeout"; NSString* const FB_SETTING_MAX_TYPING_FREQUENCY = @"maxTypingFrequency"; NSString* const FB_SETTING_RESPECT_SYSTEM_ALERTS = @"respectSystemAlerts"; +NSString* const FB_SETTING_USE_HID_CLEAR = @"useHIDClear"; diff --git a/lib/types.ts b/lib/types.ts index 8b41dfc4e..f4e58b067 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -25,6 +25,7 @@ export interface WDASettings { waitForIdleTimeout?: number; animationCoolOffTimeout?: number; maxTypingFrequency?: number; + useHIDClear?: boolean; } // WebDriverAgentLib/Utilities/FBCapabilities.h @@ -48,4 +49,5 @@ export interface WDACapabilities { forceSimulatorSoftwareKeyboardPresence?: boolean; defaultAlertAction?: 'accept' | 'dismiss'; appLaunchStateTimeoutSec?: number; + useHIDClear?: boolean; } From 35afc8ffbbeae9fcd098a1ae292c18ec9b0ff52f Mon Sep 17 00:00:00 2001 From: ppken <27220367+ppken@users.noreply.github.com> Date: Thu, 7 Nov 2024 07:20:24 +0900 Subject: [PATCH 2/4] fix: remove capability --- WebDriverAgentLib/Commands/FBSessionCommands.m | 4 ---- WebDriverAgentLib/Utilities/FBCapabilities.h | 4 +--- WebDriverAgentLib/Utilities/FBCapabilities.m | 1 - lib/types.ts | 1 - 4 files changed, 1 insertion(+), 9 deletions(-) diff --git a/WebDriverAgentLib/Commands/FBSessionCommands.m b/WebDriverAgentLib/Commands/FBSessionCommands.m index b59735839..320bb5352 100644 --- a/WebDriverAgentLib/Commands/FBSessionCommands.m +++ b/WebDriverAgentLib/Commands/FBSessionCommands.m @@ -141,10 +141,6 @@ + (NSArray *)routes [FBConfiguration forceSimulatorSoftwareKeyboardPresence]; } - if (capabilities[FB_CAP_USE_HID_CLEAR]) { - [FBConfiguration setUseHIDClear:[capabilities[FB_CAP_USE_HID_CLEAR] boolValue]]; - } - NSString *bundleID = capabilities[FB_CAP_BUNDLE_ID]; NSString *initialUrl = capabilities[FB_CAP_INITIAL_URL]; XCUIApplication *app = nil; diff --git a/WebDriverAgentLib/Utilities/FBCapabilities.h b/WebDriverAgentLib/Utilities/FBCapabilities.h index f639be12d..934a61329 100644 --- a/WebDriverAgentLib/Utilities/FBCapabilities.h +++ b/WebDriverAgentLib/Utilities/FBCapabilities.h @@ -43,6 +43,4 @@ extern NSString* const FB_CAP_USE_NATIVE_CACHING_STRATEGY; /** Whether to enforce software keyboard presence on simulator */ extern NSString* const FB_CAP_FORCE_SIMULATOR_SOFTWARE_KEYBOARD_PRESENCE; /** Sets the application state change timeout for the initial app startup */ -extern NSString* const FB_CAP_APP_LAUNCH_STATE_TIMEOUT_SEC; -/** Whether to use HIDEvent for text clear */ -extern NSString* const FB_CAP_USE_HID_CLEAR; \ No newline at end of file +extern NSString* const FB_CAP_APP_LAUNCH_STATE_TIMEOUT_SEC; \ No newline at end of file diff --git a/WebDriverAgentLib/Utilities/FBCapabilities.m b/WebDriverAgentLib/Utilities/FBCapabilities.m index 5256ae2f7..b6ccc9ce4 100644 --- a/WebDriverAgentLib/Utilities/FBCapabilities.m +++ b/WebDriverAgentLib/Utilities/FBCapabilities.m @@ -24,4 +24,3 @@ NSString* const FB_CAP_USE_NATIVE_CACHING_STRATEGY = @"useNativeCachingStrategy"; NSString* const FB_CAP_FORCE_SIMULATOR_SOFTWARE_KEYBOARD_PRESENCE = @"forceSimulatorSoftwareKeyboardPresence"; NSString* const FB_CAP_APP_LAUNCH_STATE_TIMEOUT_SEC = @"appLaunchStateTimeoutSec"; -NSString* const FB_CAP_USE_HID_CLEAR = @"useHIDClear"; diff --git a/lib/types.ts b/lib/types.ts index f4e58b067..a07f1d88c 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -49,5 +49,4 @@ export interface WDACapabilities { forceSimulatorSoftwareKeyboardPresence?: boolean; defaultAlertAction?: 'accept' | 'dismiss'; appLaunchStateTimeoutSec?: number; - useHIDClear?: boolean; } From e89b0f77a76ac2ee56826c79bc7ac09cad99781c Mon Sep 17 00:00:00 2001 From: ppken <27220367+ppken@users.noreply.github.com> Date: Thu, 7 Nov 2024 07:40:00 +0900 Subject: [PATCH 3/4] fix: fix setting name --- WebDriverAgentLib/Categories/XCUIElement+FBTyping.m | 2 +- WebDriverAgentLib/Commands/FBSessionCommands.m | 10 +++++++--- WebDriverAgentLib/Utilities/FBConfiguration.h | 4 ++-- WebDriverAgentLib/Utilities/FBConfiguration.m | 12 ++++++------ WebDriverAgentLib/Utilities/FBSettings.h | 2 +- WebDriverAgentLib/Utilities/FBSettings.m | 2 +- lib/types.ts | 2 +- 7 files changed, 19 insertions(+), 15 deletions(-) diff --git a/WebDriverAgentLib/Categories/XCUIElement+FBTyping.m b/WebDriverAgentLib/Categories/XCUIElement+FBTyping.m index 8a3f1f16b..8b59ad031 100644 --- a/WebDriverAgentLib/Categories/XCUIElement+FBTyping.m +++ b/WebDriverAgentLib/Categories/XCUIElement+FBTyping.m @@ -166,7 +166,7 @@ - (BOOL)fb_clearTextWithSnapshot:(FBXCElementSnapshotWrapper *)snapshot [self fb_prepareForTextInputWithSnapshot:snapshot]; } - if (retry == 0 && FBConfiguration.useHIDClear) { + if (retry == 0 && FBConfiguration.useClearTextShortcut) { // 1st attempt is via the IOHIDEvent as the fastest operation // https://github.com/appium/appium/issues/19389 [[XCUIDevice sharedDevice] fb_performIOHIDEventWithPage:0x07 // kHIDPage_KeyboardOrKeypad diff --git a/WebDriverAgentLib/Commands/FBSessionCommands.m b/WebDriverAgentLib/Commands/FBSessionCommands.m index 320bb5352..e5d4894f5 100644 --- a/WebDriverAgentLib/Commands/FBSessionCommands.m +++ b/WebDriverAgentLib/Commands/FBSessionCommands.m @@ -141,6 +141,10 @@ + (NSArray *)routes [FBConfiguration forceSimulatorSoftwareKeyboardPresence]; } + if (capabilities[FB_SETTING_USE_CLEAR_TEXT_SHORTCUT]) { + [FBConfiguration setUseClearTextShortcut:[capabilities[FB_SETTING_USE_CLEAR_TEXT_SHORTCUT] boolValue]]; + } + NSString *bundleID = capabilities[FB_CAP_BUNDLE_ID]; NSString *initialUrl = capabilities[FB_CAP_INITIAL_URL]; XCUIApplication *app = nil; @@ -351,7 +355,7 @@ + (NSArray *)routes FB_SETTING_DEFAULT_ALERT_ACTION: request.session.defaultAlertAction ?: @"", FB_SETTING_MAX_TYPING_FREQUENCY: @([FBConfiguration maxTypingFrequency]), FB_SETTING_RESPECT_SYSTEM_ALERTS: @([FBConfiguration shouldRespectSystemAlerts]), - FB_SETTING_USE_HID_CLEAR: @([FBConfiguration useHIDClear]), + FB_SETTING_USE_CLEAR_TEXT_SHORTCUT: @([FBConfiguration useClearTextShortcut]), #if !TARGET_OS_TV FB_SETTING_SCREENSHOT_ORIENTATION: [FBConfiguration humanReadableScreenshotOrientation], #endif @@ -450,8 +454,8 @@ + (NSArray *)routes if (nil != [settings objectForKey:FB_SETTING_MAX_TYPING_FREQUENCY]) { [FBConfiguration setMaxTypingFrequency:[[settings objectForKey:FB_SETTING_MAX_TYPING_FREQUENCY] unsignedIntegerValue]]; } - if (nil != [settings objectForKey:FB_SETTING_USE_HID_CLEAR]) { - [FBConfiguration setUseHIDClear:[[settings objectForKey:FB_SETTING_USE_HID_CLEAR] boolValue]]; + if (nil != [settings objectForKey:FB_SETTING_USE_CLEAR_TEXT_SHORTCUT]) { + [FBConfiguration setUseClearTextShortcut:[[settings objectForKey:FB_SETTING_USE_CLEAR_TEXT_SHORTCUT] boolValue]]; } #if !TARGET_OS_TV diff --git a/WebDriverAgentLib/Utilities/FBConfiguration.h b/WebDriverAgentLib/Utilities/FBConfiguration.h index 9925bd9df..7c337826c 100644 --- a/WebDriverAgentLib/Utilities/FBConfiguration.h +++ b/WebDriverAgentLib/Utilities/FBConfiguration.h @@ -289,8 +289,8 @@ typedef NS_ENUM(NSInteger, FBConfigurationKeyboardPreference) { * * @param enabled Either YES or NO */ -+ (void)setUseHIDClear:(BOOL)enabled; -+ (BOOL)useHIDClear; ++ (void)setUseClearTextShortcut:(BOOL)enabled; ++ (BOOL)useClearTextShortcut; #if !TARGET_OS_TV /** diff --git a/WebDriverAgentLib/Utilities/FBConfiguration.m b/WebDriverAgentLib/Utilities/FBConfiguration.m index 3930ddd57..dab8cb4db 100644 --- a/WebDriverAgentLib/Utilities/FBConfiguration.m +++ b/WebDriverAgentLib/Utilities/FBConfiguration.m @@ -56,7 +56,7 @@ static NSTimeInterval FBAnimationCoolOffTimeout; static BOOL FBShouldUseCompactResponses; static NSString *FBElementResponseAttributes; -static BOOL FBUseHIDClear; +static BOOL FBUseClearTextShortcut; #if !TARGET_OS_TV static UIInterfaceOrientation FBScreenshotOrientation; #endif @@ -439,14 +439,14 @@ + (NSString *)dismissAlertButtonSelector return FBDismissAlertButtonSelector; } -+ (void)setUseHIDClear:(BOOL)enabled ++ (void)setUseClearTextShortcut:(BOOL)enabled { - FBUseHIDClear = enabled; + FBUseClearTextShortcut = enabled; } -+ (BOOL)useHIDClear ++ (BOOL)useClearTextShortcut { - return FBUseHIDClear; + return FBUseClearTextShortcut; } #if !TARGET_OS_TV @@ -514,7 +514,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); - FBUseHIDClear = YES; + FBUseClearTextShortcut = YES; #if !TARGET_OS_TV FBScreenshotOrientation = UIInterfaceOrientationUnknown; #endif diff --git a/WebDriverAgentLib/Utilities/FBSettings.h b/WebDriverAgentLib/Utilities/FBSettings.h index 2736e9f57..b1f2f1fca 100644 --- a/WebDriverAgentLib/Utilities/FBSettings.h +++ b/WebDriverAgentLib/Utilities/FBSettings.h @@ -40,7 +40,7 @@ extern NSString* const FB_SETTING_WAIT_FOR_IDLE_TIMEOUT; extern NSString* const FB_SETTING_ANIMATION_COOL_OFF_TIMEOUT; extern NSString* const FB_SETTING_MAX_TYPING_FREQUENCY; extern NSString* const FB_SETTING_RESPECT_SYSTEM_ALERTS; -extern NSString* const FB_SETTING_USE_HID_CLEAR; +extern NSString* const FB_SETTING_USE_CLEAR_TEXT_SHORTCUT; NS_ASSUME_NONNULL_END diff --git a/WebDriverAgentLib/Utilities/FBSettings.m b/WebDriverAgentLib/Utilities/FBSettings.m index d9fe494a2..ada529eed 100644 --- a/WebDriverAgentLib/Utilities/FBSettings.m +++ b/WebDriverAgentLib/Utilities/FBSettings.m @@ -35,4 +35,4 @@ NSString* const FB_SETTING_ANIMATION_COOL_OFF_TIMEOUT = @"animationCoolOffTimeout"; NSString* const FB_SETTING_MAX_TYPING_FREQUENCY = @"maxTypingFrequency"; NSString* const FB_SETTING_RESPECT_SYSTEM_ALERTS = @"respectSystemAlerts"; -NSString* const FB_SETTING_USE_HID_CLEAR = @"useHIDClear"; +NSString* const FB_SETTING_USE_CLEAR_TEXT_SHORTCUT = @"useClearTextShortcut"; diff --git a/lib/types.ts b/lib/types.ts index a07f1d88c..82c51cb15 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -25,7 +25,7 @@ export interface WDASettings { waitForIdleTimeout?: number; animationCoolOffTimeout?: number; maxTypingFrequency?: number; - useHIDClear?: boolean; + useClearTextShortcut?: boolean; } // WebDriverAgentLib/Utilities/FBCapabilities.h From b639620a70fb9a489fd728f64af85bccf6c3b36d Mon Sep 17 00:00:00 2001 From: ppken <27220367+ppken@users.noreply.github.com> Date: Thu, 7 Nov 2024 08:12:16 +0900 Subject: [PATCH 4/4] fix: revert unnecessary change --- WebDriverAgentLib/Utilities/FBCapabilities.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WebDriverAgentLib/Utilities/FBCapabilities.h b/WebDriverAgentLib/Utilities/FBCapabilities.h index 934a61329..20dad743e 100644 --- a/WebDriverAgentLib/Utilities/FBCapabilities.h +++ b/WebDriverAgentLib/Utilities/FBCapabilities.h @@ -43,4 +43,4 @@ extern NSString* const FB_CAP_USE_NATIVE_CACHING_STRATEGY; /** Whether to enforce software keyboard presence on simulator */ extern NSString* const FB_CAP_FORCE_SIMULATOR_SOFTWARE_KEYBOARD_PRESENCE; /** Sets the application state change timeout for the initial app startup */ -extern NSString* const FB_CAP_APP_LAUNCH_STATE_TIMEOUT_SEC; \ No newline at end of file +extern NSString* const FB_CAP_APP_LAUNCH_STATE_TIMEOUT_SEC;