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

0

I'm performing automatic testing and would like to know how to get the IME_ACTION_DONE from the keyboard.

Follow 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 collaboration!

    
asked by anonymous 28.09.2016 / 19:12

2 answers

-1

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

onView(withId(R.id.seuedittext)).perform(pressImeActionButton());
    
28.09.2016 / 19:48
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;
    }
});
    
28.09.2016 / 19:18