google / Accessibility-Test-Framework-for-Android

Accessibility checks for automated Android testing
Apache License 2.0
454 stars 129 forks source link

Jetpack compose compatibility #40

Open sagix opened 2 years ago

sagix commented 2 years ago

This library works perfectly with a View based application.

But, not at all with jetpack compose.

Is there any plan to support it?

nishanth043 commented 1 year ago

+1 on this. I can only run these checks on a Jetpack Compose rootView. But when I run it, I only get suggestions for the rootView of the screen and it does not go through all the child Composables like it would on a view based application.

But, I see that the "Accessibility Scanner" app somehow gives me correct results on Compose screens as well.

Could you please give some guidance on how to run the checks in the repo on Compose screens? Any documentation on this would help greatly.

foster55ff commented 1 year ago

I have the same Question. Are there any plans to support Jetpack Compose with this tool?

oknirb commented 1 year ago

When ATF is used within an Espresso test, it is not possible for it to inspect Compose content from using the currently released versions. However, API 34 adds new functionality that will make this feasible.

yschimke commented 10 months ago

I assume this, so devices and emulators, but not robolectric?

https://github.com/google/Accessibility-Test-Framework-for-Android/blob/858625c4d9ad2acddee5cfbc1dedd54c76da9365/src/main/java/com/google/android/apps/common/testing/accessibility/framework/uielement/AccessibilityHierarchyAndroid.java#L644

    public AccessibilityHierarchyAndroid build() {
      AccessibilityHierarchyAndroid result;
      if (fromRootView != null) {
        if (BuildCompat.isAtLeastU() && !isRobolectric()) {
          result =
              buildHierarchyFromViewAndItsNodeInfo(
                  fromRootView, getAccessibilityNodeInfoExtraDataExtractor());
        } else {
          result =
              buildHierarchyFromView(fromRootView, getAccessibilityNodeInfoExtraDataExtractor());
        }
oknirb commented 10 months ago

That's correct. The Nov 2023 commit added support for UIs containing Compose content when running with Android 10 (API 34), but not on Robolectric.

It also added ElementMatchers (similar to Espresso's ViewMatchers) and matchesElements to support matching AccessibilityViewCheckResults with ViewHierarchyElements that are not from Views.

This is still a work in progress.

yschimke commented 10 months ago

Specifically for Robolectric, is the bulk of the technical work in robolectric or ATF?

bassettsj commented 7 months ago

Wanted to follow up here asking what is the scope of work to enable support for ATF?

It has been a big blocker for us at Airbnb to enable accessibility checks for our Jetpack Compose components and would love to find a solution if possible.

LachlanMcKee commented 4 months ago

Google mentioned in this video that they added support for Compose into this library, but I don't see any updates in the project to suggest this is the case

https://youtu.be/qLCK0HO_tNQ?t=786

oknirb commented 4 months ago

If you run the ATF checks on a View that contains Composable content (which can be a ComposeView), then they may detect accessibility issues, but only on API 34+. And not in Robolectric tests.

If you look at AccessibilityValidator.java you will see a new method buildHierarchyFromViewAndItsNodeInfo that provides this support.

Accessibility Scanner works with Compose. ATF checks can run on Compose content in Android Studio. Espresso accessibility and Play Store Developer Console’s Pre Launch Report can detect accessibility issues in Compose content when run on Android U. Also, the help content for Accessibility Scanner results (to which the ATF results reference) has been updated to specifically address Compose.

At the moment, there is no convenient way to instrument pure Compose tests, but we've heard ample feedback on this and are considering how ATF can best support this type of usage.