I'm working with some simple tests with Espresso. One of them is about click on view and check if a Dialog is showed.
My problem is that sometimes works, and sometimes not. It only work always if I put a sleep before check the dialog. Any solution without ussing sleep?
Here is my code (so simple):
onView(withId(R.id.forgot_password)).perform(click());
// only works if use Thread.sleep(ms) here
onView(withText(R.string.reset_password)).check(matches(isDisplayed()));
Edit:
I'm showing dialog with static helpers, but the simplification is this. And I'm not performing any background task in the middle.
final TextInputDialog textInputDialog = new
TextInputDialog.Builder(context)
.setTitle(titleId)
.setInputType(inputType)
.setHint(hintId)
.setPreFilledText(preFilledText)
.setNegativeButton(R.string.cancel, null)
.setPositiveButton(positiveButtonId, onTextSubmittedListener)
.create();
textInputDialog.show(textInputDialog);
Thank you!