diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a9241f2..778073c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,22 @@ # Testify Change Log -## 2.0.0-rc01 +## 2.0.0-rc03 + +### Library + +#### Fixed + +- Refactor ComposableScreenshotRule.setCaptureMethod() to call the configure() method. + +### Legacy Sample + +#### Added + +- Added a Dialog sample to test as a demonstration of how to capture dialog boxes and also as a regression test for the bug with `setCaptureMethod()` + +--- + +## 2.0.0-rc02 ### Library diff --git a/Ext/Compose/src/main/java/dev/testify/ComposableScreenshotRule.kt b/Ext/Compose/src/main/java/dev/testify/ComposableScreenshotRule.kt index 338d45d7..f066b516 100644 --- a/Ext/Compose/src/main/java/dev/testify/ComposableScreenshotRule.kt +++ b/Ext/Compose/src/main/java/dev/testify/ComposableScreenshotRule.kt @@ -68,7 +68,9 @@ open class ComposableScreenshotRule( replaceWith = ReplaceWith("configure { this@configure.captureMethod = captureMethod }") ) override fun setCaptureMethod(captureMethod: CaptureMethod?): ComposableScreenshotRule { - this.captureMethod = captureMethod ?: configuration.captureMethod ?: ::pixelCopyCapture + configure { + this@configure.captureMethod = captureMethod + } return this } diff --git a/Plugins/Gradle/jar/Plugin-local.jar b/Plugins/Gradle/jar/Plugin-local.jar index 419d00bd..6286161c 100644 Binary files a/Plugins/Gradle/jar/Plugin-local.jar and b/Plugins/Gradle/jar/Plugin-local.jar differ diff --git a/Samples/Legacy/src/androidTest/assets/screenshots/29-1080x2220@440dp-en_US/ComposableScreenshotTest_dialog.png b/Samples/Legacy/src/androidTest/assets/screenshots/29-1080x2220@440dp-en_US/ComposableScreenshotTest_dialog.png new file mode 100644 index 00000000..ebbca1f8 Binary files /dev/null and b/Samples/Legacy/src/androidTest/assets/screenshots/29-1080x2220@440dp-en_US/ComposableScreenshotTest_dialog.png differ diff --git a/Samples/Legacy/src/androidTest/java/dev/testify/sample/compose/ComposableScreenshotTest.kt b/Samples/Legacy/src/androidTest/java/dev/testify/sample/compose/ComposableScreenshotTest.kt index 2fe8b28b..b0442c16 100644 --- a/Samples/Legacy/src/androidTest/java/dev/testify/sample/compose/ComposableScreenshotTest.kt +++ b/Samples/Legacy/src/androidTest/java/dev/testify/sample/compose/ComposableScreenshotTest.kt @@ -32,9 +32,11 @@ import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.wrapContentHeight +import androidx.compose.material.AlertDialog +import androidx.compose.material.Button import androidx.compose.material.Text import androidx.compose.runtime.Composable -import androidx.compose.ui.Alignment +import androidx.compose.ui.Alignment.Companion.Center import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.test.onNodeWithTag @@ -44,6 +46,7 @@ import androidx.compose.ui.unit.sp import dev.testify.ComposableScreenshotRule import dev.testify.annotation.ScreenshotInstrumentation import dev.testify.capture.fullscreen.captureFullscreen +import dev.testify.capture.fullscreen.fullscreenCapture import dev.testify.capture.fullscreen.provider.excludeSystemUi import dev.testify.sample.ClientListItem import dev.testify.sample.DropdownDemo @@ -91,7 +94,7 @@ class ComposableScreenshotTest { PaddedBox(Color.Gray) { PaddedBox(Color.LightGray) { Text( - modifier = Modifier.align(Alignment.Center), + modifier = Modifier.align(Center), text = "Hello, Testify!", color = Color.Blue, fontSize = 32.sp @@ -178,4 +181,34 @@ class ComposableScreenshotTest { .setFontScale(fontScale) .assertSame() } + + /** + * Demonstrate how to capture a Dialog using the Fullscreen capture method + */ + @ScreenshotInstrumentation + @Test + fun dialog() { + rule + // Use the deprecated method as a regression test + .setCaptureMethod(::fullscreenCapture) + // We can't use captureFullscreen() here since that hides the ComposableScreenshotRule + .configure { + // The recommended approach would be to configure the captureMethod to ::fullscreenCapture + // captureMethod = ::fullscreenCapture + excludeSystemUi() + } + .setCompose { + Box(modifier = Modifier.fillMaxSize()) { + AlertDialog( + onDismissRequest = {}, + title = {}, + text = { + Text(modifier = Modifier.align(Center), text = "Hello, Testify!") + }, + confirmButton = { Button(onClick = {}) { Text("OK") } } + ) + } + } + .assertSame() + } } diff --git a/build.gradle b/build.gradle index be2c4835..356b3e4c 100644 --- a/build.gradle +++ b/build.gradle @@ -38,7 +38,7 @@ buildscript { 'material' : '1.9.0', // https://material.io/develop/android/docs/getting-started/ 'mockk' : '1.13.5', // https://central.sonatype.com/artifact/io.mockk/mockk/1.13.4/versions 'slf4j' : '2.0.6', - 'testify' : '2.0.0-rc02', // https://github.com/ndtp/android-testify/releases + 'testify' : '2.0.0-rc03', // https://github.com/ndtp/android-testify/releases ] coreVersions = [ 'compileSdk': 33,