Dialog boxes are untestable on Compose Desktop
See original GitHub issueProblem
Using the Compose UI Testing library, we cannot test dialog boxes on Compose Desktop. The following example construct works on Android, but not on Desktop.
Example Code
// Test Logic
@Test
fun `reproduce dialog test failure`() {
ui(compose) {
setContent {
var isDialogOpen by remember { mutableStateOf(false) }
DialogHolder(isDialogOpen) {v -> isDialogOpen = v}
}
onNodeWithText("Open").performClick()
awaitIdle()
onNodeWithText("Close").assertExists()
}
} }
// --------------
@Composable fun DialogHolder(isDialogOpen: Boolean, updateDialog: (Boolean) -> Unit) {
Button(onClick = { updateDialog(true) }) {
Text("Open")
}
if (isDialogOpen) {
Dialog(onCloseRequest = { updateDialog(false) }) {
Button(onClick = { updateDialog(false) }) {
Text("Close")
}
}
}
}
Expectation
Test passes. Content within dialog box is detected.
Actual Result
Test fails with the following error:
Failed: assertExists.
Reason: Expected exactly '1' node but could not find any node that satisfies: (Text + EditableText contains 'Close' (ignoreCase: false))
java.lang.AssertionError: Failed: assertExists.
Reason: Expected exactly '1' node but could not find any node that satisfies: (Text + EditableText contains 'Close' (ignoreCase: false))
at androidx.compose.ui.test.SemanticsNodeInteraction.fetchOneOrDie(SemanticsNodeInteraction.kt:162)
at androidx.compose.ui.test.SemanticsNodeInteraction.assertExists(SemanticsNodeInteraction.kt:137)
...
Version Info
- Kotlin: 1.6.10
- Jetpack Compose: 1.1.1
- JVM Target: 11
Links
Relevant Stackoverflow question (asked by me): https://stackoverflow.com/q/72507535/3477606.
Issue Analytics
- State:
- Created a year ago
- Reactions:2
- Comments:6
Top Results From Across the Web
Dialog boxes cannot be tested in Jetpack Compose Desktop
Dialog composables seem to be untestable in Jetpack Compose on the Desktop platform. Any action triggered from the test that adds a Dialog...
Read more >Customize a Compose for Desktop AlertDialog
Let's take a look at the AlertDialog composable when used in Compose for Desktop. A rather basic form of an AlertDialog is created...
Read more >Custom UI test steps - ServiceNow Docs
Install the ServiceNow CLI on Windows ... Set up Box spoke ... Write a script for an automation message variable in Automation Center....
Read more >Miguel on Twitter: "Two significant downsides of Jetpack ...
Two significant downsides of Jetpack Compose are the super slow previews and that it's untestable on the jvm. They are probably related ...
Read more >Compose for Desktop: Milestone 4 Released | The Kotlin Blog
compose.ui.window.Dialog. Being able to use a declarative approach to defining how your windows, dialogs, menu bars and tray icons behave makes ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Bumping this for attention. Can I at least have an idea of when/if this is planned to be fixed?
I think this goes beyond dialog boxes,
Window
s of any kind can’t be ‘seen through’.returns
For comparison, removing the
Window
returns
Is anyone aware whether end to end testing is workable by any means right now?