Jul 26, 2017 · 1 min read
Looks like this can help with testing toasts in our espresso automation. Thanks for sharing it.
Is there a reliable way to assert that toast/snack bar doesn’t show up?
I have something like
ToastPopup toast = new ToastPopup(setupRule.getActivity());
toast.oopsToast.check(doesNotExist());Where ToastPopup is
public class ToastPopup {
public ViewInteraction oopsToast;
public ToastPopup(Activity activity) {
oopsToast =
onView(withText(R.string.defaultErrorMessage))
.inRoot(withDecorView(not(activity.getWindow().getDecorView())));
}
}But I am not fully confident this is reliable and I have seen it flaking out sometimes.
