I am working on the project. I start learning instrumental tests using Espresso
to write UI testing. I have a bottom view each bottom view tab has a parent fragment & their child fragments. I have done one wrong fragment transaction i.e when navigating toward home bottom view tab from services bottom view tab home is selected but showing services fragment.
I want to test when clicking on the home bottom view tab the home fragment is added or not. I have tried the code like this but it is passing on the wrong case as well
I have also go through the below StackOverflow posts but not working
Determine fragment change while espresso testing
How to test if a fragment is visible with Espresso
@Test
fun testHomeFragment_isDisplayed() {
//click on home navigation button of bottom view
onView(withId(R.id.navigation_home)).perform(click())
//click on services navigation button of bottom view
onView(withId(R.id.navigation_more)).perform(click())
//click on recycler view item at given position
onView(withId(R.id.more_rv)).perform(
RecyclerViewActions.actionOnItemAtPosition<RecyclerView.ViewHolder>(
1,
MyViewAction.clickChildViewWithId(R.id.row_more_parent)));
//Again click on home navigation button of bottom view
onView(withId(R.id.navigation_home)).perform(click())
//check that the home fragment is displayed or not.
onView(allOf(withId(R.id.home_pager), withParent(withId(R.id.papa)))).
check(matches(isCompletelyDisplayed()))
}
How to know which fragment is currently displayed on the screen?