From 30906692e44f97e632b7a2590d0ec57ff869abe6 Mon Sep 17 00:00:00 2001 From: Yuri Schimke Date: Fri, 22 Nov 2024 10:02:50 +0000 Subject: [PATCH] Update screenshot testing library to add accessibility checks Updated Roborazzi and added accessibility checks to screenshot tests. This will help ensure that our UI is accessible to all users. Currently only fails on ERROR level. --- core/screenshot-testing/build.gradle.kts | 1 + .../core/testing/util/ScreenshotHelper.kt | 17 +++++++++++++++++ gradle/libs.versions.toml | 5 +++-- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/core/screenshot-testing/build.gradle.kts b/core/screenshot-testing/build.gradle.kts index 794416ba9..57a43a200 100644 --- a/core/screenshot-testing/build.gradle.kts +++ b/core/screenshot-testing/build.gradle.kts @@ -26,6 +26,7 @@ android { dependencies { api(libs.bundles.androidx.compose.ui.test) api(libs.roborazzi) + api(libs.roborazzi.accessibility.check) implementation(libs.androidx.compose.ui.test) implementation(libs.androidx.activity.compose) implementation(libs.robolectric) diff --git a/core/screenshot-testing/src/main/kotlin/com/google/samples/apps/nowinandroid/core/testing/util/ScreenshotHelper.kt b/core/screenshot-testing/src/main/kotlin/com/google/samples/apps/nowinandroid/core/testing/util/ScreenshotHelper.kt index f11651220..dbe286673 100644 --- a/core/screenshot-testing/src/main/kotlin/com/google/samples/apps/nowinandroid/core/testing/util/ScreenshotHelper.kt +++ b/core/screenshot-testing/src/main/kotlin/com/google/samples/apps/nowinandroid/core/testing/util/ScreenshotHelper.kt @@ -14,6 +14,8 @@ * limitations under the License. */ +@file:OptIn(ExperimentalRoborazziApi::class) + package com.google.samples.apps.nowinandroid.core.testing.util import androidx.activity.ComponentActivity @@ -30,10 +32,16 @@ import androidx.compose.ui.test.DeviceConfigurationOverride import androidx.compose.ui.test.junit4.AndroidComposeTestRule import androidx.compose.ui.test.onRoot import androidx.test.ext.junit.rules.ActivityScenarioRule +import com.github.takahirom.roborazzi.ExperimentalRoborazziApi +import com.github.takahirom.roborazzi.RoborazziATFAccessibilityCheckOptions +import com.github.takahirom.roborazzi.RoborazziATFAccessibilityChecker +import com.github.takahirom.roborazzi.RoborazziATFAccessibilityChecker.CheckLevel.Error import com.github.takahirom.roborazzi.RoborazziOptions import com.github.takahirom.roborazzi.RoborazziOptions.CompareOptions import com.github.takahirom.roborazzi.RoborazziOptions.RecordOptions import com.github.takahirom.roborazzi.captureRoboImage +import com.github.takahirom.roborazzi.checkRoboAccessibility +import com.google.android.apps.common.testing.accessibility.framework.AccessibilityCheckPreset import com.google.samples.apps.nowinandroid.core.designsystem.theme.NiaTheme import org.robolectric.RuntimeEnvironment @@ -50,6 +58,7 @@ enum class DefaultTestDevices(val description: String, val spec: String) { FOLDABLE("foldable", "spec:shape=Normal,width=673,height=841,unit=dp,dpi=480"), TABLET("tablet", "spec:shape=Normal,width=1280,height=800,unit=dp,dpi=480"), } + fun AndroidComposeTestRule, A>.captureMultiDevice( screenshotName: String, body: @Composable () -> Unit, @@ -88,6 +97,14 @@ fun AndroidComposeTestRule, A>.c "src/test/screenshots/${screenshotName}_$deviceName.png", roborazziOptions = roborazziOptions, ) + this.onRoot().checkRoboAccessibility( + roborazziATFAccessibilityCheckOptions = RoborazziATFAccessibilityCheckOptions( + failureLevel = Error, + checker = RoborazziATFAccessibilityChecker( + preset = AccessibilityCheckPreset.LATEST, + ), + ), + ) } /** diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 07076ca7d..f2c0bedb2 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -50,8 +50,8 @@ protobuf = "4.26.1" protobufPlugin = "0.9.4" retrofit = "2.11.0" retrofitKotlinxSerializationJson = "1.0.0" -robolectric = "4.14" -roborazzi = "1.32.2" +robolectric = "4.14.1" +roborazzi = "1.33.0" room = "2.6.1" secrets = "2.0.1" truth = "1.4.2" @@ -141,6 +141,7 @@ retrofit-core = { group = "com.squareup.retrofit2", name = "retrofit", version.r retrofit-kotlin-serialization = { group = "com.squareup.retrofit2", name = "converter-kotlinx-serialization", version.ref = "retrofit" } robolectric = { group = "org.robolectric", name = "robolectric", version.ref = "robolectric" } roborazzi = { group = "io.github.takahirom.roborazzi", name = "roborazzi", version.ref = "roborazzi" } +roborazzi-accessibility-check = { group = "io.github.takahirom.roborazzi", name = "roborazzi-accessibility-check", version.ref = "roborazzi" } room-compiler = { group = "androidx.room", name = "room-compiler", version.ref = "room" } room-ktx = { group = "androidx.room", name = "room-ktx", version.ref = "room" } room-runtime = { group = "androidx.room", name = "room-runtime", version.ref = "room" }