Skip to content

Instantly share code, notes, and snippets.

@DavidRyan
Created July 11, 2014 20:14
Show Gist options
  • Save DavidRyan/51e3afb517d79a1b3046 to your computer and use it in GitHub Desktop.
Save DavidRyan/51e3afb517d79a1b3046 to your computer and use it in GitHub Desktop.
/** Perform action of waiting for a specific view id. */
public static ViewAction waitForId(final int viewId, final long millis) {
return new ViewAction() {
@Override
public Matcher<View> getConstraints() {
return isDisplayed();
}
@Override
public String getDescription() {
return "waited for a specific view with id <" + viewId + "> for " + millis + " millis.";
}
@Override
public void perform(final UiController uiController, final View view) {
uiController.loopMainThreadUntilIdle();
final long startTime = System.currentTimeMillis();
final long endTime = startTime + millis;
do {
uiController.loopMainThreadForAtLeast(100);
}
while (System.currentTimeMillis() < endTime);
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment