Skip to content

Commit

Permalink
feat: add useClearTextShortcut setting (#952)
Browse files Browse the repository at this point in the history
  • Loading branch information
ppken authored Nov 7, 2024
1 parent afd09a8 commit 61bc051
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion WebDriverAgentLib/Categories/XCUIElement+FBTyping.m
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ - (BOOL)fb_clearTextWithSnapshot:(FBXCElementSnapshotWrapper *)snapshot
[self fb_prepareForTextInputWithSnapshot:snapshot];
}

if (retry == 0) {
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
Expand Down
8 changes: 8 additions & 0 deletions WebDriverAgentLib/Commands/FBSessionCommands.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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_CLEAR_TEXT_SHORTCUT: @([FBConfiguration useClearTextShortcut]),
#if !TARGET_OS_TV
FB_SETTING_SCREENSHOT_ORIENTATION: [FBConfiguration humanReadableScreenshotOrientation],
#endif
Expand Down Expand Up @@ -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_CLEAR_TEXT_SHORTCUT]) {
[FBConfiguration setUseClearTextShortcut:[[settings objectForKey:FB_SETTING_USE_CLEAR_TEXT_SHORTCUT] boolValue]];
}

#if !TARGET_OS_TV
if (nil != [settings objectForKey:FB_SETTING_SCREENSHOT_ORIENTATION]) {
Expand Down
9 changes: 9 additions & 0 deletions WebDriverAgentLib/Utilities/FBConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)setUseClearTextShortcut:(BOOL)enabled;
+ (BOOL)useClearTextShortcut;

#if !TARGET_OS_TV
/**
Set the screenshot orientation for iOS
Expand Down
12 changes: 12 additions & 0 deletions WebDriverAgentLib/Utilities/FBConfiguration.m
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
static NSTimeInterval FBAnimationCoolOffTimeout;
static BOOL FBShouldUseCompactResponses;
static NSString *FBElementResponseAttributes;
static BOOL FBUseClearTextShortcut;
#if !TARGET_OS_TV
static UIInterfaceOrientation FBScreenshotOrientation;
#endif
Expand Down Expand Up @@ -438,6 +439,16 @@ + (NSString *)dismissAlertButtonSelector
return FBDismissAlertButtonSelector;
}

+ (void)setUseClearTextShortcut:(BOOL)enabled
{
FBUseClearTextShortcut = enabled;
}

+ (BOOL)useClearTextShortcut
{
return FBUseClearTextShortcut;
}

#if !TARGET_OS_TV
+ (BOOL)setScreenshotOrientation:(NSString *)orientation error:(NSError **)error
{
Expand Down Expand Up @@ -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);
FBUseClearTextShortcut = YES;
#if !TARGET_OS_TV
FBScreenshotOrientation = UIInterfaceOrientationUnknown;
#endif
Expand Down
1 change: 1 addition & 0 deletions WebDriverAgentLib/Utilities/FBSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_CLEAR_TEXT_SHORTCUT;


NS_ASSUME_NONNULL_END
1 change: 1 addition & 0 deletions WebDriverAgentLib/Utilities/FBSettings.m
Original file line number Diff line number Diff line change
Expand Up @@ -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_CLEAR_TEXT_SHORTCUT = @"useClearTextShortcut";
1 change: 1 addition & 0 deletions lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface WDASettings {
waitForIdleTimeout?: number;
animationCoolOffTimeout?: number;
maxTypingFrequency?: number;
useClearTextShortcut?: boolean;
}

// WebDriverAgentLib/Utilities/FBCapabilities.h
Expand Down

0 comments on commit 61bc051

Please sign in to comment.