Espresso - how to wait for idle without an assertion/view interaction?

Espresso - how to wait for idle without an assertion/view interaction?

By : Seya Natgho Boo
Date : November 20 2020, 07:00 PM
it should still fix some issue You can use InstrumentationRegistry.getInstrumentation().waitForIdleSync(). https://developer.android.com/reference/android/app/Instrumentation.html#waitForIdleSync()
There is also Espresso.onIdle(), but the documentation warns Only call this method for tests that do not interact with any UI elements, but require Espresso's main thread synchronisation! https://developer.android.com/reference/android/support/test/espresso/Espresso.html#onIdle()
code :

Share : facebook icon twitter icon
Wait for view pager animations with espresso?

Wait for view pager animations with espresso?

By : Rajasekar
Date : March 29 2020, 07:55 AM
I wish this helpful for you The IdlingResource @Simas suggests is actually pretty simple to implement:
code :
public class ViewPagerIdlingResource implements IdlingResource {

    private final String mName;

    private boolean mIdle = true; // Default to idle since we can't query the scroll state.

    private ResourceCallback mResourceCallback;

    public ViewPagerIdlingResource(ViewPager viewPager, String name) {
        viewPager.addOnPageChangeListener(new ViewPagerListener());
        mName = name;

    public String getName() {
        return mName;

    public boolean isIdleNow() {
        return mIdle;

    public void registerIdleTransitionCallback(ResourceCallback resourceCallback) {
        mResourceCallback = resourceCallback;

    private class ViewPagerListener extends ViewPager.SimpleOnPageChangeListener {

        public void onPageScrollStateChanged(int state) {
            mIdle = (state == ViewPager.SCROLL_STATE_IDLE
                    // Treat dragging as idle, or Espresso will block itself when swiping.
                    || state == ViewPager.SCROLL_STATE_DRAGGING);
            if (mIdle && mResourceCallback != null) {
Espresso Wait for [RxIdlingResource] to become idle timed out

Espresso Wait for [RxIdlingResource] to become idle timed out

By : Zachary Townes
Date : March 29 2020, 07:55 AM
Hope this helps Since we didn't obtain any better answer to this problem we assumed objects send through the RxBus were immediate and didn't need to be counted in the subscriptions.incrementAndGet();
We simply filtered the objects out before this line. In our case the objects were of the class SerializedSubject and PublishSubject.
code :
public <T> Observable.OnSubscribe<T> onSubscribeStart(Observable<? extends T> observableInstance, final Observable.OnSubscribe<T> onSubscribe) {

    int activeSubscriptionCount = 0;

    if (observableInstance instanceof SerializedSubject || observableInstance instanceof PublishSubject) {
        Log.d(TAG, "Observable we won't register: " + observableInstance.toString());
    } else {
        activeSubscriptionCount = subscriptions.incrementAndGet();
    if (LOG_LEVEL.atOrAbove(DEBUG)) {
        if (LOG_LEVEL.atOrAbove(VERBOSE)) {
            Log.d(TAG, onSubscribe + " - onSubscribeStart: " + activeSubscriptionCount, new Throwable());
        } else {
            Log.d(TAG, onSubscribe + " - onSubscribeStart: " + activeSubscriptionCount);

    onSubscribe.call(new Subscriber<T>() {
        public void onCompleted() {
            onFinally(onSubscribe, "onCompleted");

        public void onError(Throwable e) {
            onFinally(onSubscribe, "onError");

        public void onNext(T t) {
            Log.d(TAG, "onNext:: " + t.toString());

    return onSubscribe;
How do I make Espresso wait until Data Binding has updated the View with the data-model?

How do I make Espresso wait until Data Binding has updated the View with the data-model?

By : Thomas Schmid
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further Espresso does waitForIdle before executing view checks. waitForIdle goes thought IdlingRegistry and waits until every IdlingResource is idle.
LoopingIdlingResource is used in Espresso by default. It waits until looper doesn't have messages in queue, which means that it is idle.
code :
val dataBindingIdlingResourceRule = DataBindingIdlingResourceRule(activityRule)
Is it possible to use Espresso's IdlingResource to wait until a certain view appears?

Is it possible to use Espresso's IdlingResource to wait until a certain view appears?

By : Rocky Medure
Date : March 29 2020, 07:55 AM
To fix this issue In my test I have a stage where after pressing a button application does a lot of asynchronous calculations and requests to the cloud service, after which it displays a certain view. , Your IdlingResource could look like this:
code :
import android.support.test.espresso.IdlingResource;
import android.support.test.espresso.ViewFinder;
import android.support.test.espresso.ViewInteraction;
import android.view.View;

import org.hamcrest.Matcher;

import java.lang.reflect.Field;

import static android.support.test.espresso.Espresso.onView;

public class ViewShownIdlingResource implements IdlingResource {

    private static final String TAG = ViewShownIdlingResource.class.getSimpleName();

    private final Matcher<View> viewMatcher;
    private ResourceCallback resourceCallback;

    public ViewShownIdlingResource(final Matcher<View> viewMatcher) {
        this.viewMatcher = viewMatcher;

    public boolean isIdleNow() {
        View view = getView(viewMatcher);
        boolean idle = view == null || view.isShown();

        if (idle && resourceCallback != null) {

        return idle;

    public void registerIdleTransitionCallback(ResourceCallback resourceCallback) {
        this.resourceCallback = resourceCallback;

    public String getName() {
        return this + viewMatcher.toString();

    private static View getView(Matcher<View> viewMatcher) {
        try {
            ViewInteraction viewInteraction = onView(viewMatcher);
            Field finderField = viewInteraction.getClass().getDeclaredField("viewFinder");
            ViewFinder finder = (ViewFinder) finderField.get(viewInteraction);
            return finder.getView();
        } catch (Exception e) {
            return null;
public void waitViewShown(Matcher<View> matcher) {
    IdlingResource idlingResource = new ViewShownIdlingResource(matcher);///
    try {
    } finally {
public void someTest() {

    //do whatever verification needed afterwards    
Espresso does not wait for animation to finish assertion faills

Espresso does not wait for animation to finish assertion faills

By : Felix Ouma
Date : March 29 2020, 07:55 AM
I hope this helps . Most of the resources that I've found (like the one above) links to a dead page.
I found this blog post but it also links to the dead link above as well, but it proved useful because it provides step by step instructions on how to set it up.
Related Posts Related Posts :
  • Android: Add view onclick after the view itself
  • Set zoom for Webview
  • how to add item to Spinner's ArrayAdapter?
  • Android - Vertical layout only
  • MP3 Decoding on Android
  • How do you set tab view to scroll?
  • Set List View Size Android
  • Embedding ads on Android app?
  • Any receiver for sent SMS messages?
  • View the Task's activity stack
  • Move a little image over the screen
  • What is Android's file system?
  • Trying to get Package Version Information to display in an "About" message
  • Click in a ListView item changes status of elements inside the item?
  • Android: Accessing assets folder sqlite database file with .sqlite extension
  • Android HttpClient and HTTPS
  • How do we get Polygon Antialiasing in OpenGL ES on Android 1.5?
  • Is decreasing size of .png files have some effect to resulted Bitmap in memory
  • When Running android app I get ADB error
  • How to finish series of open sub-activities from one activity?
  • ClassCastException: com.android.internal.telephony.PhoneProxy
  • Remove item from todoList
  • Android: OutOfMemoryError while uploading video - how best to chunk?
  • How to serialize a Bundle?
  • How to do a fadein of an image on an Android Activity screen?
  • How can I disable a view behind my SlidingDrawer in Android?
  • How to scale/resize text to fit a TextView?
  • Android ProgressDialog Progress Bar doing things in the right order
  • Using hebrew with the android emulator
  • Can I force the Android Back button to go two steps back in the Activity stack?
  • Displaying popup images on button click
  • getting playlist of stations for internet radio application in android
  • Android SDK not updating the installed packages
  • GPS timeout in android
  • Android - Fail to connect to camera
  • Android: Get the scroll position of a WebView
  • How to disable double click event on radio button?
  • Android OpenAL?
  • Sending Email in Android using JavaMail API without using the default android app
  • Using WebView setHttpAuthUsernamePassword?
  • what is the difference between sendStickyBroadcast and sendBroadcast in Android
  • SocketException (The system call was cancelled)
  • How does ImageView just redraw part of its content when invalidate(Rect) is called?
  • Android Image Orientation Issue on Motorola Droid
  • Android paid applications
  • Android - TimePicker minutes to 15
  • ListView with images and text
  • Is it possible to write an Android broadcast receiver that detects when the phone wakes up?
  • How to resolve Android class issues: android.Manifest$permission and android.R?
  • Including Android Activities (and their layouts) in JAR files
  • How to submit android app for facebook review?
  • Circular Overlay of Video on Another Video using FFMPEG in Android
  • How Do We Get SpannedString Objects From String Resources Using Data Binding?
  • Is it possible to pull a webpage or content from the web into a widget on the android home screen?
  • No field host in class Ljava/net/URL
  • Android beginner: Touch events in android gridview
  • What adapter to use for ExpandableListView with non-TextView views?
  • Android WebView shows a blank page
  • Showing Live Wallpaper in a 1.6 target app by detecting if it's a 2.1 device?
  • Width of a scroll bar in android
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk