How to test an event on the keyboard (Editorinfo.IME_ACTION_DONE)

Asked

Viewed 54 times

0

I am performing automatic tests and would like to know how to catch the and evendo IME_ACTION_DONE keyboard.

Follows the code:

@Test
public void shouldSearchUserOnMap(){
    SystemClock.sleep(2500);
    Login();
    onView(withId(R.id.searchButton)).perform(typeText("[email protected]"));
    SystemClock.sleep(2500);
    onView(pressKey(EditorInfo.IME_ACTION_DONE)).perform(click());

}

Thank you for your cooperation!

2 answers

0

You need the Oneditoractionlistener

Example:

EditText et = (EditText) findViewById(R.id.search_field);

et.setOnEditorActionListener(new EditText.OnEditorActionListener() {
    @Override
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
        if (actionId == EditorInfo.IME_ACTION_DONE)  {

            //faz algo aqui

            return true;
        }
        return false;
    }
});
  • Does not work for intaface test

-1


To solve the DONE of the keyboard for Unit/Interface tests, do the following: In the code there is the editActionListener with the desired keyboard action. Then include in the test:

onView(withId(R.id.seuedittext)).perform(pressImeActionButton());

Browser other questions tagged

You are not signed in. Login or sign up in order to post.