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

Run accessibility checks after each screenshot #575

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

yschimke
Copy link
Contributor

@yschimke yschimke commented Nov 23, 2024

This commit introduces the ability to run accessibility checks after each screenshot is taken by Roborazzi. This is achieved by adding a new accessibility check strategy, AccessibilityCheckEachScreenshotStrategy, which is used by the RoborazziRule.

Additionally, the captureAndroidView and captureComposeNode functions have been updated to accept an onEach callback, which is invoked after each screenshot is taken. This callback can be used to perform any necessary actions, such as running accessibility checks.

Finally the checks are changed to only run when roborazzi is enabled and will be skipped completely if roborazzi is not running.

partial fix for #567

This commit introduces the ability to run accessibility checks after each screenshot is taken by Roborazzi. This is achieved by adding a new accessibility check strategy, `AccessibilityCheckEachScreenshotStrategy`, which is used by the `RoborazziRule`.

Additionally, the `captureAndroidView` and `captureComposeNode` functions have been updated to accept an `onEach` callback, which is invoked after each screenshot is taken. This callback can be used to perform any necessary actions, such as running accessibility checks.

Finally the checks are changed to only run when roborazzi is
enabled and will be skipped completely if roborazzi is not running.
@takahirom
Copy link
Owner

Thanks.
This change might conflict with this PR. I'm still not sure if separating the stable constructor is a good approach. Do you have any thoughts on this? I would prefer to merge this first so we can determine if the change is treated as Experimental.
https://github.com/takahirom/roborazzi/pull/566/files#diff-0bb7b68fe285cb6875132e144fbb4d226a3f35ff5525cd14d6c627f1389b5999R62-R63

@yschimke
Copy link
Contributor Author

Which one do you want to merge first?

Your call. I'll rebase later today and as necessary.

@yschimke
Copy link
Contributor Author

It would be good to avoid duplicate warnings, so in a follow up I might add some way to log only once for duplicate warning.

Copy link

Snapshot diff report

File name Image
com.github.takahirom
.roborazzi.sample.Co
mposeA11yAfterScreen
shotTest.takesScreen
shots_2_compare.png
com.github.takahirom
.roborazzi.sample.Co
mposeA11yTest.smallC
lickable_compare.png
com.github.takahirom
.roborazzi.sample.Vi
ewA11yTest.checkRobo
AccessibilityCheck_c
ompare.png
com.github.takahirom
.roborazzi.sample.Co
mposeA11yTest.wrongA
pi_compare.png
com.github.takahirom
.roborazzi.sample.Co
mposeA11yTest.faintT
ext_compare.png
com.github.takahirom
.roborazzi.sample.Co
mposeA11yTest.clicka
bleBox_compare.png
com.github.takahirom
.roborazzi.sample.Vi
ewA11yTest.normalTex
t_compare.png
com.github.takahirom
.roborazzi.sample.Co
mposeA11yAfterScreen
shotTest.takesScreen
shots_compare.png
com.github.takahirom
.roborazzi.sample.Co
mposeA11yWithCustomC
heckTest.redText_com
pare.png
com.github.takahirom
.roborazzi.sample.Co
mposeA11yTest.notNat
ive_compare.png
com.github.takahirom
.roborazzi.sample.Vi
ewA11yTest.smallClic
kable_compare.png
com.github.takahirom
.roborazzi.sample.Co
mposeA11yTest.compos
ableOnly_compare.png
com.github.takahirom
.roborazzi.sample.Co
mposeA11yAfterScreen
shotTest.takesScreen
shots_3_compare.png
com.github.takahirom
.roborazzi.sample.Co
mposeA11yWithCustomC
heckTest.normalText_
compare.png
com.github.takahirom
.roborazzi.sample.Co
mposeA11yTest.supres
sionsTakeEffect_comp
are.png
com.github.takahirom
.roborazzi.sample.Vi
ewA11yTest.clickable
WithoutSemantics_com
pare.png
com.github.takahirom
.roborazzi.sample.Co
mposeA11yTest.clicka
bleWithoutSemantics_
compare.png
com.github.takahirom
.roborazzi.sample.Vi
ewA11yTest.faintText
_compare.png
com.github.takahirom
.roborazzi.sample.Vi
ewA11yTest.supressio
nsTakeEffect_compare
.png
com.github.takahirom
.roborazzi.sample.Co
mposeA11yTest.boxWit
hEmptyContentDescrip
tion_compare.png
com.github.takahirom
.roborazzi.sample.Vi
ewA11yTest.clickable
Box_compare.png
com.github.takahirom
.roborazzi.sample.Co
mposeA11yTest.normal
Text_compare.png

Copy link
Owner

@takahirom takahirom left a comment

Choose a reason for hiding this comment

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

Thank you for your pull request! Most parts look good.
Could you fix the conflict?

# Conflicts:
#	sample-android/src/test/java/com/github/takahirom/roborazzi/sample/ComposeA11yWithCustomCheckTest.kt
@yschimke yschimke marked this pull request as draft November 24, 2024 10:30
@yschimke yschimke marked this pull request as ready for review November 24, 2024 10:38
@@ -273,3 +275,26 @@ data class AccessibilityCheckAfterTestStrategy(
)
}
}

@ExperimentalRoborazziApi
data class AccessibilityCheckEachScreenshotStrategy(
Copy link
Owner

Choose a reason for hiding this comment

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

Thanks. I have a question about the current implementation.
I haven't read the code thoroughly. The AccessibilityCheckEachScreenshotStrategy is only for RoborazziRule.Options.captureRule and not for captureRoboImage(), right?
I believe that if we provide the RoborazziContext, we can check every captureRoboImage. Do you have any thoughts on this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm happy to take your advice, I'm not as familiar with all the different APIs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Really the intention is to run when roborazzi produces distinct screenshots.

From

  • once per test
  • per screenshot
  • none (roborazzi or a11y checks not enabled)

What gets us closer to that?

Copy link
Owner

Choose a reason for hiding this comment

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

I think we can add ruleAccessibilityCheckStrategy and use it in captureRoboImage() like provideRoborazziContext().accessibilityCheckStrategy.afterScreenshot() to check the accessibility of each screenshot now that you added onEach{}.

77fa9dc#diff-84240ff001c21726c87098748f05f02f55cb70b8425874729662bc07ad8786ecR66

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should I move that type from rule to core module?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This feels like a big change I won't get to until next weekend.

Options

  • I'll take a look and make changes then
  • feel free to make the changes yourself before then
  • I can remove that screenshot mode, and just land the other changes for now

No rush, just letting you know where I am

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I started to make the change and noticed some are already there. I'm unclear if you made all the changes already?

But for RoboComponent, what to do about Screen? Since it has multiple roots?

Copy link
Owner

Choose a reason for hiding this comment

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

I'm not sure, but can we conduct checks for each root? I don't have a good idea for that, but it might work.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Or just the top window?

Copy link
Owner

Choose a reason for hiding this comment

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

Sounds good. We could output logs like:
"Roborazzi: It seems we have multiple windows, so we'll check accessibility for the top window only."

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.

2 participants