Skip to content
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

Add accessibility identifier in AccessibilityMarker #228

Merged
merged 1 commit into from
Nov 21, 2024

Conversation

priip
Copy link
Collaborator

@priip priip commented Nov 20, 2024

Adds a new identifier property to the AccessibilityMarker object which stores the accessibilityIdentifier for an element. This unique identifier can be used for identifying elements in UITests and is not visible to users.

@priip priip marked this pull request as draft November 20, 2024 16:45
@priip priip force-pushed the priip/add-identifier-in-accessibility-marker branch from dcb06e4 to 1e86122 Compare November 20, 2024 16:46
@priip priip self-assigned this Nov 20, 2024
@priip priip marked this pull request as ready for review November 20, 2024 16:52
Comment on lines 751 to 788
var identifier: String? {
if let accessibilityIdentifier = value(forKey: "accessibilityIdentifier") as? String {
return accessibilityIdentifier
}
return nil
}
Copy link
Collaborator Author

@priip priip Nov 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no "clean" way to access the accessibilityIdentifier for an NSObject, since it's only available for objects that conform to UIAccessibilityIdentification (doc) I tried using the accessibilityIdentifierBlock (doc), but that yielded no results, so I've opted to pull the value using key values. I'm open to suggestions though if ya'll have any!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would the following work?

if let typedSelf = self as? UIAccessibilityIdentification {
    return typedSelf.accessibilityIdentifier
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried this, but it was not triggering any of the UIKIt views.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh, okay yes I vaguely remember now having a discussion with @RoyalPineapple about something very similar. I forget the context, but perhaps he can recall what he ended up doing here.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the solution here of testing for known conformance before using the key/value as a fallback works well enough. This bug is frustrating every time it comes up.

@priip priip force-pushed the priip/add-identifier-in-accessibility-marker branch from 1e86122 to 24b20ed Compare November 21, 2024 15:01
@@ -714,7 +720,7 @@ extension UIView {
fileprivate extension NSObject {
var customContent: [(label: String, value: String, isImportant:Bool)] {
// Github runs tests on specific iOS versions against specific versions of Xcode in CI.
// Forward deployment on old versions of Xcode require a compile time check which require diferentiation by swift version rather than iOS SDK.
// Forward deployment on old versions of Xcode require a compile time check which require differentiation by swift version rather than iOS SDK.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks 👍🏻

@priip priip merged commit bc3d41b into master Nov 21, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants