I've encountered an issue where my UI test freezes specifically on the performScrollToNode() function when testing a screen that contains a LazyVerticalGrid. The test enters an apparent infinite loop, unable to exit the state stabilization mechanism (similar to an internal while(true){} within the testing framework).
Screen and Architecture Context:
- Container: The main content is inside a
LazyVerticalGrid(tagged withtestTag("product_lazy_grid")). - Architecture: The application uses Compose UI hosted within a Fragment (
ComposeScreenFragment), with navigation managed by Cicerone. - The Issue: Attempting to force a scroll to a component at the end of the list (
performScrollToNode(hasTestTag("last_page_widget"))) causes the test runner to hang indefinitely.
Steps Taken and Verified (Did Not Resolve the Issue):
- Synchronization: The test is run within
runTestwith explicit calls totestScheduler.runCurrent()andcomposeTestRule.waitForIdle()before and after navigation and scrolling attempts. - Mocking/DI: I use Koin/MockK to mock the
ViewModeland the CiceroneRouter, ensuring no external dependencies (e.g.,BottomBarActivity) are blocking the UI thread. - Element Existence: The target element (
last_page_widget) is guaranteed to be present in theLazyGridScopeand is visible in the unmerged semantic tree (onRoot(useUnmergedTree = true)), although it's initially off-screen.
Thank you for any insights and help with diagnosis!
The Core Questions:
- What other factors could prevent
performScrollToNode()from determining the UI's "idle state," leading to a freeze? - Could internal logic within the
LazyVerticalGrid(such as a specific implementation ofLazyGridScope.itemorfillMaxWidthItem) be interfering with the Compose synchronization mechanism? - What global Kaspresso settings (
ComposeTestRule,FlakySafetyParams) or Coroutine Dispatcher configurations might specifically impact freezing inside this function? - How can I diagnose the root cause more deeply (e.g., via Logcat or specific debugging flags) to see why the Compose Test Rule believes the UI is perpetually busy?