Created
July 28, 2017 14:17
-
-
Save araujotadeu/59cf02c8ae88f3ac512c3fee6c814ff6 to your computer and use it in GitHub Desktop.
This file contains 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
public abstract class ViewActions { | |
public static final int DELAY = 100; | |
public static ViewAction waitId(final int viewId, final long millis) { | |
return new ViewAction() { | |
@Override | |
public Matcher<View> getConstraints() { | |
return isRoot(); | |
} | |
@Override | |
public String getDescription() { | |
return "wait for a specific view with id <" + viewId + "> during " + millis + " millis."; | |
} | |
@Override | |
public void perform(final UiController uiController, final View view) { | |
uiController.loopMainThreadUntilIdle(); | |
final long startTime = System.currentTimeMillis(); | |
final long endTime = startTime + millis; | |
final Matcher<View> viewMatcher = withId(viewId); | |
do { | |
for (View child : TreeIterables.breadthFirstViewTraversal(view)) { | |
if (viewMatcher.matches(child) && child.getVisibility() == View.VISIBLE) { | |
return; | |
} | |
} | |
uiController.loopMainThreadForAtLeast(DELAY); | |
} | |
while (System.currentTimeMillis() < endTime); | |
throw new PerformException.Builder() | |
.withActionDescription(this.getDescription()) | |
.withViewDescription(HumanReadables.describe(view)) | |
.withCause(new TimeoutException()) | |
.build(); | |
} | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment