Test if soft keyboard is visible using espresso

前端 未结 4 1511
野的像风
野的像风 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:23

    another trick could be checking for the visibility of a view that you know is going to be covered when the keyboard is showing. don't forget to take animations into consideration...

    instrumentation testing using espresso and hamcrest for the NOT matcher something like:

    //make sure keyboard is visible by clicking on an edit text component
        ViewInteraction v = onView(withId(R.id.editText));
        ViewInteraction v2 = onView(withId(R.id.componentVisibleBeforeKeyboardIsShown));
        v2.check(matches(isDisplayed()));
        v.perform(click());
        //add a small delay because of the showing keyboard animation
        SystemClock.sleep(500);
        v2.check(matches(not(isDisplayed())));
        hideKeyboardMethod();
        //add a small delay because of the hiding keyboard animation
        SystemClock.sleep(500);
        v2.check(matches(isDisplayed()));
    

提交回复
热议问题