[Snapshots] Error when snapshotting preview with Dialog #136
Open
Description
There's a crash upon snapshotting a preview that contains a dialog. As a minimal repro:
@Preview
@Composable
fun ConfirmationAlertDialogPreview() {
SnapshotsSampleTheme {
Box(
modifier = Modifier
.fillMaxSize()
.background(color = MaterialTheme.colorScheme.background)
) {
// Other UI
ConfirmationAlertDialog(...)
}
}
}
@Composable
fun ConfirmationAlertDialog(
onDismiss: () -> Unit,
onConfirm: () -> Unit,
message: String,
title: String,
confirmButtonLabel: String,
confirmButtonColor: Color = Color.Unspecified,
) {
AlertDialog(
onDismissRequest = onDismiss,
confirmButton = { ... },
dismissButton = { ... },
title = { Text(title) },
text = { Text(message) },
)
}
Running this with ./gradlew emergeLocalSnapshotsDebug
results in a crash with the following stacktrace. The same crash occurs when running on Emerge's cloud snapshotting system.
There was 1 failure:
1) MaterialThemedComponentWithDialog_GenSnapshot(com.emergetools.snapshots.sample.ui.MaterialThemedComponentWithDialog_-1316455265_GenSnapshot)
java.lang.AssertionError: Failed to capture a node to bitmap.
Reason: Expected exactly '1' node but found '2' nodes that satisfy: (isRoot)
Nodes found:
1) Node #11 at (l=0.0, t=77.0, r=1080.0, b=2028.0)px
Has 1 child
2) Node #12 at (l=0.0, t=0.0, r=770.0, b=382.0)px
Has 1 child
at androidx.compose.ui.test.SemanticsNodeInteraction.fetchOneOrDie(SemanticsNodeInteraction.kt:145)
at androidx.compose.ui.test.SemanticsNodeInteraction.fetchSemanticsNode(SemanticsNodeInteraction.kt:79)
at androidx.compose.ui.test.AndroidImageHelpers_androidKt.captureToImage(AndroidImageHelpers.android.kt:51)
at com.emergetools.snapshots.EmergeSnapshots.take(EmergeSnapshots.kt:72)
at com.emergetools.snapshots.sample.ui.MaterialThemedComponentWithDialog_-1316455265_GenSnapshot.MaterialThemedComponentWithDialog_GenSnapshot(MaterialThemedComponentWithDialog_-1316455265_GenSnapshot.kt:34)