I have an espresso test where my screen contains an EditText and a skip Button underneath.
When I launch the activity the keyboard pops open, focuses on the EditText and overlaps the Button.
I now want to write a test for the skip button and assert what happens afterwards.
The issue is that espresso does not wait for the keyboard to open.
So what happens is
- Espresso is not waiting for keyboard and presses "skip"
- Keyboard slides open
- Assertion for something thats now underneath the keyboard fails
The code looks like this:
public void givenSkipped_whenConfirmed_thenMainActivityLaunched() {
Espresso.closeSoftKeyboard();// <- Not working as espresso seems to think it is not open yet
skipPostcodeEntry.perform(click()); //<- Can click this as keyboard is not open yet.
warningText.check(matches(withText(R.string.some_text)));
confirmationButton.perform(click());//<- Fails as this is now overlapped by KB
Assert.DoesSomething()
}
I found an issue where espresso was not waiting for the keyboard to close but nothing about it not waiting for the keyboard to open.
Has anyone solved this issue?
Edit:
When you look into the closeSoftKeyboard method you can find a class called CloseKeyboardAction. You can see that it even logs when the keyboard is not recognised as open.
Log.w(TAG, "Attempting to close soft keyboard, while it is not shown.");