Skip to content

Commit ab036df

Browse files
fixup! feat: expose customActions on the element
Add element double declaration for custom actions in unit tests.
1 parent 6fbf62e commit ab036df

16 files changed

Lines changed: 116 additions & 49 deletions

File tree

WebDriverAgentLib/Categories/XCUIElement+FBCustomActions.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#import "XCUIElement+FBUtilities.h"
1111
#import "FBXCElementSnapshotWrapper+Helpers.h"
1212
#import "FBLogger.h"
13+
#import "FBConfiguration.h"
1314
#import "XCTestPrivateSymbols.h"
1415

1516
@interface FBXCElementSnapshotWrapper (FBCustomActionsInternal)
@@ -88,7 +89,7 @@ - (NSString *)fb_stringAttribute:(NSString *)attributeName
8889
NSLog(@"[FBCustomActions] Custom action title: %@", title);
8990
}
9091

91-
NSString *joined = [stringified componentsJoinedByString:@", "];
92+
NSString *joined = [stringified componentsJoinedByString:[FBConfiguration customActionsDelimiter]];
9293
NSMutableDictionary *updated =
9394
(self.additionalAttributes ?: @{}).mutableCopy;
9495
updated[symbol] = joined;

WebDriverAgentLib/Commands/FBSessionCommands.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ + (NSArray *)routes
356356
FB_SETTING_INCLUDE_NATIVE_FRAME_IN_PAGE_SOURCE: @([FBConfiguration includeNativeFrameInPageSource]),
357357
FB_SETTING_INCLUDE_MIN_MAX_VALUE_IN_PAGE_SOURCE: @([FBConfiguration includeMinMaxValueInPageSource]),
358358
FB_SETTING_INCLUDE_CUSTOM_ACTIONS_IN_PAGE_SOURCE: @([FBConfiguration includeCustomActionsInPageSource]),
359+
FB_SETTING_CUSTOM_ACTIONS_DELIMITER: [FBConfiguration customActionsDelimiter],
359360
FB_SETTING_ENFORCE_CUSTOM_SNAPSHOTS: @([FBConfiguration enforceCustomSnapshots]),
360361
FB_SETTING_LIMIT_XPATH_CONTEXT_SCOPE: @([FBConfiguration limitXpathContextScope]),
361362
#if !TARGET_OS_TV
@@ -471,6 +472,9 @@ + (NSArray *)routes
471472
if (nil != [settings objectForKey:FB_SETTING_INCLUDE_CUSTOM_ACTIONS_IN_PAGE_SOURCE]) {
472473
[FBConfiguration setIncludeCustomActionsInPageSource:[[settings objectForKey:FB_SETTING_INCLUDE_CUSTOM_ACTIONS_IN_PAGE_SOURCE] boolValue]];
473474
}
475+
if (nil != [settings objectForKey:FB_SETTING_CUSTOM_ACTIONS_DELIMITER]) {
476+
[FBConfiguration setCustomActionsDelimiter:(NSString *)[settings objectForKey:FB_SETTING_CUSTOM_ACTIONS_DELIMITER]];
477+
}
474478
if (nil != [settings objectForKey:FB_SETTING_ENFORCE_CUSTOM_SNAPSHOTS]) {
475479
[FBConfiguration setEnforceCustomSnapshots:[[settings objectForKey:FB_SETTING_ENFORCE_CUSTOM_SNAPSHOTS] boolValue]];
476480
}

WebDriverAgentLib/Utilities/FBConfiguration.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,15 @@ typedef NS_ENUM(NSInteger, FBConfigurationKeyboardPreference) {
387387
+ (void)setIncludeCustomActionsInPageSource:(BOOL)enabled;
388388
+ (BOOL)includeCustomActionsInPageSource;
389389

390+
/**
391+
* Sets the delimiter string used when joining custom action names.
392+
* Defaults to ", " (comma followed by space).
393+
*
394+
* @param delimiter The delimiter string to use when joining custom actions
395+
*/
396+
+ (void)setCustomActionsDelimiter:(NSString *)delimiter;
397+
+ (NSString *)customActionsDelimiter;
398+
390399
/**
391400
* Whether to enforce the use of custom snapshots instead of standard snapshots.
392401
* When enabled, fb_customSnapshot is always invoked instead of fb_standardSnapshot

WebDriverAgentLib/Utilities/FBConfiguration.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
static BOOL FBShouldIncludeMinMaxValueInPageSource = NO;
6666
static BOOL FBShouldIncludeCustomActionsInPageSource = NO;
6767
static BOOL FBShouldEnforceCustomSnapshots = NO;
68+
static NSString *FBCustomActionsDelimiter;
6869

6970
@implementation FBConfiguration
7071

@@ -543,6 +544,7 @@ + (void)resetSessionSettings
543544
FBSetCustomParameterForElementSnapshot(FBSnapshotMaxDepthKey, @50);
544545
FBUseClearTextShortcut = YES;
545546
FBLimitXpathContextScope = YES;
547+
FBCustomActionsDelimiter = @", ";
546548
#if !TARGET_OS_TV
547549
FBScreenshotOrientation = UIInterfaceOrientationUnknown;
548550
#endif
@@ -698,6 +700,16 @@ + (BOOL)includeCustomActionsInPageSource
698700
return FBShouldIncludeCustomActionsInPageSource;
699701
}
700702

703+
+ (void)setCustomActionsDelimiter:(NSString *)delimiter
704+
{
705+
FBCustomActionsDelimiter = delimiter ?: @", ";
706+
}
707+
708+
+ (NSString *)customActionsDelimiter
709+
{
710+
return FBCustomActionsDelimiter ?: @", ";
711+
}
712+
701713
+ (void)setEnforceCustomSnapshots:(BOOL)enabled
702714
{
703715
FBShouldEnforceCustomSnapshots = enabled;

WebDriverAgentLib/Utilities/FBSettings.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ extern NSString *const FB_SETTING_INCLUDE_HITTABLE_IN_PAGE_SOURCE;
4343
extern NSString *const FB_SETTING_INCLUDE_NATIVE_FRAME_IN_PAGE_SOURCE;
4444
extern NSString *const FB_SETTING_INCLUDE_MIN_MAX_VALUE_IN_PAGE_SOURCE;
4545
extern NSString *const FB_SETTING_INCLUDE_CUSTOM_ACTIONS_IN_PAGE_SOURCE;
46+
extern NSString *const FB_SETTING_CUSTOM_ACTIONS_DELIMITER;
4647
extern NSString *const FB_SETTING_ENFORCE_CUSTOM_SNAPSHOTS;
4748

4849
NS_ASSUME_NONNULL_END

WebDriverAgentLib/Utilities/FBSettings.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,5 @@
3939
NSString* const FB_SETTING_INCLUDE_NATIVE_FRAME_IN_PAGE_SOURCE = @"includeNativeFrameInPageSource";
4040
NSString* const FB_SETTING_INCLUDE_MIN_MAX_VALUE_IN_PAGE_SOURCE = @"includeMinMaxValueInPageSource";
4141
NSString* const FB_SETTING_INCLUDE_CUSTOM_ACTIONS_IN_PAGE_SOURCE = @"includeCustomActionsInPageSource";
42+
NSString* const FB_SETTING_CUSTOM_ACTIONS_DELIMITER = @"customActionsDelimiter";
4243
NSString* const FB_SETTING_ENFORCE_CUSTOM_SNAPSHOTS = @"enforceCustomSnapshots";

WebDriverAgentTests/IntegrationApp/Classes/ViewController.m

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,32 @@
1010

1111
@interface ViewController ()
1212
@property (weak, nonatomic) IBOutlet UILabel *orentationLabel;
13+
@property (weak, nonatomic) IBOutlet UIButton *button;
1314
@end
1415

1516
@implementation ViewController
1617

18+
- (void)viewDidLoad
19+
{
20+
[super viewDidLoad];
21+
22+
UIAccessibilityCustomAction *action1 =
23+
[[UIAccessibilityCustomAction alloc] initWithName:@"Custom Action 1"
24+
target:self
25+
selector:@selector(handleCustomAction:)];
26+
UIAccessibilityCustomAction *action2 =
27+
[[UIAccessibilityCustomAction alloc] initWithName:@"Custom Action 2"
28+
target:self
29+
selector:@selector(handleCustomAction:)];
30+
self.button.accessibilityCustomActions = @[action1, action2];
31+
}
32+
33+
- (BOOL)handleCustomAction:(UIAccessibilityCustomAction *)action
34+
{
35+
// Custom action handler - just return YES to indicate success
36+
return YES;
37+
}
38+
1739
- (IBAction)deadlockApp:(id)sender
1840
{
1941
dispatch_sync(dispatch_get_main_queue(), ^{

0 commit comments

Comments
 (0)