onView(withId(R.id.menu_item_add)).check(
matches(
allOf(
isEnabled(),
isClickable()
)
)
).perform(
object : ViewAction {
override fun getDescription(): String {
return "click add button"
}
override fun getConstraints(): Matcher<View> {
return isEnabled()
}
override fun perform(uiController: UiController?, view: View?) {
view?.performClick()
}
}
)
//MainActivity
private lateinit var navController:NavController
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
navController=Navigation.findNavController(this,R.id.fragment)
NavigationUI.setupActionBarWithNavController(this,navController)
}
override fun onSupportNavigateUp(): Boolean {
return navController.navigateUp()
}