public final class ViewMatchers
extends Object
java.lang.Object | |
↳ | android.support.test.espresso.matcher.ViewMatchers |
与 View
s匹配的Hamcrest匹配器集合。
Nested classes |
|
---|---|
枚举 |
ViewMatchers.Visibility 枚举View.getVisibility()的可能值列表。 |
Public methods |
|
---|---|
static <T> void |
assertThat(String message, T actual, Matcher<T> matcher) MatcherAssert.assert替换为很好地呈现View对象。 |
static <T> void |
assertThat(T actual, Matcher<T> matcher) MatcherAssert.assert替换为很好地呈现View对象。 |
static Matcher<View> |
hasContentDescription() |
static Matcher<View> |
hasDescendant(Matcher<View> descendantMatcher) 根据视图层次结构中存在的后代,返回匹配 |
static Matcher<View> |
hasErrorText(String expectedError) 根据编辑文本错误字符串值返回匹配 |
static Matcher<View> |
hasErrorText(Matcher<String> stringMatcher) 根据编辑文本错误字符串值返回匹配 |
static Matcher<View> |
hasFocus() 返回匹配 |
static Matcher<View> |
hasImeAction(int imeAction) 返回匹配支持输入方法的视图的匹配器(例如, |
static Matcher<View> |
hasImeAction(Matcher<Integer> imeActionMatcher) 返回匹配支持输入方法的视图的匹配器(例如, |
static Matcher<View> |
hasLinks() 返回匹配具有链接的 |
static Matcher<View> |
hasSibling(Matcher<View> siblingMatcher) |
static Matcher<View> |
isAssignableFrom(Class<? extends View> clazz) 返回与所提供的类的实例或子类相匹配的Views的匹配器。 |
static Matcher<View> |
isChecked() 返回当且仅当视图是CompoundButton(或子类型)并处于选中状态时接受的匹配器。 |
static Matcher<View> |
isClickable() 返回与可点击的 |
static Matcher<View> |
isCompletelyDisplayed() 返回一个匹配器,它只接受一个视图,该视图的高度和宽度完全适合该视图的当前显示区域。 |
static Matcher<View> |
isDescendantOfA(Matcher<View> ancestorMatcher) 根据给定的祖先类型返回匹配 |
static Matcher<View> |
isDisplayed() 返回与当前显示在屏幕上的 |
static Matcher<View> |
isDisplayingAtLeast(int areaPercentage) 返回接受视图的匹配器,只要该视图区域的给定百分比不被任何其他视图遮挡并因此对用户可见即可。 |
static Matcher<View> |
isEnabled() 返回与匹配的 |
static Matcher<View> |
isFocusable() 返回匹配 |
static Matcher<View> |
isJavascriptEnabled() 如果他们正在评估Javascript,则返回匹配 |
static Matcher<View> |
isNotChecked() 返回当且仅当视图是CompoundButton(或子类型)且未处于选中状态的匹配器。 |
static Matcher<View> |
isRoot() 返回匹配根 |
static Matcher<View> |
isSelected() 返回匹配选中的 |
static Matcher<View> |
supportsInputMethods() 返回匹配支持输入方法的视图的匹配器。 |
static Matcher<View> |
withChild(Matcher<View> childMatcher) 当且仅当视图的子项被提供的匹配器接受时才返回true的匹配器。 |
static Matcher<View> |
withClassName(Matcher<String> classNameMatcher) 返回与匹配给定匹配器的类名匹配的视图的匹配器。 |
static Matcher<View> |
withContentDescription(int resourceId) |
static Matcher<View> |
withContentDescription(String text) |
static Matcher<View> |
withContentDescription(Matcher<? extends CharSequence> charSequenceMatcher) |
static Matcher<View> |
withEffectiveVisibility(ViewMatchers.Visibility visibility) |
static Matcher<View> |
withHint(Matcher<String> stringMatcher) 根据提示属性值返回匹配 |
static Matcher<View> |
withHint(int resourceId) 返回匹配 |
static Matcher<View> |
withHint(String hintText) 根据它的提示属性值返回匹配 |
static Matcher<View> |
withId(Matcher<Integer> integerMatcher) 根据资源ID返回匹配 |
static Matcher<View> |
withId(int id) 与withId(is(int))相同,但尝试查找给定ID的资源名称并使用describeTo使用R.id.myView样式描述。 |
static Matcher<View> |
withInputType(int inputType) 返回匹配 |
static Matcher<View> |
withParent(Matcher<View> parentMatcher) 当且仅当视图的父项被提供的匹配器接受时才接受视图的匹配器。 |
static Matcher<View> |
withResourceName(String name) 根据资源ID名称返回匹配 |
static Matcher<View> |
withResourceName(Matcher<String> stringMatcher) 根据资源ID名称返回匹配 |
static Matcher<View> |
withSpinnerText(int resourceId) 返回匹配 |
static Matcher<View> |
withSpinnerText(String text) 根据所选项目的toString值返回匹配 |
static Matcher<View> |
withSpinnerText(Matcher<String> stringMatcher) 根据所选项目的toString值返回匹配 |
static Matcher<View> |
withTagKey(int key) 返回基于标签键匹配 |
static Matcher<View> |
withTagKey(int key, Matcher<Object> objectMatcher) 根据标签键返回匹配 |
static Matcher<View> |
withTagValue(Matcher<Object> tagValueMatcher) 根据标签属性值返回匹配 |
static Matcher<View> |
withText(Matcher<String> stringMatcher) 根据文本属性值返回匹配 |
static Matcher<View> |
withText(String text) 根据文本属性值返回匹配 |
static Matcher<View> |
withText(int resourceId) 返回匹配 |
Inherited methods |
|
---|---|
From class java.lang.Object
|
void assertThat (String message, T actual, Matcher<T> matcher)
MatcherAssert.assert替换为很好地呈现View对象。
Parameters | |
---|---|
message |
String : the message to display. |
actual |
T : the actual value. |
matcher |
Matcher : a matcher that accepts or rejects actual. |
void assertThat (T actual, Matcher<T> matcher)
MatcherAssert.assert替换为很好地呈现View对象。
Parameters | |
---|---|
actual |
T : the actual value. |
matcher |
Matcher : a matcher that accepts or rejects actual. |
Matcher<View> hasContentDescription ()
Returns | |
---|---|
Matcher<View> |
Matcher<View> hasDescendant (Matcher<View> descendantMatcher)
根据其视图层次结构中存在的后代,返回匹配 View
的匹配器。
Parameters | |
---|---|
descendantMatcher |
Matcher : the type of the descendant to match on |
Returns | |
---|---|
Matcher<View> |
Matcher<View> hasErrorText (String expectedError)
根据编辑文本错误字符串值返回匹配 EditText
的匹配器。
注意:Sugar for hasErrorText(is(“string”))。
Parameters | |
---|---|
expectedError |
String
|
Returns | |
---|---|
Matcher<View> |
Matcher<View> hasErrorText (Matcher<String> stringMatcher)
根据编辑文本错误字符串值返回匹配 EditText
的匹配器。
Parameters | |
---|---|
stringMatcher |
Matcher
|
Returns | |
---|---|
Matcher<View> |
Matcher<View> hasImeAction (int imeAction)
返回匹配支持输入法(例如EditText)的视图的匹配器,并在其 EditorInfo
设置指定的IME操作。
Parameters | |
---|---|
imeAction |
int : the IME action to match |
Returns | |
---|---|
Matcher<View> |
Matcher<View> hasImeAction (Matcher<Integer> imeActionMatcher)
返回匹配支持输入法(例如EditText)的视图的匹配器,并在其 EditorInfo
设置指定的IME操作。
Parameters | |
---|---|
imeActionMatcher |
Matcher : a matcher for the IME action |
Returns | |
---|---|
Matcher<View> |
Matcher<View> hasSibling (Matcher<View> siblingMatcher)
根据他们的兄弟姐妹返回与View匹配的View
。
当一个视图不能在诸如文本或R.id之类的属性上唯一选择时,这可能特别有用。 例如:呼叫按钮在联系人布局中重复多次,区分呼叫按钮视图的唯一方式是旁边显示的内容(例如联系人的唯一名称)。
Parameters | |
---|---|
siblingMatcher |
Matcher : a Matcher for the sibling of the view. |
Returns | |
---|---|
Matcher<View> |
Matcher<View> isAssignableFrom (Class<? extends View> clazz)
返回与所提供的类的实例或子类相匹配的Views的匹配器。 Hamcrest的一些版本使得这个噩梦的通用打字,所以我们有一个特殊情况为我们的用户。
Parameters | |
---|---|
clazz |
Class
|
Returns | |
---|---|
Matcher<View> |
Matcher<View> isChecked ()
返回当且仅当视图是CompoundButton(或子类型)并处于选中状态时接受的匹配器。
Returns | |
---|---|
Matcher<View> |
Matcher<View> isCompletelyDisplayed ()
返回一个匹配器,它只接受一个视图,该视图的高度和宽度完全适合该视图的当前显示区域。 存在视图(例如ScrollViews),其高度和宽度都大于设计的物理设备屏幕。 这些视图将不会完全显示。
Returns | |
---|---|
Matcher<View> |
Matcher<View> isDescendantOfA (Matcher<View> ancestorMatcher)
根据给定的祖先类型返回匹配 View
的匹配器。
Parameters | |
---|---|
ancestorMatcher |
Matcher : the type of the ancestor to match on |
Returns | |
---|---|
Matcher<View> |
Matcher<View> isDisplayed ()
返回与当前屏幕上显示的View
匹配的匹配器给用户。 注:isDisplayed将选择部分显示的视图(例如:视图的全高/宽度大于可见矩形的高度/宽度)。 如果您希望确保将此视图绘制的整个矩形显示给用户,请使用isCompletelyDisplayed。
Returns | |
---|---|
Matcher<View> |
Matcher<View> isDisplayingAtLeast (int areaPercentage)
返回接受视图的匹配器,只要该视图区域的给定百分比不被任何其他视图遮挡并因此对用户可见即可。
Parameters | |
---|---|
areaPercentage |
int : an integer ranging from (0, 100] indicating how much percent of the surface area of the view must be shown to the user to be accepted. |
Returns | |
---|---|
Matcher<View> |
Matcher<View> isJavascriptEnabled ()
如果他们正在评估Javascript,则返回匹配 WebView
的匹配器。
Returns | |
---|---|
Matcher<View> |
Matcher<View> isNotChecked ()
返回当且仅当视图是CompoundButton(或子类型)且未处于选中状态的匹配器。
Returns | |
---|---|
Matcher<View> |
Matcher<View> supportsInputMethods ()
返回匹配支持输入方法的视图的匹配器。
Returns | |
---|---|
Matcher<View> |
Matcher<View> withChild (Matcher<View> childMatcher)
当且仅当视图的子项被提供的匹配器接受时才返回true的匹配器。
Parameters | |
---|---|
childMatcher |
Matcher : the matcher to apply on the child views. |
Returns | |
---|---|
Matcher<View> |
Matcher<View> withClassName (Matcher<String> classNameMatcher)
返回与匹配给定匹配器的类名匹配的视图的匹配器。
Parameters | |
---|---|
classNameMatcher |
Matcher
|
Returns | |
---|---|
Matcher<View> |
Matcher<View> withContentDescription (int resourceId)
Parameters | |
---|---|
resourceId |
int : the resource id of the content description to match on. |
Returns | |
---|---|
Matcher<View> |
Matcher<View> withContentDescription (String text)
根据内容描述属性值返回与View匹配的View
。 withContentDescription(is(“string”))。
Parameters | |
---|---|
text |
String : the text to match on. |
Returns | |
---|---|
Matcher<View> |
Matcher<View> withContentDescription (Matcher<? extends CharSequence> charSequenceMatcher)
Parameters | |
---|---|
charSequenceMatcher |
Matcher : a CharSequence Matcher for the content description |
Returns | |
---|---|
Matcher<View> |
Matcher<View> withEffectiveVisibility (ViewMatchers.Visibility visibility)
返回匹配View
s的“有效”可见性设置为给定值的匹配器。 有效的可视性不仅考虑到视图的可见性值,还考虑其祖先的可见性值。 在View.VISIBLE的情况下,这意味着该视图及其所有祖先的可见性=可见。 在GONE和INVISIBLE的情况下,情况正好相反 - 任何GONE或INVISIBLE父母都会让其所有孩子都有其有效的知名度。
注意:与名称相反,视图可见性不直接转换为视图是否显示在屏幕上(使用isDisplayed())。 例如,视图及其所有祖先可以具有可见性=可见性,但视图可能需要滚动以实际上对用户可见。 除非您专门针对测试的可见性值,否则请使用isDisplayed。
Parameters | |
---|---|
visibility |
ViewMatchers.Visibility
|
Returns | |
---|---|
Matcher<View> |
Matcher<View> withHint (Matcher<String> stringMatcher)
根据提示属性值返回匹配TextView
的匹配器。 注意:视图的提示属性可以为空。
Parameters | |
---|---|
stringMatcher |
Matcher : Matcher of String with text to match |
Returns | |
---|---|
Matcher<View> |
Matcher<View> withHint (int resourceId)
返回匹配 TextView
后代的匹配器,该匹配器显示与给定资源ID关联的提示。
Parameters | |
---|---|
resourceId |
int : the string resource the text view is expected to have as a hint. |
Returns | |
---|---|
Matcher<View> |
Matcher<View> withHint (String hintText)
根据它的提示属性值返回匹配TextView
的匹配器。 注意:用于withHint的视图的Sugar(是(“string”))。
Parameters | |
---|---|
hintText |
String : String with the hint text to match |
Returns | |
---|---|
Matcher<View> |
Matcher<View> withId (Matcher<Integer> integerMatcher)
根据资源ID返回匹配View
的匹配器。 注意:Android资源ID不保证是唯一的。 您可能必须将此匹配器与另一匹配器配对才能保证独特的视图选择。
Parameters | |
---|---|
integerMatcher |
Matcher : a Matcher for resource ids |
Returns | |
---|---|
Matcher<View> |
Matcher<View> withId (int id)
与withId(is(int))相同,但尝试查找给定ID的资源名称并使用describeTo使用R.id.myView样式描述。 如果资源查找不可用,则在调用describeTo时,将打印出一个简单的“with id:%d”。 如果资源查找可用,但查找给定ID的名称失败,则将返回“with id:%d(资源名称未找到)”作为描述。
Parameters | |
---|---|
id |
int : the resource id. |
Returns | |
---|---|
Matcher<View> |
Matcher<View> withInputType (int inputType)
返回匹配 InputType
的匹配器。
Parameters | |
---|---|
inputType |
int
|
Returns | |
---|---|
Matcher<View> |
Matcher<View> withParent (Matcher<View> parentMatcher)
当且仅当视图的父项被提供的匹配器接受时才接受视图的匹配器。
Parameters | |
---|---|
parentMatcher |
Matcher : the matcher to apply on getParent. |
Returns | |
---|---|
Matcher<View> |
Matcher<View> withResourceName (String name)
根据资源ID名称返回匹配 View
的匹配器(例如,channel_avatar)。
Parameters | |
---|---|
name |
String : the resource id name |
Returns | |
---|---|
Matcher<View> |
Matcher<View> withResourceName (Matcher<String> stringMatcher)
根据资源ID名称返回匹配 View
的匹配器(例如,channel_avatar)。
Parameters | |
---|---|
stringMatcher |
Matcher : a Matcher for resource id names |
Returns | |
---|---|
Matcher<View> |
Matcher<View> withSpinnerText (int resourceId)
返回匹配 Spinner
后代的匹配器,该后代显示与给定资源ID关联的选定项的字符串。
Parameters | |
---|---|
resourceId |
int : the string resource the text view is expected to hold. |
Returns | |
---|---|
Matcher<View> |
Matcher<View> withSpinnerText (String text)
根据所选项目的toString值返回匹配 Spinner
的匹配器。
注意:Sugar for withSpinnerText(是(“string”))。
Parameters | |
---|---|
text |
String
|
Returns | |
---|---|
Matcher<View> |
Matcher<View> withSpinnerText (Matcher<String> stringMatcher)
根据所选项目的toString值返回匹配 Spinner
的匹配器。
Parameters | |
---|---|
stringMatcher |
Matcher : Matcher of String with text to match. |
Returns | |
---|---|
Matcher<View> |
Matcher<View> withTagKey (int key)
根据标签键返回匹配 View
的匹配器。
Parameters | |
---|---|
key |
int : to match |
Returns | |
---|---|
Matcher<View> |
Matcher<View> withTagKey (int key, Matcher<Object> objectMatcher)
根据标签键返回匹配 View
的匹配器。
Parameters | |
---|---|
key |
int : to match |
objectMatcher |
Matcher : Object to match |
Returns | |
---|---|
Matcher<View> |
Matcher<View> withTagValue (Matcher<Object> tagValueMatcher)
根据标签属性值返回匹配 View
的匹配器。
Parameters | |
---|---|
tagValueMatcher |
Matcher : a Matcher for the view's tag property value |
Returns | |
---|---|
Matcher<View> |
Matcher<View> withText (Matcher<String> stringMatcher)
根据文本属性值返回匹配TextView
的匹配器。 注意:视图的文本属性不会为空。 如果你设置了文本(null),它仍然是“”。 不要使用空匹配器。
Parameters | |
---|---|
stringMatcher |
Matcher : Matcher of String with text to match |
Returns | |
---|---|
Matcher<View> |
Matcher<View> withText (String text)
根据文本属性值返回匹配TextView
的匹配器。 注意:视图的Sugar for withText(是(“string”))。
Parameters | |
---|---|
text |
String : String with the text to match |
Returns | |
---|---|
Matcher<View> |
Matcher<View> withText (int resourceId)
返回匹配 TextView
后代的匹配器,该后代显示与给定资源ID关联的字符串。
Parameters | |
---|---|
resourceId |
int : the string resource the text view is expected to hold. |
Returns | |
---|---|
Matcher<View> |