focus-android icon indicating copy to clipboard operation
focus-android copied to clipboard

Cannot run automated test on compose lazy list: java.lang.IllegalArgumentException: Failed requirement. at androidx.compose.ui.node.MeasureAndLayoutDelegate.measureAndLayout(MeasureAndLayoutDelegate.kt:190

Open sv-ohorvath opened this issue 3 years ago • 1 comments

Steps to reproduce

Note:This is for documenting my findings in testing Compose lazy lists. Not manually reproducible, this is affecting UI tests only (as far as I know), but needs an engineer's attention

While trying to refactor englishSystemLocaleTest() to test with Compose test rule, I hit this error trying to scroll the language list:

java.lang.IllegalArgumentException: Failed requirement.
at androidx.compose.ui.node.MeasureAndLayoutDelegate.measureAndLayout(MeasureAndLayoutDelegate.kt:190)
at androidx.compose.ui.platform.AndroidComposeView.measureAndLayout(AndroidComposeView.android.kt:662)
at androidx.compose.ui.node.Owner$DefaultImpls.measureAndLayout$default(Owner.kt:182)
at androidx.compose.ui.node.LayoutNode.forceRemeasure(LayoutNode.kt:1339)
at androidx.compose.foundation.lazy.layout.LazyLayoutState.remeasure(LazyLayoutState.kt:54)
at androidx.compose.foundation.lazy.LazyListState.snapToItemIndexInternal$foundation_release(LazyListState.kt:202)
at androidx.compose.foundation.lazy.LazyListState$scrollToItem$2.invokeSuspend(LazyListState.kt:194)
at androidx.compose.foundation.lazy.LazyListState$scrollToItem$2.invoke(Unknown Source:8)
at androidx.compose.foundation.lazy.LazyListState$scrollToItem$2.invoke(Unknown Source:4)

While investigating I've tried a solution found here https://dmytroshuba.com/blog/jetpack-compose-ui-testing/#h-lateinit-property-remeasurement-has-not-been-initialized-in-lazylist* to replace scrollToItem(index) with animateScrollToItem(index) which should work the same way. The test passed now until I hit another crash which didn't seem so straightforward to fix: java.lang.IllegalStateException: measure() may not be called multiple times on the same Measurable. Current state InMeasureBlock. Parent state Measuring. Test log: https://console.firebase.google.com/u/1/project/moz-focus-android/testlab/histories/bh.2189b040bbce6d5a/matrices/5356848690213833442/executions/bs.c8e057ae5d7d1fc4/testcases/1/test-cases

Meanwhile, the UI tests are now written using UiAutomator and not scrolling the list (it will scroll only partially, not all the way down), but it would be nice to have a working scrollable language list in case we need to expand our testing. Also good to know in case other lists are refactored to Compose LazyList.

Device information

  • Android device: Pixel 3 (android 11)
  • Focus version: debug

sv-ohorvath avatar Jun 27 '22 12:06 sv-ohorvath

Probably another case, in Fenix: SettingsSearchTest. editCustomSearchEngineTest

sv-ohorvath avatar Oct 11 '22 13:10 sv-ohorvath

More and more tests require scrolling compose lists as the Compose migration is advancing on Fenix and Focus. So I'm marking this as S1 to get some attention.

sv-ohorvath avatar Nov 17 '22 13:11 sv-ohorvath

Moved to bugzilla: https://bugzilla.mozilla.org/show_bug.cgi?id=1802638

Change performed by the Move to Bugzilla add-on.

cpeterso avatar Nov 26 '22 05:11 cpeterso