Issue
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!
Solution
Finally it seems like the problem was animations. For make Espresso works properly is needed to disable animations in developer options menu.
In this case, the problem was solved. But there are other cases in which the problem could be a background task, like the comments to my question suggest. So I recommend to have a look at IdlingResource https://medium.com/azimolabs/wait-for-it-idlingresource-and-conditionwatcher-602055f32356#.pw55uipfj or this Espresso: Thread.sleep( );
Answered By - adalpari
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.