From 30906692e44f97e632b7a2590d0ec57ff869abe6 Mon Sep 17 00:00:00 2001 From: Yuri Schimke Date: Fri, 22 Nov 2024 10:02:50 +0000 Subject: [PATCH 1/8] 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" } From 6f3894a91b081ea7c54aaf0be3b23e1bc5bd063f Mon Sep 17 00:00:00 2001 From: Yuri Schimke Date: Fri, 22 Nov 2024 11:33:53 +0000 Subject: [PATCH 2/8] Update ScreenshotHelper.kt --- .../apps/nowinandroid/core/testing/util/ScreenshotHelper.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 dbe286673..71f49cbc0 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 @@ -35,7 +35,7 @@ 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.RoborazziATFAccessibilityChecker.CheckLevel import com.github.takahirom.roborazzi.RoborazziOptions import com.github.takahirom.roborazzi.RoborazziOptions.CompareOptions import com.github.takahirom.roborazzi.RoborazziOptions.RecordOptions @@ -99,7 +99,7 @@ fun AndroidComposeTestRule, A>.c ) this.onRoot().checkRoboAccessibility( roborazziATFAccessibilityCheckOptions = RoborazziATFAccessibilityCheckOptions( - failureLevel = Error, + failureLevel = CheckLevel.Warning, checker = RoborazziATFAccessibilityChecker( preset = AccessibilityCheckPreset.LATEST, ), From 0849597755395b84809ad24faf2b5a8ad9b10623 Mon Sep 17 00:00:00 2001 From: Yuri Schimke Date: Sat, 23 Nov 2024 06:24:59 +0000 Subject: [PATCH 3/8] Suppress A11y exception for now --- .../core/testing/util/ScreenshotHelper.kt | 11 +++++++-- .../foryou/ForYouScreenScreenshotTests.kt | 23 ++++++++++++++++--- 2 files changed, 29 insertions(+), 5 deletions(-) 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 71f49cbc0..20cb09a6f 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 @@ -31,6 +31,7 @@ import androidx.compose.ui.test.DarkMode import androidx.compose.ui.test.DeviceConfigurationOverride import androidx.compose.ui.test.junit4.AndroidComposeTestRule import androidx.compose.ui.test.onRoot +import androidx.compose.ui.test.printToString import androidx.test.ext.junit.rules.ActivityScenarioRule import com.github.takahirom.roborazzi.ExperimentalRoborazziApi import com.github.takahirom.roborazzi.RoborazziATFAccessibilityCheckOptions @@ -42,7 +43,10 @@ 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.android.apps.common.testing.accessibility.framework.AccessibilityViewCheckResult import com.google.samples.apps.nowinandroid.core.designsystem.theme.NiaTheme +import org.hamcrest.Matcher +import org.hamcrest.Matchers import org.robolectric.RuntimeEnvironment val DefaultRoborazziOptions = @@ -61,10 +65,11 @@ enum class DefaultTestDevices(val description: String, val spec: String) { fun AndroidComposeTestRule, A>.captureMultiDevice( screenshotName: String, + accessibilitySuppressions: Matcher = Matchers.not(Matchers.anything()), body: @Composable () -> Unit, ) { - DefaultTestDevices.entries.forEach { - this.captureForDevice(it.description, it.spec, screenshotName, body = body) + listOf(DefaultTestDevices.FOLDABLE).forEach { + this.captureForDevice(it.description, it.spec, screenshotName, body = body, accessibilitySuppressions = accessibilitySuppressions) } } @@ -73,6 +78,7 @@ fun AndroidComposeTestRule, A>.c deviceSpec: String, screenshotName: String, roborazziOptions: RoborazziOptions = DefaultRoborazziOptions, + accessibilitySuppressions: Matcher = Matchers.not(Matchers.anything()), darkMode: Boolean = false, body: @Composable () -> Unit, ) { @@ -102,6 +108,7 @@ fun AndroidComposeTestRule, A>.c failureLevel = CheckLevel.Warning, checker = RoborazziATFAccessibilityChecker( preset = AccessibilityCheckPreset.LATEST, + suppressions = accessibilitySuppressions ), ), ) diff --git a/feature/foryou/src/test/kotlin/com/google/samples/apps/nowinandroid/feature/foryou/ForYouScreenScreenshotTests.kt b/feature/foryou/src/test/kotlin/com/google/samples/apps/nowinandroid/feature/foryou/ForYouScreenScreenshotTests.kt index 14b67c64e..243e25263 100644 --- a/feature/foryou/src/test/kotlin/com/google/samples/apps/nowinandroid/feature/foryou/ForYouScreenScreenshotTests.kt +++ b/feature/foryou/src/test/kotlin/com/google/samples/apps/nowinandroid/feature/foryou/ForYouScreenScreenshotTests.kt @@ -19,6 +19,10 @@ package com.google.samples.apps.nowinandroid.feature.foryou import androidx.activity.ComponentActivity import androidx.compose.runtime.Composable import androidx.compose.ui.test.junit4.createAndroidComposeRule +import com.google.android.apps.common.testing.accessibility.framework.AccessibilityCheckResultUtils +import com.google.android.apps.common.testing.accessibility.framework.AccessibilityCheckResultUtils.matchesElements +import com.google.android.apps.common.testing.accessibility.framework.checks.TextContrastCheck +import com.google.android.apps.common.testing.accessibility.framework.matcher.ElementMatchers.withText import com.google.samples.apps.nowinandroid.core.designsystem.component.NiaBackground import com.google.samples.apps.nowinandroid.core.designsystem.theme.NiaTheme import com.google.samples.apps.nowinandroid.core.testing.util.DefaultTestDevices @@ -31,6 +35,7 @@ import com.google.samples.apps.nowinandroid.feature.foryou.OnboardingUiState.Loa import com.google.samples.apps.nowinandroid.feature.foryou.OnboardingUiState.NotShown import com.google.samples.apps.nowinandroid.feature.foryou.OnboardingUiState.Shown import dagger.hilt.android.testing.HiltTestApplication +import org.hamcrest.Matchers import org.junit.Before import org.junit.Rule import org.junit.Test @@ -53,8 +58,7 @@ class ForYouScreenScreenshotTests { /** * Use a test activity to set the content on. */ - @get:Rule - val composeTestRule = createAndroidComposeRule() + @get:Rule val composeTestRule = createAndroidComposeRule() private val userNewsResources = UserNewsResourcePreviewParameterProvider().values.first() @@ -108,7 +112,20 @@ class ForYouScreenScreenshotTests { @Test fun forYouScreenTopicSelection() { - composeTestRule.captureMultiDevice("ForYouScreenTopicSelection") { + composeTestRule.captureMultiDevice( + "ForYouScreenTopicSelection", + accessibilitySuppressions = Matchers.allOf( + AccessibilityCheckResultUtils.matchesCheck(TextContrastCheck::class.java), + Matchers.anyOf( + // Disabled Button + matchesElements(withText("Done")), + + // TODO investigate, seems a false positive + matchesElements(withText("What are you interested in?")), + matchesElements(withText("UI")), + ), + ), + ) { ForYouScreenTopicSelection() } } From 4f27c18f20fc89971f36fdf6bd2f26eee717ccb7 Mon Sep 17 00:00:00 2001 From: Yuri Schimke Date: Sat, 23 Nov 2024 06:30:30 +0000 Subject: [PATCH 4/8] Change order of exceptions --- .../core/testing/util/ScreenshotHelper.kt | 44 +++++++++++++------ .../foryou/ForYouScreenScreenshotTests.kt | 3 +- 2 files changed, 33 insertions(+), 14 deletions(-) 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 20cb09a6f..89994ac57 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 @@ -31,7 +31,6 @@ import androidx.compose.ui.test.DarkMode import androidx.compose.ui.test.DeviceConfigurationOverride import androidx.compose.ui.test.junit4.AndroidComposeTestRule import androidx.compose.ui.test.onRoot -import androidx.compose.ui.test.printToString import androidx.test.ext.junit.rules.ActivityScenarioRule import com.github.takahirom.roborazzi.ExperimentalRoborazziApi import com.github.takahirom.roborazzi.RoborazziATFAccessibilityCheckOptions @@ -44,6 +43,7 @@ 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.android.apps.common.testing.accessibility.framework.AccessibilityViewCheckResult +import com.google.android.apps.common.testing.accessibility.framework.integrations.espresso.AccessibilityViewCheckException import com.google.samples.apps.nowinandroid.core.designsystem.theme.NiaTheme import org.hamcrest.Matcher import org.hamcrest.Matchers @@ -62,14 +62,19 @@ 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, accessibilitySuppressions: Matcher = Matchers.not(Matchers.anything()), body: @Composable () -> Unit, ) { - listOf(DefaultTestDevices.FOLDABLE).forEach { - this.captureForDevice(it.description, it.spec, screenshotName, body = body, accessibilitySuppressions = accessibilitySuppressions) + DefaultTestDevices.entries.forEach { + this.captureForDevice( + deviceName = it.description, + deviceSpec = it.spec, + screenshotName = screenshotName, + body = body, + accessibilitySuppressions = accessibilitySuppressions, + ) } } @@ -98,20 +103,33 @@ fun AndroidComposeTestRule, A>.c } } } + + // Run Accessibility checks first so logging is included + val accessibilityException = try { + this.onRoot().checkRoboAccessibility( + roborazziATFAccessibilityCheckOptions = RoborazziATFAccessibilityCheckOptions( + failureLevel = CheckLevel.Warning, + checker = RoborazziATFAccessibilityChecker( + preset = AccessibilityCheckPreset.LATEST, + suppressions = accessibilitySuppressions + ), + ), + ) + null + } catch (e: AccessibilityViewCheckException) { + e + } + this.onRoot() .captureRoboImage( "src/test/screenshots/${screenshotName}_$deviceName.png", roborazziOptions = roborazziOptions, ) - this.onRoot().checkRoboAccessibility( - roborazziATFAccessibilityCheckOptions = RoborazziATFAccessibilityCheckOptions( - failureLevel = CheckLevel.Warning, - checker = RoborazziATFAccessibilityChecker( - preset = AccessibilityCheckPreset.LATEST, - suppressions = accessibilitySuppressions - ), - ), - ) + + // Rethrow the Accessibility exception once screenshots have passed + if (accessibilityException != null) { + throw accessibilityException + } } /** diff --git a/feature/foryou/src/test/kotlin/com/google/samples/apps/nowinandroid/feature/foryou/ForYouScreenScreenshotTests.kt b/feature/foryou/src/test/kotlin/com/google/samples/apps/nowinandroid/feature/foryou/ForYouScreenScreenshotTests.kt index 243e25263..29fc6f536 100644 --- a/feature/foryou/src/test/kotlin/com/google/samples/apps/nowinandroid/feature/foryou/ForYouScreenScreenshotTests.kt +++ b/feature/foryou/src/test/kotlin/com/google/samples/apps/nowinandroid/feature/foryou/ForYouScreenScreenshotTests.kt @@ -58,7 +58,8 @@ class ForYouScreenScreenshotTests { /** * Use a test activity to set the content on. */ - @get:Rule val composeTestRule = createAndroidComposeRule() + @get:Rule + val composeTestRule = createAndroidComposeRule() private val userNewsResources = UserNewsResourcePreviewParameterProvider().values.first() From 3e4f66b489218be5f6b18896a53b5d91eccd4860 Mon Sep 17 00:00:00 2001 From: Yuri Schimke Date: Sat, 23 Nov 2024 06:44:49 +0000 Subject: [PATCH 5/8] spotless --- .../core/testing/util/ScreenshotHelper.kt | 17 ++++++++++++++++- .../foryou/ForYouScreenScreenshotTests.kt | 4 ++-- 2 files changed, 18 insertions(+), 3 deletions(-) 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 89994ac57..00c54e909 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 @@ -18,6 +18,7 @@ package com.google.samples.apps.nowinandroid.core.testing.util +import android.graphics.Bitmap.CompressFormat.PNG import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.compose.runtime.Composable @@ -44,10 +45,12 @@ import com.github.takahirom.roborazzi.checkRoboAccessibility import com.google.android.apps.common.testing.accessibility.framework.AccessibilityCheckPreset import com.google.android.apps.common.testing.accessibility.framework.AccessibilityViewCheckResult import com.google.android.apps.common.testing.accessibility.framework.integrations.espresso.AccessibilityViewCheckException +import com.google.android.apps.common.testing.accessibility.framework.utils.contrast.BitmapImage import com.google.samples.apps.nowinandroid.core.designsystem.theme.NiaTheme import org.hamcrest.Matcher import org.hamcrest.Matchers import org.robolectric.RuntimeEnvironment +import java.io.FileOutputStream val DefaultRoborazziOptions = RoborazziOptions( @@ -111,7 +114,7 @@ fun AndroidComposeTestRule, A>.c failureLevel = CheckLevel.Warning, checker = RoborazziATFAccessibilityChecker( preset = AccessibilityCheckPreset.LATEST, - suppressions = accessibilitySuppressions + suppressions = accessibilitySuppressions, ), ), ) @@ -128,6 +131,18 @@ fun AndroidComposeTestRule, A>.c // Rethrow the Accessibility exception once screenshots have passed if (accessibilityException != null) { + accessibilityException.results.forEachIndexed { index, check -> + val viewImage = check.viewImage + if (viewImage is BitmapImage) { + FileOutputStream( + "build/outputs/roborazzi/" + + "${screenshotName}_${deviceName}_$index.png", + ).use { + viewImage.bitmap.compress(PNG, 100, it) + } + } + } + throw accessibilityException } } diff --git a/feature/foryou/src/test/kotlin/com/google/samples/apps/nowinandroid/feature/foryou/ForYouScreenScreenshotTests.kt b/feature/foryou/src/test/kotlin/com/google/samples/apps/nowinandroid/feature/foryou/ForYouScreenScreenshotTests.kt index 29fc6f536..d5e3ca0f1 100644 --- a/feature/foryou/src/test/kotlin/com/google/samples/apps/nowinandroid/feature/foryou/ForYouScreenScreenshotTests.kt +++ b/feature/foryou/src/test/kotlin/com/google/samples/apps/nowinandroid/feature/foryou/ForYouScreenScreenshotTests.kt @@ -122,8 +122,8 @@ class ForYouScreenScreenshotTests { matchesElements(withText("Done")), // TODO investigate, seems a false positive - matchesElements(withText("What are you interested in?")), - matchesElements(withText("UI")), +// matchesElements(withText("What are you interested in?")), +// matchesElements(withText("UI")), ), ), ) { From e77dedf0dcb85c3e33a635d141444e06f7256bf1 Mon Sep 17 00:00:00 2001 From: Yuri Schimke Date: Sat, 23 Nov 2024 06:47:12 +0000 Subject: [PATCH 6/8] logging --- .../apps/nowinandroid/core/testing/util/ScreenshotHelper.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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 00c54e909..cca781725 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 @@ -50,6 +50,7 @@ import com.google.samples.apps.nowinandroid.core.designsystem.theme.NiaTheme import org.hamcrest.Matcher import org.hamcrest.Matchers import org.robolectric.RuntimeEnvironment +import java.io.File import java.io.FileOutputStream val DefaultRoborazziOptions = @@ -134,9 +135,10 @@ fun AndroidComposeTestRule, A>.c accessibilityException.results.forEachIndexed { index, check -> val viewImage = check.viewImage if (viewImage is BitmapImage) { + val file = File("build/outputs/roborazzi/${screenshotName}_${deviceName}_$index.png") + println("Writing check.viewImage to $file") FileOutputStream( - "build/outputs/roborazzi/" + - "${screenshotName}_${deviceName}_$index.png", + file, ).use { viewImage.bitmap.compress(PNG, 100, it) } From 2415239d456ad84357a67df3031adbac4f32be05 Mon Sep 17 00:00:00 2001 From: Yuri Schimke Date: Sat, 23 Nov 2024 06:59:45 +0000 Subject: [PATCH 7/8] suppress checks --- .../feature/foryou/ForYouScreenScreenshotTests.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/feature/foryou/src/test/kotlin/com/google/samples/apps/nowinandroid/feature/foryou/ForYouScreenScreenshotTests.kt b/feature/foryou/src/test/kotlin/com/google/samples/apps/nowinandroid/feature/foryou/ForYouScreenScreenshotTests.kt index d5e3ca0f1..29fc6f536 100644 --- a/feature/foryou/src/test/kotlin/com/google/samples/apps/nowinandroid/feature/foryou/ForYouScreenScreenshotTests.kt +++ b/feature/foryou/src/test/kotlin/com/google/samples/apps/nowinandroid/feature/foryou/ForYouScreenScreenshotTests.kt @@ -122,8 +122,8 @@ class ForYouScreenScreenshotTests { matchesElements(withText("Done")), // TODO investigate, seems a false positive -// matchesElements(withText("What are you interested in?")), -// matchesElements(withText("UI")), + matchesElements(withText("What are you interested in?")), + matchesElements(withText("UI")), ), ), ) { From 92c5d4b068aad54d2e94dffdc619a92ddf8ce9af Mon Sep 17 00:00:00 2001 From: Yuri Schimke Date: Sat, 23 Nov 2024 07:02:46 +0000 Subject: [PATCH 8/8] reduce for now --- .../apps/nowinandroid/core/testing/util/ScreenshotHelper.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 cca781725..20b9a5deb 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 @@ -112,7 +112,7 @@ fun AndroidComposeTestRule, A>.c val accessibilityException = try { this.onRoot().checkRoboAccessibility( roborazziATFAccessibilityCheckOptions = RoborazziATFAccessibilityCheckOptions( - failureLevel = CheckLevel.Warning, + failureLevel = CheckLevel.Error, checker = RoborazziATFAccessibilityChecker( preset = AccessibilityCheckPreset.LATEST, suppressions = accessibilitySuppressions,