Test if soft keyboard is visible using espresso

前端 未结 4 1600
野的像风
野的像风 2021-02-19 02:08

I want to test keyboard visibility when an activity calls onCreate() and onResume().

How can i test whether or not the keyboard is shown using espresso?

4条回答
  •  轮回少年
    2021-02-19 02:32

    This is a kind of trick to check if keyboard is visible, it's not a perfect solution but for me was enough:

    1. check if the fragment/activity container is displayed
    2. perform a press back
    3. check if the same fragment/activity container is displayed

    Simple code example:

    onView(allOf(withId(R.id.myFragment),isDisplayed()));
    onView(withId(R.id.myFragment)).perform(pressBack());
    onView(allOf(withId(R.id.myFragment),isDisplayed()));
    

    If keyboard is visible means that the second time you press back button the view container is still there ;)

    Hope this help!

提交回复
热议问题