ViewActions

public final class ViewActions
extends Object

java.lang.Object
   ↳ android.support.test.espresso.action.ViewActions


常见的 ViewActions的集合。

Summary

Public methods

static ViewAction actionWithAssertions(ViewAction viewAction)

在此类中的 ViewAction之前执行所有断言,然后执行给定的 ViewAction

static void addGlobalAssertion(String name, ViewAssertion viewAssertion)

每次执行 ViewAction中的 ViewAction ,都会添加一个 ViewAssertion

static void clearGlobalAssertions()
static ViewAction clearText()

返回清除视图上文本的操作。

static ViewAction click()

返回单击视图的操作。

static ViewAction click(ViewAction rollbackAction)

返回在视图上执行一次单击的操作。

static ViewAction closeSoftKeyboard()

返回关闭软键盘的操作。

static ViewAction doubleClick()

返回一个双击视图的操作。

static ViewAction longClick()

返回长时间点击视图的操作。

static ViewAction openLink(Matcher<String> linkTextMatcher, Matcher<Uri> uriMatcher)

返回一个操作,该操作可打开与给定链接文本和uri匹配器匹配的链接。

static ViewAction openLinkWithText(String linkText)

openLinkWithText(Matcher<String> linkTextMatcher)相同,但使用 is(linkText)作为linkTextMatcher。

static ViewAction openLinkWithText(Matcher<String> linkTextMatcher)

openLink(Matcher<String> linkTextMatcher, Matcher<Uri> uriMatcher)相同,但使用 any(Uri.class)作为uriMatcher。

static ViewAction openLinkWithUri(String uri)

openLinkWithUri(Matcher<Uri> uriMatcher)相同,但使用 is(uri)作为uriMatcher。

static ViewAction openLinkWithUri(Matcher<Uri> uriMatcher)

openLink(Matcher<String> linkTextMatcher, Matcher<Uri> uriMatcher)相同,但使用 any(String.class)作为linkTextMatcher。

static ViewAction pressBack()

返回单击后退按钮的操作。

static ViewAction pressImeActionButton()

返回按下IME(输入法编辑器)上的当前操作按钮(下一步,完成,搜索等)的操作。

static ViewAction pressKey(int keyCode)

返回按下由keyCode指定的键的操作(例如,

static ViewAction pressKey(EspressoKey key)

返回一个操作,该操作用指定的修饰符按下指定的键。

static ViewAction pressMenuKey()

返回按下硬件菜单键的操作。

static void removeGlobalAssertion(ViewAssertion viewAssertion)

从执行操作之前要运行的一组断言中删除给定的断言。

static ViewAction replaceText(String stringToBeSet)

返回更新视图的文本属性的操作。

static ViewAction scrollTo()

返回滚动到视图的操作。

static ViewAction swipeDown()

返回在视图的水平中心上执行从顶部到底部滑动的操作。

static ViewAction swipeLeft()

返回在视图的垂直中心上从右向左滑动的操作。

static ViewAction swipeRight()

返回在视图的垂直中心上执行从左到右滑动的操作。

static ViewAction swipeUp()

返回一个操作,该操作在视图的水平中心上执行从底部到顶部的滑动操作。

static ViewAction typeText(String stringToBeTyped)

返回一个选择视图的动作(通过点击它)并将提供的字符串输入到视图中。

static ViewAction typeTextIntoFocusedView(String stringToBeTyped)

返回一个将提供的字符串输入到视图中的操作。

Inherited methods

From class java.lang.Object

Public methods

actionWithAssertions

ViewAction actionWithAssertions (ViewAction viewAction)

在此类中的 ViewAction之前执行所有断言,然后执行给定的 ViewAction

Parameters
viewAction ViewAction: the ViewAction to perform after the assertions
Returns
ViewAction

addGlobalAssertion

void addGlobalAssertion (String name, 
                ViewAssertion viewAssertion)

每次执行ViewAction中的ViewAction ,都会添加一个ViewAssertion 断言将在执行操作之前运行。

Parameters
name String: a name of the assertion to be added
viewAssertion ViewAssertion: a ViewAssertion to be added
Throws
IllegalArgumentException if the name/viewAssertion pair is already contained in the global assertions.

clearGlobalAssertions

void clearGlobalAssertions ()

clearText

ViewAction clearText ()

返回清除视图上文本的操作。

查看约束:

click

ViewAction click ()

返回单击视图的操作。

查看约束:

click

ViewAction click (ViewAction rollbackAction)

返回在视图上执行一次单击的操作。 如果点击时间长于“长按”时间(可能),则在视图上调用所提供的回滚操作,并再次尝试点击。 这只有当点击的视图对于长按与普通敲击有不同的行为时才是必要的。 例如 - 如果长按一个特定的视图元素打开一个弹出菜单 - ViewActions.pressBack()可能是一个可接受的回滚操作。
查看约束:

closeSoftKeyboard

ViewAction closeSoftKeyboard ()

返回关闭软键盘的操作。 如果键盘已经关闭,则它是无操作的。

Returns
ViewAction

doubleClick

ViewAction doubleClick ()

返回一个双击视图的操作。

查看先决条件:

longClick

ViewAction longClick ()

返回长时间点击视图的操作。

查看先决条件:

openLink

ViewAction openLink (Matcher<String> linkTextMatcher, 
                Matcher<Uri> uriMatcher)

返回一个操作,该操作可打开与给定链接文本和uri匹配器匹配的链接。 该操作通过调用链接的onClick方法来执行(而不是在屏幕上实际发出点击)。

查看先决条件:

openLinkWithText

ViewAction openLinkWithText (String linkText)

openLinkWithText(Matcher<String> linkTextMatcher)相同,但使用 is(linkText)作为linkTextMatcher。

Parameters
linkText String
Returns
ViewAction

openLinkWithText

ViewAction openLinkWithText (Matcher<String> linkTextMatcher)

openLink(Matcher<String> linkTextMatcher, Matcher<Uri> uriMatcher)相同,但使用 any(Uri.class)作为uriMatcher。

Parameters
linkTextMatcher Matcher
Returns
ViewAction

openLinkWithUri

ViewAction openLinkWithUri (String uri)

openLinkWithUri(Matcher<Uri> uriMatcher)相同,但使用 is(uri)作为uriMatcher。

Parameters
uri String
Returns
ViewAction

openLinkWithUri

ViewAction openLinkWithUri (Matcher<Uri> uriMatcher)

openLink(Matcher<String> linkTextMatcher, Matcher<Uri> uriMatcher)相同,但使用 any(String.class)作为linkTextMatcher。

Parameters
uriMatcher Matcher
Returns
ViewAction

pressBack

ViewAction pressBack ()

返回单击后退按钮的操作。

Returns
ViewAction

pressImeActionButton

ViewAction pressImeActionButton ()

返回按下IME(输入法编辑器)上的当前操作按钮(下一步,完成,搜索等)的操作。 所选视图将调用onEditorAction方法。

Returns
ViewAction

pressKey

ViewAction pressKey (int keyCode)

返回按下由keyCode指定的键的操作(例如,Keyevent.KEYCODE_BACK)。

Parameters
keyCode int
Returns
ViewAction

pressKey

ViewAction pressKey (EspressoKey key)

返回一个操作,该操作用指定的修饰符按下指定的键。

Parameters
key EspressoKey
Returns
ViewAction

pressMenuKey

ViewAction pressMenuKey ()

返回按下硬件菜单键的操作。

Returns
ViewAction

removeGlobalAssertion

void removeGlobalAssertion (ViewAssertion viewAssertion)

从执行操作之前要运行的一组断言中删除给定的断言。

Parameters
viewAssertion ViewAssertion: the assertion to remove
Throws
IllegalArgumentException if the name/viewAssertion pair is not already contained in the global assertions.

replaceText

ViewAction replaceText (String stringToBeSet)

返回更新视图的文本属性的操作。

查看先决条件:

scrollTo

ViewAction scrollTo ()

返回滚动到视图的操作。

查看先决条件:

swipeDown

ViewAction swipeDown ()

返回在视图的水平中心上执行从顶部到底部滑动的操作。 滑动并不从视图的边缘开始,但有一点偏移。

查看约束:

swipeLeft

ViewAction swipeLeft ()

返回在视图的垂直中心上从右向左滑动的操作。 滑动并不是从视图的边缘开始,而是有点偏移。

查看约束:

swipeRight

ViewAction swipeRight ()

返回在视图的垂直中心上执行从左到右滑动的操作。 滑动并不是从视图的边缘开始,而是有点偏移。

查看约束:

swipeUp

ViewAction swipeUp ()

返回一个操作,该操作在视图的水平中心上执行从底部到顶部的滑动操作。 滑动并不从视图的边缘开始,但有一点偏移。

查看约束:

typeText

ViewAction typeText (String stringToBeTyped)

返回一个选择视图的动作(通过点击它)并将提供的字符串输入到视图中。 将\ n附加到字符串的末尾可转换为ENTER键事件。 注意:如果视图已经包含文本,则此方法会在输入之前对视图执行轻击操作以强制视图进入焦点,此轻击可将光标置于文本中的任意位置。

查看先决条件:

typeTextIntoFocusedView

ViewAction typeTextIntoFocusedView (String stringToBeTyped)

返回一个将提供的字符串输入到视图中的操作。 将\ n附加到字符串的末尾可转换为ENTER键事件。 注意:此方法不会改变焦点视图中的光标位置 - 文本插入到当前指针所在的位置。

查看先决条件: