I found a pretty cool lump of code from here that helps with performing a wait function until a resource withId(int)
appears - and it seems to be working fine when I actually have a resource id to work with.
However, the app I am working with does not normally have simple resource id's and I have to work with Matchers instead.
An Example:
Matcher secondBanner = allOf(childAtPosition(allOf(withId(R.id.story_details_body),
childAtPosition(IsInstanceOf.<View>instanceOf(
android.widget.LinearLayout.class),2)),0)))
Is there any way to perform a similar wait on a Matcher like there is the resource id?
The code I am referring to in the previous link is -
/** Perform action of waiting for a specific view id. */
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)) {
// found view with required ID
if (viewMatcher.matches(child)) {
return;
}
}
uiController.loopMainThreadForAtLeast(50);
}
while (System.currentTimeMillis() < endTime);
// timeout happens
throw new PerformException.Builder()
.withActionDescription(this.getDescription())
.withViewDescription(HumanReadables.describe(view))
.withCause(new TimeoutException())
.build();
}
};
}
I've tried to simply just change everything from withId(int)
to Matcher
to no avail.
So is it possible to turn this bit of code into something that can perform a wait/timeout?
Thanks for any and all help.