2017-03-08 27 views

回答

7

我不認爲這是可能的方式,這取決於你想要什麼,我會使用自定義匹配:

public static Matcher<View> hasNoErrorText() { 
    return new BoundedMatcher<View, EditText>(EditText.class) { 

     @Override 
     public void describeTo(Description description) { 
      description.appendText("has no error text: "); 
     } 

     @Override 
     protected boolean matchesSafely(EditText view) { 
      return view.getError() == null; 
     } 
    }; 
} 

這個匹配可以檢查一個EditText沒有任何錯誤文本集,像這樣使用它:

onView(allOf(withId(R.id.edittext), isDisplayed())).check(matches(hasNoErrorText())); 
相關問題