title: Espresso: Test TextInputLayout PasswordVisibilityToggle button
body: <p>Good day, am getting to grips with espresso and am trying to check if the PasswordVisibilityToggleEnabled button of a TextInputLayout is visible or not. I know this button is a CheckableImageButton with the id (<code>R.id.text_input_password_toggle)</code> but not sure how to get it in Espresso.</p>
  
  <p>I tried doing this:</p>
  
  <pre><code>onView(withId(R.id.passwordTextInputLayout)).check(hasDescendant(withId(R.id.text_input_password_toggle))).check(matches(not(isDisplayed())));
  </code></pre>
  
  <p>But this is not working. I guessed i might have to use a custom Matcher based on a few questions on StackOverflow but am not sure if am doing that correctly.</p>
  
  <pre><code>public static Matcher&lt;View&gt; getPasswordToggleView(final Matcher&lt;View&gt; parentMatcher, int id) {
      return new TypeSafeMatcher&lt;View&gt;() {
          @Override
          protected boolean matchesSafely(View view) {
              if(!(view.getParent() instanceof ViewGroup)) {
                  return parentMatcher.matches(view.getParent());
              }
  
              ViewGroup group = (ViewGroup) view.getParent();
              return  parentMatcher.matches(view.getParent()) &amp;&amp; view.getId() == id;
          }
  
          @Override
          public void describeTo(Description description) {
              description.appendText("get View with matching id");
          }
      };
  }
  </code></pre>
  
  <p>and try to use it like this but still not working:</p>
  
  <pre><code> onView(getPasswordToggleView(withId(R.id.passwordTextInputLayout), R.id.text_input_password_toggle)).check(matches(not(isDisplayed())));
  </code></pre>
  
  <p>Any thoughts?</p>