Issue
Eg. I have created two activities and second activities contain recycler item list and progress bar. until finish API call we are waiting for a response and shows progress bar
Solution
So, you want to wait until your ProgressBar is hidden.
You can either create an idling resource
or use a custom ViewAction as this one:
/**
* Perform action of waiting until the element is accessible & not shown.
* @param viewId The id of the view to wait for.
* @param millis The timeout of until when to wait for.
*/
public static ViewAction waitUntilNotShown(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 + "> is hidden 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) && !child.isShown()) {
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();
}
};
}
And you can use it this way:
onView(isRoot()).perform(waitUntilNotShown(R.id.theIdToWaitFor, 5000));
changing theIdToWaitFor
with the specific id of your ProgressBar
and updating the timeout of 5 secs (5000 millis) if necessary.
However, depending on which test you are doing, if this is not an integration test it's better not to make real api calls.
Answered By - jeprubio
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.