title: Wait until view become visible with IdleResource
body: <p>I am writing Instrumentation tests with usage of Espresso 2.2.</p>
  
  <p>Flow I want to test:</p>
  
  <ol>
  <li>radioButton clicked by test</li>
  <li>onClick launches request to API</li>
  <li>after every time different time I receive response</li>
  <li>positive response triggers interface method that is called in activity</li>
  <li>onRequestSuccess I am making additional panel on screen named vSetupAmount visible</li>
  </ol>
  
  <p>I want to register IdleResource after click on radioButton so it waits until vSetupAmount becomes visible. But I can't make it work. Please tell me what am I doing wrong.</p>
  
  <p>I have written such IdleResource:</p>
  
  <pre><code>public class AmountViewIdlingResource implements IdlingResource {
  
      private CountriesAndRatesActivity activity;
      private ResourceCallback callback;
  
      private SetupAmountView amountView;
  
      public AmountViewIdlingResource(CountriesAndRatesActivity activity) {
          this.activity = activity;
  
          amountView = (SetupAmountView) this.activity.findViewById(R.id.vSetupAmount);
      }
  
      @Override public String getName() {
          return "Amount View idling resource";
      }
  
      @Override public boolean isIdleNow() {
          callback.onTransitionToIdle();
          return amountView.getVisibility() == View.VISIBLE;
      }
  
      @Override public void registerIdleTransitionCallback(ResourceCallback resourceCallback) {
          this.callback = resourceCallback;
      }
  
  }
  </code></pre>
  
  <p>So I am passing activity to IdleResource, link view with variable. I understand that IdleResource won't let test go through until isIdleNow() returns value true. So if view is View.GONE then it won't go further. </p>
  
  <p>How it looks in test:</p>
  
  <pre><code>    // click of radioButton picked from radioGroup
      onView(withId(rgDeliveries.getChildAt(id).getId())).perform(scrollTo(), click());
  
      // wait for view to become visible
      Espresso.registerIdlingResources(new AmountViewIdlingResource(getActivity()));
  
      // go to button on view
      onView(withId(R.id.btnGetStarted)).perform(scrollTo());
  
      // unregister idle resource
      for (  IdlingResource resource : getIdlingResources()) {
          Espresso.unregisterIdlingResources(resource);
      }
  </code></pre>
  
  <p>So I get my click on radioButton. IdleResource is successfully registered but nothing happens. On my device API response comes. vSetupAmount is being displayed but </p>
  
  <pre><code>amountView.getVisibility() == View.VISIBLE;
  </code></pre>
  
  <p>which is being checked forever (but I see my view on screen) always returns false. </p>
  
  <p>What am I doing wrong?</p>