-
-
Save moltak/a8d1d5a7aca45875e760 to your computer and use it in GitHub Desktop.
Matcher that is Toast window
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Matcher that is Toast window. | |
*/ | |
public static Matcher<Root> isToast() { | |
return new TypeSafeMatcher<Root>() { | |
@Override | |
public void describeTo(Description description) { | |
description.appendText("is toast"); | |
} | |
@Override | |
public boolean matchesSafely(Root root) { | |
int type = root.getWindowLayoutParams().get().type; | |
if ((type == WindowManager.LayoutParams.TYPE_TOAST)) { | |
IBinder windowToken = root.getDecorView().getWindowToken(); | |
IBinder appToken = root.getDecorView().getApplicationWindowToken(); | |
if (windowToken == appToken) { | |
// windowToken == appToken means this window isn't contained by any other windows. | |
// if it was a window for an activity, it would have TYPE_BASE_APPLICATION. | |
return true; | |
} | |
} | |
return false; | |
} | |
}; | |
} | |
// How to use | |
onView(isRoot()).inRoot(isToast()).check(matches(withText("Request has been sent."))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment