cashapp / AccessibilitySnapshot

Easy regression testing for iOS accessibility
Apache License 2.0
554 stars 69 forks source link

Sort ordering does not match VoiceOver order #221

Open g-mark opened 3 months ago

g-mark commented 3 months ago

A difference in accessibility snapshots was noticed when one of two side by side items changed from providing an outdented acessibilityPath to just using the default accessibilityFrame.

Further investigation found that the AccessibilityHierarchyParser has two potential issues with how elements are ordered in comparison with how VoiceOver works.

  1. The ordering of elements is based on either the accessibilityPath (if not nil) or the accessibilityFrame. VoiceOver seems to always use the accessibilityFrame.
  2. The vertical y comparison of elements uses a strict != comparison, whereas VoiceOver has about a ± 7 pt "roughly equal to" comparison.
This view controller shows some UILabels where one provides a custom accessibilityFrame, and another an accessibilityPath - each insets the view's frame by a different amount. Below is the VoiceOver focus order as seen by the Accessibility Inspector. Header "Lorem ipsum" label "frame" label "path" label
image image image image

In the snapshot image, however the order is: Header, "path" label, "frame" label, then "Lorem ipsum" label. image

Sample project: AccessibilityElementOrder.zip