Skip to content

Commit

Permalink
Update screenshot testing library to add accessibility checks
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
yschimke committed Nov 22, 2024
1 parent 1c2fe16 commit 3090669
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions core/screenshot-testing/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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,
Expand Down Expand Up @@ -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,
),
),
)
}

/**
Expand Down
5 changes: 3 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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" }
Expand Down

0 comments on commit 3090669

Please sign in to comment.