| java.lang.Object | |
| ↳ | androidx.test.espresso.action.ViewActions |
A collection of common ViewActions.
| Public Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
Performs all assertions before the
ViewActions in this class and then performs the
given ViewAction | |||||||||||
Adds a
ViewAssertion to be run every time a ViewAction in this class is
performed. | |||||||||||
Returns an action that clears text on the view.
| |||||||||||
Same as
click(int inputDevice, int buttonState), but uses SOURCE_UNKNOWN as the inputDevice and BUTTON_PRIMARY as the
buttonState. | |||||||||||
Returns an action that clicks the view for a specific input device and button state.
| |||||||||||
Returns an action that performs a single click on the view.
| |||||||||||
Returns an action that closes soft keyboard.
| |||||||||||
Returns an action that double clicks the view.
| |||||||||||
Returns an action that long clicks the view.
| |||||||||||
Returns an action that opens a link matching the given link text and uri matchers.
| |||||||||||
Same as
openLinkWithText(Matcher<String> linkTextMatcher), but uses is(linkText) as the linkTextMatcher. | |||||||||||
Same as
openLink(Matcher<String> linkTextMatcher, Matcher<Uri> uriMatcher), but uses
any(Uri.class) as the uriMatcher. | |||||||||||
Same as
openLinkWithUri(Matcher<Uri> uriMatcher), but uses is(uri) as the
uriMatcher. | |||||||||||
Same as
openLink(Matcher<String> linkTextMatcher, Matcher<Uri> uriMatcher), but uses
any(String.class) as the linkTextMatcher. | |||||||||||
Returns an action that clicks the back button.
| |||||||||||
Similar to
pressBack() but will not throw an exception when Espresso navigates
outside the application or process under test. | |||||||||||
Returns an action that presses the current action button (next, done, search, etc) on the IME
(Input Method Editor).
| |||||||||||
Returns an action that presses the specified key with the specified modifiers.
| |||||||||||
Returns an action that presses the key specified by the keyCode (eg.
| |||||||||||
Returns an action that presses the hardware menu key.
| |||||||||||
Removes the given assertion from the set of assertions to be run before actions are performed.
| |||||||||||
Returns an action that performs given
ViewAction on the view until view matches the
desired Matcher<View>. | |||||||||||
Returns an action that updates the text attribute of a view.
| |||||||||||
Returns an action that scrolls to the view.
| |||||||||||
Returns an action that performs a swipe top-to-bottom across the horizontal center of the view.
| |||||||||||
Returns an action that performs a swipe right-to-left across the vertical center of the view.
| |||||||||||
Returns an action that performs a swipe left-to-right across the vertical center of the view.
| |||||||||||
Returns an action that performs a swipe bottom-to-top across the horizontal center of the view.
| |||||||||||
Returns an action that selects the view (by clicking on it) and types the provided string into
the view.
| |||||||||||
Returns an action that types the provided string into the view.
| |||||||||||
|
[Expand]
Inherited Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
|
| |||||||||||
Performs all assertions before the ViewActions in this class and then performs the
given ViewAction
| Parameters | |
|---|---|
viewAction |
ViewAction: the ViewAction to perform after the assertions
|
| Returns | |
|---|---|
ViewAction |
|
Adds a ViewAssertion to be run every time a ViewAction in this class is
performed. The assertion will be run prior to performing the action.
| 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. |
Returns an action that clears text on the view.
View constraints:
| Returns | |
|---|---|
ViewAction |
|
Same as click(int inputDevice, int buttonState), but uses SOURCE_UNKNOWN as the inputDevice and BUTTON_PRIMARY as the
buttonState.
| Returns | |
|---|---|
ViewAction |
|
Returns an action that clicks the view for a specific input device and button state.
Note: Not supported by API < 14. An UnsupportedOperationException will be
thrown if called on API < 14. For API < 14, call click() instead.
View constraints:
| Parameters | |
|---|---|
inputDevice |
int: source input device of the click. Example: SOURCE_MOUSE |
buttonState |
int: buttonState associated with the click. Example: BUTTON_PRIMARY
|
| Returns | |
|---|---|
ViewAction |
|
Returns an action that performs a single click on the view.
If the click takes longer than the 'long press' duration (which is possible) the provided rollback action is invoked on the view and a click is attempted again.
This is only necessary if the view being clicked on has some different behaviour for long press versus a normal tap.
For example - if a long press on a particular view element opens a popup menu -
ViewActions.pressBack() may be an acceptable rollback action.
View constraints:
| Parameters | |
|---|---|
rollbackAction |
ViewAction |
| Returns | |
|---|---|
ViewAction |
|
Returns an action that closes soft keyboard. If the keyboard is already closed, it is a no-op.
| Returns | |
|---|---|
ViewAction |
|
Returns an action that double clicks the view.
View preconditions:
| Returns | |
|---|---|
ViewAction |
|
Returns an action that long clicks the view.
View preconditions:
| Returns | |
|---|---|
ViewAction |
|
Returns an action that opens a link matching the given link text and uri matchers. The action
is performed by invoking the link's onClick method (as opposed to actually issuing a click on
the screen).
View preconditions:
| Parameters | |
|---|---|
linkTextMatcher |
Matcher |
uriMatcher |
Matcher |
| Returns | |
|---|---|
ViewAction |
|
Same as openLinkWithText(Matcher<String> linkTextMatcher), but uses is(linkText) as the linkTextMatcher.
| Parameters | |
|---|---|
linkText |
String |
| Returns | |
|---|---|
ViewAction |
|
Same as openLink(Matcher<String> linkTextMatcher, Matcher<Uri> uriMatcher), but uses
any(Uri.class) as the uriMatcher.
| Parameters | |
|---|---|
linkTextMatcher |
Matcher |
| Returns | |
|---|---|
ViewAction |
|
Same as openLinkWithUri(Matcher<Uri> uriMatcher), but uses is(uri) as the
uriMatcher.
| Parameters | |
|---|---|
uri |
String |
| Returns | |
|---|---|
ViewAction |
|
Same as openLink(Matcher<String> linkTextMatcher, Matcher<Uri> uriMatcher), but uses
any(String.class) as the linkTextMatcher.
| Parameters | |
|---|---|
uriMatcher |
Matcher |
| Returns | |
|---|---|
ViewAction |
|
Returns an action that clicks the back button.
| Returns | |
|---|---|
ViewAction |
|
| Throws | |
|---|---|
PerformException |
if Espresso navigates outside the application or process under test. |
Similar to pressBack() but will not throw an exception when Espresso navigates
outside the application or process under test.
| Returns | |
|---|---|
ViewAction |
|
Returns an action that presses the current action button (next, done, search, etc) on the IME (Input Method Editor). The selected view will have its onEditorAction method called.
| Returns | |
|---|---|
ViewAction |
|
Returns an action that presses the specified key with the specified modifiers.
| Parameters | |
|---|---|
key |
EspressoKey |
| Returns | |
|---|---|
ViewAction |
|
Returns an action that presses the key specified by the keyCode (eg. Keyevent.KEYCODE_BACK).
| Parameters | |
|---|---|
keyCode |
int |
| Returns | |
|---|---|
ViewAction |
|
Returns an action that presses the hardware menu key.
| Returns | |
|---|---|
ViewAction |
|
Removes the given assertion from the set of assertions to be run before actions are performed.
| Parameters | |
|---|---|
viewAssertion |
ViewAssertion: the assertion to remove |
| Throws | |
|---|---|
IllegalArgumentException |
if the name/viewAssertion pair is not already contained in the global assertions. |
Returns an action that performs given ViewAction on the view until view matches the
desired Matcher<View>. It will repeat the given action until view matches the desired
Matcher<View> or PerformException will be thrown if given number of unsuccessful
attempts are made.
| Parameters | |
|---|---|
action |
ViewAction: action to be performed repeatedly |
desiredStateMatcher |
Matcher: action is performed repeatedly until view matches this view matcher |
maxAttempts |
int: max number of times for which this action to be performed if view doesn't
match the given view matcher
|
| Returns | |
|---|---|
ViewAction |
|
Returns an action that updates the text attribute of a view.
View preconditions:
| Parameters | |
|---|---|
stringToBeSet |
String |
| Returns | |
|---|---|
ViewAction |
|
Returns an action that scrolls to the view.
View preconditions:
| Returns | |
|---|---|
ViewAction |
|
Returns an action that performs a swipe top-to-bottom across the horizontal center of the view.
The swipe doesn't start at the very edge of the view, but has a bit of offset.
View constraints:
| Returns | |
|---|---|
ViewAction |
|
Returns an action that performs a swipe right-to-left across the vertical center of the view.
The swipe doesn't start at the very edge of the view, but is a bit offset.
View constraints:
| Returns | |
|---|---|
ViewAction |
|
Returns an action that performs a swipe left-to-right across the vertical center of the view.
The swipe doesn't start at the very edge of the view, but is a bit offset.
View constraints:
| Returns | |
|---|---|
ViewAction |
|
Returns an action that performs a swipe bottom-to-top across the horizontal center of the view.
The swipe doesn't start at the very edge of the view, but has a bit of offset.
View constraints:
| Returns | |
|---|---|
ViewAction |
|
Returns an action that selects the view (by clicking on it) and types the provided string into
the view. Appending a \n to the end of the string translates to a ENTER key event. Note: this
method performs a tap on the view before typing to force the view into focus, if the view
already contains text this tap may place the cursor at an arbitrary position within the text.
View preconditions:
| Parameters | |
|---|---|
stringToBeTyped |
String |
| Returns | |
|---|---|
ViewAction |
|
Returns an action that types the provided string into the view. Appending a \n to the end of
the string translates to a ENTER key event. Note: this method does not change cursor position
in the focused view - text is inserted at the location where the cursor is currently pointed.
View preconditions:
| Parameters | |
|---|---|
stringToBeTyped |
String |
| Returns | |
|---|---|
ViewAction |
|