I have one test case where I want to click fragment button which will navigate me to different screen.
This is my test case in feature file.
@abc
Scenario: As a RM, I should be able to see accepted on coming to admin approval screen
Given User is at XYZ screen for scenario "approved"
And User is able to see that verification is accepted
When User clicks on next button
Then User will be navigated to abc screen
When "User clicks on next button" test case is executed this method will call with the button id.
Espresso.onView(ViewMatchers.withId(R.id.add_button))
.perform(ViewActions.click())
And after that "Then" situation will execute with this method where I'm navigating to different fragment.
/**
* Match destination to which user will be navigated.
* Assert that mock nav controller has action for destination.
*
* @param id : This is fragment action id
*/
fun matchIntendedDestination(id: Int) {
SystemClock.sleep(1000)
val idCapture = ArgumentCaptor.forClass(Int::class.java)
Mockito.verify(BaseHelper.getMockNavController()).navigate(idCapture.capture())
Assert.assertEquals(id, idCapture.value)
}
Gradle version
classpath 'com.android.tools.build:gradle:4.2.1'
Espresso libraries
testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.espresso:espresso-intents:3.2.0'
androidTestImplementation "androidx.test.espresso:espresso-contrib:3.2.0"
androidTestImplementation('androidx.test:runner:1.1.0')
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
androidTestImplementation 'io.cucumber:cucumber-android:4.3.1'
androidTestImplementation 'com.squareup.okhttp3:mockwebserver:4.6.0'
debugImplementation 'androidx.fragment:fragment-testing:1.2.4'
androidTestImplementation "org.mockito:mockito-android:3.3.3"
And getting this error
Wanted but not invoked:
navController.navigate(<Capturing argument>);
-> at com.rupeek.loanreleaseapp.helper.ReleaseRejectionHelper.matchIntendedDestination(ReleaseRejectionHelper.kt:117)
Actually, there were zero interactions with this mock.
But the problem is this code is executing successfully in android 10 but not in Android 11. Can anyone please help me what I'm missing here for Android 11. I have also checked with updating all the libraries.
And when I debugged the code I found that perform(click()) is not calling anything in the fragment.