Skip to content

Commit

Permalink
Add a Roborazzi Screenshot test for Tutorial's Welcome page (#882)
Browse files Browse the repository at this point in the history
  • Loading branch information
timothyfroehlich committed Mar 28, 2024
1 parent b7160cc commit 3d8f2e9
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 33 deletions.
14 changes: 13 additions & 1 deletion reference-apps/tutorial/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ android {
// Deprecated in AGP 8+, replaced by `packaging`
@Suppress("DEPRECATION")
packagingOptions { resources { excludes.add("/META-INF/{AL2.0,LGPL2.1}") } }

testOptions.unitTests {
isIncludeAndroidResources = true // For Roborazzi
}
}

dependencies {
Expand All @@ -78,9 +82,17 @@ dependencies {
implementation(libs.androidx.compose.ui.tooling.preview)
implementation(libs.material)

testImplementation(libs.junit)
debugImplementation(libs.androidx.compose.ui.tooling)
debugImplementation(libs.androidx.compose.ui.test.manifest)

testImplementation(libs.designcompose.test)
testImplementation(libs.robolectric)
testImplementation(libs.roborazzi)
testImplementation(libs.roborazzi.compose)
testImplementation(libs.roborazzi.junit)
testImplementation(libs.androidx.test.espresso.core)
testImplementation(libs.androidx.compose.ui.test.junit4)

androidTestImplementation(platform(libs.androidx.compose.bom))
androidTestImplementation(libs.junit)
androidTestImplementation(libs.androidx.compose.ui.test.junit4)
Expand Down
Binary file not shown.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.android.designcompose.tutorial

import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.onRoot
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.github.takahirom.roborazzi.RobolectricDeviceQualifiers
import com.github.takahirom.roborazzi.RoborazziRule
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.annotation.Config
import org.robolectric.annotation.GraphicsMode

@RunWith(AndroidJUnit4::class)
@Config(qualifiers = RobolectricDeviceQualifiers.MediumTablet, sdk = [34])
@GraphicsMode(GraphicsMode.Mode.NATIVE)
class CheckStartupPage {
@get:Rule val composeTestRule = createComposeRule()

@get:Rule
val roborazziRule =
RoborazziRule(
composeRule = composeTestRule,
// Specify the node to capture for the last image
captureRoot = composeTestRule.onRoot(),
options =
RoborazziRule.Options(
outputDirectoryPath = "src/testDebug/roborazzi",
// Always capture the last image of the test
captureType = RoborazziRule.CaptureType.LastImage()
)
)

@Test
fun testStartupPage() {
with(composeTestRule) {
setContent { TutorialMain() }
onNodeWithText(
"Congratulations on running the Automotive Design for Compose Tutorial app!",
substring = true
)
.assertExists()
}
}
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 3d8f2e9

Please sign in to comment.