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.
pull/1708/head
Yuri Schimke 1 month ago
parent 1c2fe163a0
commit 30906692e4

@ -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)

@ -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 <A : ComponentActivity> AndroidComposeTestRule<ActivityScenarioRule<A>, A>.captureMultiDevice(
screenshotName: String,
body: @Composable () -> Unit,
@ -88,6 +97,14 @@ fun <A : ComponentActivity> AndroidComposeTestRule<ActivityScenarioRule<A>, A>.c
"src/test/screenshots/${screenshotName}_$deviceName.png",
roborazziOptions = roborazziOptions,
)
this.onRoot().checkRoboAccessibility(
roborazziATFAccessibilityCheckOptions = RoborazziATFAccessibilityCheckOptions(
failureLevel = Error,
checker = RoborazziATFAccessibilityChecker(
preset = AccessibilityCheckPreset.LATEST,
),
),
)
}
/**

@ -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" }

Loading…
Cancel
Save