2016-05-06 20 views
5

के साथ आप टेक्स्टिनपुटलाउट की त्रुटि को कैसे देख सकते हैं मैं एक टेक्स्ट इनपुटपुटआउट दृश्य के खिलाफ एक मैचर चलाने में सक्षम होना चाहता हूं जिसमें त्रुटि सेट है।एस्प्रेसो

onView(withId(R.id.myTextInputLayout)).check(matches(withText('myError'))); 

withTest() TextInputLayout त्रुटि संदेश के साथ काम नहीं कर रहा है। क्या कोई और जानता है कि यह कैसे करें?

आपकी मदद के लिए धन्यवाद।

उत्तर

3

बॉक्स के बाहर समर्थित दृश्यों का परीक्षण करने के लिए कस्टम व्यूमैचर लागू करें।

यहाँ TextInputLayout

public static Matcher<View> withErrorInInputLayout(final Matcher<String> stringMatcher) { 
    checkNotNull(stringMatcher); 

    return new BoundedMatcher<View, TextInputLayout>(TextInputLayout.class) { 
     String actualError = ""; 

     @Override 
     public void describeTo(Description description) { 
      description.appendText("with error: "); 
      stringMatcher.describeTo(description); 
      description.appendText("But got: " + actualText); 
     } 

     @Override 
     public boolean matchesSafely(TextInputLayout textInputLayout) { 
      CharSequence error = textInputLayout.getError(); 
      if (error != null) { 
       actualError = error.toString(); 
       return stringMatcher.matches(actualError); 
      } 
      return false; 
     } 
    }; 
} 

public static Matcher<View> withErrorInInputLayout(final String string) { 
    return withErrorInInputLayout(is(string)); 
} 
के लिए withError मिलान का एक उदाहरण दिया गया है
संबंधित मुद्दे