3

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

3
  • Did you ever figure this out? I'm running into a similar problem. Commented Dec 15, 2023 at 21:06
  • Same here happening to me Commented Jan 4, 2024 at 10:19
  • were you able to resolve this? Also @alireza or @codingjeremy? Commented Sep 8, 2024 at 18:12

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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>()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.