forked from facebookarchive/WebDriverAgent
-
Notifications
You must be signed in to change notification settings - Fork 463
feat: expose customActions on the element #1095
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mykola-mokhnach
merged 6 commits into
appium:master
from
ihor-kravchenko-evinced:feat/add-cutom-custom-actions-attribute
Dec 28, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f9518ed
feat: expose customActions on the element
ihor-kravchenko-evinced 49f1d0d
fix: remove custom actions delimiter configuration
ihor-kravchenko-evinced b9a5137
fix: split fb_stringAttribute method into smaller methods
ihor-kravchenko-evinced 1f08b88
fix: use dedicated logger instead of NSLog
ihor-kravchenko-evinced 3b8531a
fix: update method body formatting according to common code style
ihor-kravchenko-evinced a5a4cdb
fix: reduce line length
ihor-kravchenko-evinced File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
WebDriverAgentLib/Categories/XCUIElement+FBCustomActions.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| /** | ||
| * 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. | ||
| */ | ||
|
|
||
| #import <WebDriverAgentLib/FBXCElementSnapshotWrapper.h> | ||
|
|
||
| NS_ASSUME_NONNULL_BEGIN | ||
|
|
||
| @interface XCUIElement (FBCustomActions) | ||
|
|
||
| /*! Custom accessibility actions as a string – may be nil if the element does not have this attribute */ | ||
| @property (nonatomic, readonly, nullable) NSString *fb_customActions; | ||
|
|
||
| @end | ||
|
|
||
| @interface FBXCElementSnapshotWrapper (FBCustomActions) | ||
|
|
||
| /*! Custom accessibility actions as a string – may be nil if the element does not have this attribute */ | ||
| @property (nonatomic, readonly, nullable) NSString *fb_customActions; | ||
|
|
||
| @end | ||
|
|
||
| NS_ASSUME_NONNULL_END |
127 changes: 127 additions & 0 deletions
127
WebDriverAgentLib/Categories/XCUIElement+FBCustomActions.m
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| /** | ||
| * 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. | ||
| */ | ||
|
|
||
| #import "XCUIElement+FBCustomActions.h" | ||
| #import "XCUIElement+FBUtilities.h" | ||
| #import "FBXCElementSnapshotWrapper+Helpers.h" | ||
| #import "FBLogger.h" | ||
| #import "FBConfiguration.h" | ||
| #import "XCTestPrivateSymbols.h" | ||
|
|
||
| @interface FBXCElementSnapshotWrapper (FBCustomActionsInternal) | ||
|
|
||
| - (NSString *)fb_stringAttribute:(NSString *)attributeName | ||
| symbol:(NSNumber *)symbol; | ||
|
|
||
| @end | ||
|
|
||
| @implementation XCUIElement (FBCustomActions) | ||
|
|
||
| - (NSString *)fb_customActions | ||
| { | ||
| @autoreleasepool { | ||
| id<FBXCElementSnapshot> snapshot = [self fb_standardSnapshot]; | ||
| return [[FBXCElementSnapshotWrapper ensureWrapped:snapshot] | ||
| fb_customActions]; | ||
| } | ||
| } | ||
|
|
||
| @end | ||
|
|
||
|
|
||
| @implementation FBXCElementSnapshotWrapper(FBCustomActions) | ||
|
|
||
| - (NSString *)fb_customActions | ||
| { | ||
| return [self fb_stringAttribute:FB_XCAXACustomActionsAttributeName | ||
| symbol:FB_XCAXACustomActionsAttribute]; | ||
| } | ||
|
|
||
| - (NSString *)fb_stringAttribute:(NSString *)attributeName | ||
| symbol:(NSNumber *)symbol | ||
| { | ||
| id cached = (self.snapshot.additionalAttributes ?: @{})[symbol]; | ||
| if ([cached isKindOfClass:[NSString class]]) { | ||
| return cached; | ||
| } | ||
|
|
||
| NSError *error = nil; | ||
| id raw = [self fb_attributeValue:attributeName error:&error]; | ||
| if (raw == nil) { | ||
| [FBLogger logFmt: @"[FBCustomActions] Cannot determine string value for %@: %@", | ||
| attributeName, error.localizedDescription]; | ||
| return nil; | ||
| } | ||
|
|
||
| // Case 1: Already a string | ||
| if ([raw isKindOfClass:[NSString class]]) { | ||
| return [self retrieveCustomActionsFromString:raw forSymbol:symbol]; | ||
| } | ||
|
|
||
| // Case 2: Array of custom actions | ||
| if ([raw isKindOfClass:[NSArray class]]) { | ||
| return [self retrieveCustomActionsFromArray:raw forSymbol:symbol]; | ||
| } | ||
|
|
||
| // Fallback: Try to cast to string | ||
| return [self retrieveCustomActionsByCastingToString:raw forSymbol:symbol]; | ||
| } | ||
|
|
||
| - (NSString *)retrieveCustomActionsFromString:(NSString *)stringValue | ||
| forSymbol:(NSNumber *)symbol | ||
| { | ||
| NSMutableDictionary *updated = | ||
| (self.additionalAttributes ?: @{}).mutableCopy; | ||
| updated[symbol] = stringValue; | ||
| self.snapshot.additionalAttributes = updated.copy; | ||
| return stringValue; | ||
| } | ||
|
|
||
| - (NSString *)retrieveCustomActionsFromArray:(NSArray *)arrayValue | ||
| forSymbol:(NSNumber *)symbol | ||
| { | ||
| NSMutableArray *stringified = [NSMutableArray array]; | ||
| for (id action in arrayValue) { | ||
| NSString *title = nil; | ||
|
|
||
| if ([action isKindOfClass:[NSDictionary class]]) { | ||
| title = ((NSDictionary *)action)[@"CustomActionName"]; | ||
| } | ||
|
|
||
| if (!title || ![title isKindOfClass:[NSString class]]) { | ||
| @try { | ||
| title = [action valueForKey:@"title"]; | ||
| } @catch (__unused NSException * e) { | ||
| title = @"<unknown>"; | ||
| } | ||
| } | ||
|
|
||
| [stringified addObject:title ?: @"<null>"]; | ||
| [FBLogger logFmt: @"[FBCustomActions] Custom action title: %@", title]; | ||
| } | ||
|
|
||
| NSString *joined = [stringified componentsJoinedByString:@","]; | ||
| NSMutableDictionary *updated = | ||
| (self.additionalAttributes ?: @{}).mutableCopy; | ||
| updated[symbol] = joined; | ||
| self.snapshot.additionalAttributes = updated.copy; | ||
| return joined; | ||
| } | ||
|
|
||
| - (NSString *)retrieveCustomActionsByCastingToString:(id)raw | ||
| forSymbol:(NSNumber *)symbol | ||
| { | ||
| NSString *stringValue = [NSString stringWithFormat:@"%@", raw]; | ||
| NSMutableDictionary *updated = | ||
| (self.additionalAttributes ?: @{}).mutableCopy; | ||
| updated[symbol] = stringValue; | ||
| self.snapshot.additionalAttributes = updated.copy; | ||
| return stringValue; | ||
| } | ||
|
|
||
| @end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.