So, I have use Espresso library's waitUntilDoesNotExist which take two arguments SemanticsMatcher and timeoutMillis. By default, timeoutMillis is 1000ms but in my case i have to increase it 2000ms because it takes more time then 1000ms to complete the network call to register.
@get: Rule
val composeRule = createAndroidComposeRule<MainActivity>()
@OptIn(ExperimentalTestApi::class)
@Test
fun validateRegisterFormButtonIsClickAndShowEmailAlreadyExits() {
composeRule.apply {
onNodeWithTag("RegistrationForm").assertIsDisplayed()
onNodeWithTag("User Name").assertIsDisplayed().performTextInput("Nizam")
onNodeWithTag("Email").assertIsDisplayed().performTextInput("[email protected]")
onNodeWithTag("Password").assertIsDisplayed().performTextInput("Nizam@123")
onNodeWithTag("Confirm Password").assertIsDisplayed().performTextInput("Nizam@123")
onNodeWithTag("Register").assertIsDisplayed().performClick()
waitUntilDoesNotExist(hasTestTag("progress"),2000)
onNodeWithText("([email protected])-email already exists").assertIsDisplayed()
}
}
I know this is very flaky solution, but can you help to Idle the resource just until network API response comes.