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

RoborazziATFAccessibilityCheckOptions - Configuring supression results to an error #613

Open
aileene-willow opened this issue Dec 18, 2024 · 3 comments

Comments

@aileene-willow
Copy link

Using this configuration

roborazziAccessibilityOptions = RoborazziATFAccessibilityCheckOptions( RoborazziATFAccessibilityChecker( preset = AccessibilityCheckPreset.LATEST, suppressions = matchesElements(withTestTag("suppress")) ), failureLevel = RoborazziATFAccessibilityChecker.CheckLevel.Error )

returns this error:

Argument type mismatch: actual type is 'com.android.layoutlib.hamcrest.Matcher<com.google.android.apps.common.testing.accessibility.framework.AccessibilityViewCheckResult!>!', but 'org.hamcrest.Matcher' was expected.

@takahirom
Copy link
Owner

takahirom commented Dec 18, 2024

Thank you for reporting this. Could you clarify which import you are using for matchesElements and withTestTag?

I believe the correct imports should be:

  • com.google.android.apps.common.testing.accessibility.framework.AccessibilityCheckResultUtils.matchesElements
  • com.google.android.apps.common.testing.accessibility.framework.matcher.ElementMatchers.withTestTag

@aileene-willow
Copy link
Author

aileene-willow commented Dec 18, 2024

Hi @takahiromThank you for checking/. I just looked and I am using those imports. This is my full configuration:

import androidx.compose.ui.test.junit4.AndroidComposeTestRule
import androidx.compose.ui.test.onRoot
import com.dropbox.differ.SimpleImageComparator
import com.github.takahirom.roborazzi.AccessibilityCheckAfterTestStrategy
import com.github.takahirom.roborazzi.ExperimentalRoborazziApi
import com.github.takahirom.roborazzi.RoborazziATFAccessibilityCheckOptions
import com.github.takahirom.roborazzi.RoborazziATFAccessibilityChecker
import com.github.takahirom.roborazzi.RoborazziOptions
import com.github.takahirom.roborazzi.RoborazziRule
import com.google.android.apps.common.testing.accessibility.framework.AccessibilityCheckPreset
import com.google.android.apps.common.testing.accessibility.framework.AccessibilityCheckResultUtils.matchesElements
import com.google.android.apps.common.testing.accessibility.framework.matcher.ElementMatchers.withTestTag

@OptIn(ExperimentalRoborazziApi::class)
fun tmoRoborazziRule(
    // captureImage is not used for tests of pop-up modals
    composeTestRule: AndroidComposeTestRule<*, *>,
    captureImage: Boolean = true,
): RoborazziRule {
    return RoborazziRule(
        composeRule = composeTestRule,
        captureRoot = composeTestRule.onRoot(),
        options = RoborazziRule.Options(
            // Accessibility check options is only supported for SDK 34 and higher

            roborazziAccessibilityOptions = RoborazziATFAccessibilityCheckOptions(
                RoborazziATFAccessibilityChecker(
                    preset = AccessibilityCheckPreset.LATEST,


                   suppressions = matchesElements(withTestTag("suppress"))

                ),
                failureLevel = RoborazziATFAccessibilityChecker.CheckLevel.Error
            ),
            accessibilityCheckStrategy = AccessibilityCheckAfterTestStrategy(),
            outputDirectoryPath = "./src/test/roborazzi/images",
            captureType = if (captureImage) RoborazziRule.CaptureType.LastImage() else RoborazziRule.CaptureType.None,
            roborazziOptions = RoborazziOptions(
                compareOptions = RoborazziOptions.CompareOptions(
                    imageComparator = SimpleImageComparator(maxDistance = 0.014F, hShift = 1)
                )
            )
        ),
    )
}

@takahirom
Copy link
Owner

takahirom commented Dec 18, 2024

Thanks. Could you check the version of the accessibility framework? The code works in Roborazzi, which seems to use com.google.android.apps.common.testing.accessibility.framework:accessibility-test-framework:4.1.1.

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

No branches or pull requests

2 participants