s3rius
03/23/2023, 6:57 PMawaitIdle()
before taking a screenshot. This works because it waits until the animation has finished, but since awaitIdle()
is a suspend function, I cannot just run it in a ChildStack observer.
@Test
fun test() = runBlocking {
var count = 0
// The user flow is: Login -> Onboarding -> Dashboard
val main = MainComponent(testContext(lifecycleRegistry))
rule.setContentAndAwaitIdle {
MainUi(main)
}
lifecycleRegistry.start()
rule.awaitIdle()
rule.renderToFile("${count++}.jpg") // Takes a screenshot of the Login screen
// Perform login
rule.onNodeWithText("E-Mail").performTextInput("test")
rule.onNodeWithText("Password").performTextInput("word")
rule.onNode(hasText("Login").and(hasClickAction().and(isEnabled()))).performClick()
rule.awaitIdle()
rule.renderToFile("${count++}.jpg") // Takes a screenshot of the Onboarding screen
rule.onNode(hasClickAction()).performClick() // Accept Onboarding
rule.awaitIdle()
rule.renderToFile("${count++}.jpg") // Takes a screenshot of the Dashboard screen
}
If I want to automate the process of taking screenshots the only options I can see are (1) observe the moment the transition animation has ended or (2) modify the code so that no animation happens during tests (but even then I think I'm actually taking a screenshot of the frame before the new scene is rendered).Arkadii Ivanov
03/23/2023, 8:25 PMChildren(
stack = childStack,
modifier = Modifier.weight(weight = 1F),
animation = tabAnimation(),
) {
when (val child = it.instance) {
is CountersChild -> CountersContent(component = child.component, modifier = Modifier.fillMaxSize())
is MultiPaneChild -> MultiPaneContent(component = child.component, modifier = Modifier.fillMaxSize())
is DynamicFeaturesChild -> DynamicFeaturesContent(component = child.component, modifier = Modifier.fillMaxSize())
is CustomNavigationChild -> CustomNavigationContent(component = child.component, modifier.fillMaxSize())
}
DisposableEffect(it.configuration) {
onDispose {
// The animation is finished
}
}
}
idle
in tests. This is how I tested the Children
function with animations - link.s3rius
03/23/2023, 9:14 PMArkadii Ivanov
03/23/2023, 9:29 PM