Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't I access to ComposeTestRule when UI testing with xml and compose screen hybrid

Android Compose UI test: I am getting this error when I tried to use composeTestRule to access compose node. This only happens when my app finishes login sync and app brings up the homescreen. My app has a takeover screen over the homescreen after the sync. It's like when the sync finishes, first app shows homescreen and the takeover screen shows up. Homescreen and login sync screen is done using xml and the takeover screen is doing using jetpack compose. Takeover screen (jetpack compose screen) is setcontent in a fragment from HomeActivity. Fyi: I am doing full app UI test (end to end).I have it at my class level

@get:Rule val composeTestRule = createAndroidComposeRule<HomeActivity>() composeTestRule.onNodeWithText("Dismiss").assertIsDisplayed()

Does anybody know, why I can't access to composeTestRule on the takeover screen? and get the below error? java.lang.IllegalStateException: Test not setup properly. Use a ComposeTestRule in your test to be able to interact with composables

like image 982
indraw Avatar asked Dec 06 '25 07:12

indraw


2 Answers

I had this error when rule was created in helper class/object. Moving the creation of androidComposeRule to the class where the espresso test is, solved the problem.

like image 139
Łukasz Koryciński Avatar answered Dec 08 '25 20:12

Łukasz Koryciński


I had the same error. In my test class I used three rules and fixed this by moving the compose rule to the last position of the rule order. You can do so by

@get:Rule(order = 2)
val composeTestRule = createAndroidComposeRule<Activity>()
like image 36
Maik Peschutter Avatar answered Dec 08 '25 19:12

Maik Peschutter



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!