-
Notifications
You must be signed in to change notification settings - Fork 38
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 basic ATF A11y checks via AccessibilityCheckAfterTestStrategy and checkRoboAccessibility #557
Conversation
Run ATF after test completes to check for A11y issues.
...d/roborazzi-core/src/commonJvmMain/kotlin/com/github/takahirom/roborazzi/RoborazziOptions.kt
Outdated
Show resolved
Hide resolved
Let me update this branch to check the screenshot differences, as Robolectric has been updated in the main branch. |
I don't fully understand what has been done in this pull request yet. I'll take a look tomorrow.🙏 |
There are multiple ways to achieve this, depending on the end goals.
I started at 2, then moved to 3, then ended up at 4. Firstly, I think we should aim to make this part of most developers toolkit. But with 2 or 3 it's hard to override the checks, suppressions, how screenshots are taken. I think it ended up quite clean but also flexible. |
I think robolectric 4.14 produces a lot of small diffs. Improvements, but also differences in font handling. |
One small example that shows the benefit of this. The stdout for each test shows the errors and warnings notices for checks. So we could have a Log mode and raise awareness in existing tests |
AccessibilityCheckResultType.ERROR -> System.err.println("Error: $check") | ||
AccessibilityCheckResultType.WARNING -> System.err.println( | ||
"Warning: $check" | ||
) | ||
|
||
AccessibilityCheckResultType.INFO -> println( | ||
"Info: $check" | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📝
Error: [AccessibilityViewCheckResult check=AccessibilityHierarchyCheckResult ERROR SpeakableTextPresentCheck 4 [ViewHierarchyElement class=android.view.View bounds=Rect(474, 1074 - 606, 1206)] null num_answers:0 view=null]
Warning: [AccessibilityViewCheckResult check=AccessibilityHierarchyCheckResult WARNING TextContrastCheck 11 [ViewHierarchyElement class=android.widget.TextView text=Something hard to read bounds=Rect(403, 1002 - 678, 1092)] {KEY_BACKGROUND_COLOR=-12303292, KEY_CONTRAST_RATIO=1.02, KEY_FOREGROUND_COLOR=-12369085, KEY_REQUIRED_CONTRAST_RATIO=3.0} num_answers:0 view=null]
Error: [AccessibilityViewCheckResult check=AccessibilityHierarchyCheckResult ERROR SpeakableTextPresentCheck 4 [ViewHierarchyElement class=android.view.View bounds=Rect(474, 1074 - 606, 1206)] null num_answers:0 view=null]
Looks like a good compromise. Ideally this would be on for everyone. This is a great way to make it accessible (pun intended). I'd like to make the errors visual in future, but this can presumably be done with a similar approach of an optional overlay for screenshots? |
…essibility-check/2024-11-17 Takahirom/separate roborazzi accessibility check/2024 11 17
Slight refactor and added a README |
|
} else if (captureRoot is CaptureRoot.View) { | ||
val viewInteraction = captureRoot.viewInteraction | ||
// Use perform to get the view | ||
viewInteraction.perform(object : ViewAction { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added View support by using perform(). 👀
...-accessibility-check/src/main/java/com/github/takahirom/roborazzi/ATFAccessibilityChecker.kt
Outdated
Show resolved
Hide resolved
@RunWith(AndroidJUnit4::class) | ||
@GraphicsMode(GraphicsMode.Mode.NATIVE) | ||
@Config(qualifiers = RobolectricDeviceQualifiers.Pixel4, sdk = [35]) | ||
class ViewA11yTest { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added a test for Android View. 👀
roborazzi-junit-rule/src/main/java/com/github/takahirom/roborazzi/RoborazziRule.kt
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Thank you for your contribution. I have a quick question.
...-accessibility-check/src/main/java/com/github/takahirom/roborazzi/ATFAccessibilityChecker.kt
Outdated
Show resolved
Hide resolved
707f4a4
to
ef6a265
Compare
@takahirom looks great! I think I successfully nerdsniped you into building the feature I wanted but didn't know how to build. :) |
Thanks! Accessibility is important, and I noticed you wrote a test using a custom check. It made me think that we could also make our apps more accessible for AI agents to further improve their quality, such as by adding content descriptions for image buttons or other elements that agents might need to interact with. I believe this could also be good preparation for AI agent testing. |
The intent was to prove it's possible and demystify this. |
Run ATF after test completes to check for A11y issues.
Future possible changes
or