I m trying to write a UI test using BDD + Compose but I keep getting the error “Test not setup properly.Use a ComposeTestRule in your test to be able to interact with composables”.
I have tried both createComposeRule
and createAndroidComposeRule
:
@RunWith(AndroidJUnit4::class)
class LoginSteps {
@get:Rule
val composeTestRule = createAndroidComposeRule<MainActivity>()
@Given("^I am on the signup page$")
fun I_am_on_the_signup_page() {
// the following line produces the error:
composeTestRule.onNodeWithTag("logo").assertIsDisplayed()
}
@When("^I click the login button$")
fun when_I_click_login() {
composeTestRule.onNodeWithTag("loginBtn").assertIsDisplayed().performClick()
}
@Then("^I should see the login page$")
fun See_the_Sign_in_page() {
composeTestRule.onNodeWithTag("LoginWelcomemsg").assertIsDisplayed()
}
}
Below error:
java.lang.IllegalStateException: Test not setup properly. Use a ComposeTestRule in your test to be able to interact with composables
at androidx.compose.ui.test.junit4.ComposeRootRegistry_androidKt.ensureComposeRootRegistryIsSetUp(ComposeRootRegistry.android.kt:254)
at androidx.compose.ui.test.junit4.ComposeRootRegistry_androidKt.waitForComposeRoots(ComposeRootRegistry.android.kt:261)
at androidx.compose.ui.test.AndroidComposeUiTestEnvironment.waitForIdle(ComposeUiTest.android.kt:338)
at androidx.compose.ui.test.AndroidComposeUiTestEnvironment.access$waitForIdle(ComposeUiTest.android.kt:230)
at androidx.compose.ui.test.AndroidComposeUiTestEnvironment$AndroidTestOwner.getRoots(ComposeUiTest.android.kt:533)
at androidx.compose.ui.test.TestContext.getAllSemanticsNodes$ui_test_release(TestOwner.kt:86)
at androidx.compose.ui.test.SemanticsNodeInteraction.fetchSemanticsNodes$ui_test_release(SemanticsNodeInteraction.kt:63)
at androidx.compose.ui.test.SemanticsNodeInteraction.fetchSemanticsNodes$ui_test_release$default(SemanticsNodeInteraction.kt:56)
at androidx.compose.ui.test.AndroidAssertions_androidKt.checkIsDisplayed(AndroidAssertions.android.kt:29)
at androidx.compose.ui.test.AssertionsKt.isDisplayed(Assertions.kt:359)
at androidx.compose.ui.test.AssertionsKt.assertIsDisplayed(Assertions.kt:33)
at uk.co.topcashback.topcashback.qa.steps.login.LoginSteps.I_am_on_the_dual_page(LoginSteps.kt:61)
at ✽.I am on the dual page(file:/features/login.feature:4)
sri Natarajan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.