Summary: Methods | Inherited Methods | [Expand All]

# ViewActions

`public final class ViewActions`
`extends Object` ``

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

A collection of common `ViewActions`.

## Summary

### Public methods
`static ViewAction` | `actionWithAssertions(ViewAction viewAction)` Performs all assertions before the `ViewAction`s in this class and then performs the given `ViewAction`
`static void` | `addGlobalAssertion(String name, ViewAssertion viewAssertion)` Adds a `ViewAssertion` to be run every time a `ViewAction` in this class is performed.
`static void` | `clearGlobalAssertions()`
`static ViewAction` | `clearText()` Returns an action that clears text on the view.
`static ViewAction` | `click()` Returns an action that clicks the view.
`static ViewAction` | `click(ViewAction rollbackAction)` Returns an action that performs a single click on the view.
`static ViewAction` | `closeSoftKeyboard()` Returns an action that closes soft keyboard.
`static ViewAction` | `doubleClick()` Returns an action that double clicks the view.
`static ViewAction` | `longClick()` Returns an action that long clicks the view.
`static ViewAction` | `openLink(Matcher<String> linkTextMatcher, Matcher<Uri> uriMatcher)` Returns an action that opens a link matching the given link text and uri matchers.
`static ViewAction` | `openLinkWithText(String linkText)` Same as `openLinkWithText(Matcher<String> linkTextMatcher)`, but uses `is(linkText)` as the linkTextMatcher.
`static ViewAction` | `openLinkWithText(Matcher<String> linkTextMatcher)` Same as `openLink(Matcher<String> linkTextMatcher, Matcher<Uri> uriMatcher)`, but uses `any(Uri.class)` as the uriMatcher.
`static ViewAction` | `openLinkWithUri(String uri)` Same as `openLinkWithUri(Matcher<Uri> uriMatcher)`, but uses `is(uri)` as the uriMatcher.
`static ViewAction` | `openLinkWithUri(Matcher<Uri> uriMatcher)` Same as `openLink(Matcher<String> linkTextMatcher, Matcher<Uri> uriMatcher)`, but uses `any(String.class)` as the linkTextMatcher.
`static ViewAction` | `pressBack()` Returns an action that clicks the back button.
`static ViewAction` | `pressImeActionButton()` Returns an action that presses the current action button (next, done, search, etc) on the IME (Input Method Editor).
`static ViewAction` | `pressKey(int keyCode)` Returns an action that presses the key specified by the keyCode (eg.
`static ViewAction` | `pressKey(EspressoKey key)` Returns an action that presses the specified key with the specified modifiers.
`static ViewAction` | `pressMenuKey()` Returns an action that presses the hardware menu key.
`static void` | `removeGlobalAssertion(ViewAssertion viewAssertion)` Removes the given assertion from the set of assertions to be run before actions are performed.
`static ViewAction` | `replaceText(String stringToBeSet)` Returns an action that updates the text attribute of a view.
`static ViewAction` | `scrollTo()` Returns an action that scrolls to the view.
`static ViewAction` | `swipeDown()` Returns an action that performs a swipe top-to-bottom across the horizontal center of the view.
`static ViewAction` | `swipeLeft()` Returns an action that performs a swipe right-to-left across the vertical center of the view.
`static ViewAction` | `swipeRight()` Returns an action that performs a swipe left-to-right across the vertical center of the view.
`static ViewAction` | `swipeUp()` Returns an action that performs a swipe bottom-to-top across the horizontal center of the view.
`static ViewAction` | `typeText(String stringToBeTyped)` Returns an action that selects the view (by clicking on it) and types the provided string into the view.
`static ViewAction` | `typeTextIntoFocusedView(String stringToBeTyped)` Returns an action that types the provided string into the view.

### Inherited methods
From class `java.lang.Object`
`Object` | `clone()`
`boolean` | `equals(Object arg0)`
`void` | `finalize()`
`final Class<?>` | `getClass()`
`int` | `hashCode()`
`final void` | `notify()`
`final void` | `notifyAll()`
`String` | `toString()`
`final void` | `wait(long arg0, int arg1)`
`final void` | `wait(long arg0)`
`final void` | `wait()`

## Public methods

### actionWithAssertions

    ViewAction actionWithAssertions (ViewAction viewAction)

Performs all assertions before the `ViewAction`s in this class and then performs the given `ViewAction`

Parameters
`viewAction` | `ViewAction`: the `ViewAction` to perform after the assertions

Returns
`ViewAction` |

### addGlobalAssertion

    void addGlobalAssertion (String name,
                    ViewAssertion viewAssertion)

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.

### clearGlobalAssertions

    void clearGlobalAssertions ()

### clearText

    ViewAction clearText ()

Returns an action that clears text on the view.
View constraints:

- must be displayed on screen

  Returns
  `ViewAction` |

### click

    ViewAction click ()

Returns an action that clicks the view.
View constraints:

- must be displayed on screen

  Returns
  `ViewAction` |

### click

    ViewAction click (ViewAction rollbackAction)

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:

- must be displayed on screen
- any constraints of the rollbackAction

Parameters
`rollbackAction` | `ViewAction`

Returns
`ViewAction` |

### closeSoftKeyboard

    ViewAction closeSoftKeyboard ()

Returns an action that closes soft keyboard. If the keyboard is already closed, it is a no-op.

Returns
`ViewAction` |

### doubleClick

    ViewAction doubleClick ()

Returns an action that double clicks the view.
View preconditions:

- must be displayed on screen

  Returns
  `ViewAction` |

### longClick

    ViewAction longClick ()

Returns an action that long clicks the view.
View preconditions:

- must be displayed on screen

  Returns
  `ViewAction` |

### openLink

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

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:

- must be displayed on screen
- must be assignable from TextView
- must have links

  Parameters
  `linkTextMatcher` | `Matcher`
  `uriMatcher` | `Matcher`

  Returns
  `ViewAction` |

### openLinkWithText

    ViewAction openLinkWithText (String linkText)

Same as `openLinkWithText(Matcher<String> linkTextMatcher)`, but uses `is(linkText)` as the linkTextMatcher.

Parameters
`linkText` | `String`

Returns
`ViewAction` |

### openLinkWithText

    ViewAction openLinkWithText (Matcher<String> linkTextMatcher)

Same as `openLink(Matcher<String> linkTextMatcher, Matcher<Uri> uriMatcher)`, but uses `any(Uri.class)` as the uriMatcher.

Parameters
`linkTextMatcher` | `Matcher`

Returns
`ViewAction` |

### openLinkWithUri

    ViewAction openLinkWithUri (String uri)

Same as `openLinkWithUri(Matcher<Uri> uriMatcher)`, but uses `is(uri)` as the uriMatcher.

Parameters
`uri` | `String`

Returns
`ViewAction` |

### openLinkWithUri

    ViewAction openLinkWithUri (Matcher<Uri> uriMatcher)

Same as `openLink(Matcher<String> linkTextMatcher, Matcher<Uri> uriMatcher)`, but uses `any(String.class)` as the linkTextMatcher.

Parameters
`uriMatcher` | `Matcher`

Returns
`ViewAction` |

### pressBack

    ViewAction pressBack ()

Returns an action that clicks the back button.

Returns
`ViewAction` |

### pressImeActionButton

    ViewAction pressImeActionButton ()

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` |

### pressKey

    ViewAction pressKey (int keyCode)

Returns an action that presses the key specified by the keyCode (eg. Keyevent.KEYCODE_BACK).

Parameters
`keyCode` | `int`

Returns
`ViewAction` |

### pressKey

    ViewAction pressKey (EspressoKey key)

Returns an action that presses the specified key with the specified modifiers.

Parameters
`key` | `EspressoKey`

Returns
`ViewAction` |

### pressMenuKey

    ViewAction pressMenuKey ()

Returns an action that presses the hardware menu key.

Returns
`ViewAction` |

### removeGlobalAssertion

    void removeGlobalAssertion (ViewAssertion viewAssertion)

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.

### replaceText

    ViewAction replaceText (String stringToBeSet)

Returns an action that updates the text attribute of a view.
View preconditions:

- must be displayed on screen
- must be assignable from EditText

  Parameters
  `stringToBeSet` | `String`

  Returns
  `ViewAction` |

### scrollTo

    ViewAction scrollTo ()

Returns an action that scrolls to the view.
View preconditions:

- must be a descendant of ScrollView
- must have visibility set to View.VISIBLE

  Returns
  `ViewAction` |

### swipeDown

    ViewAction swipeDown ()

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:

- must be displayed on screen

  Returns
  `ViewAction` |

### swipeLeft

    ViewAction swipeLeft ()

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:

- must be displayed on screen

  Returns
  `ViewAction` |

### swipeRight

    ViewAction swipeRight ()

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:

- must be displayed on screen

  Returns
  `ViewAction` |

### swipeUp

    ViewAction swipeUp ()

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:

- must be displayed on screen

  Returns
  `ViewAction` |

### typeText

    ViewAction typeText (String stringToBeTyped)

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:

- must be displayed on screen
- must support input methods

  Parameters
  `stringToBeTyped` | `String`

  Returns
  `ViewAction` |

### typeTextIntoFocusedView

    ViewAction typeTextIntoFocusedView (String stringToBeTyped)

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:

- must be displayed on screen
- must support input methods
- must be already focused

  Parameters
  `stringToBeTyped` | `String`

  Returns
  `ViewAction` |

- ## Interfaces

  - AdapterViewProtocol
  - AdapterViewProtocol.DataFunction
  - CoordinatesProvider
  - PrecisionDescriber
  - Swiper
  - Tapper

- ## Classes

  - AdapterDataLoaderAction
  - AdapterViewProtocol.AdaptedData
  - AdapterViewProtocol.AdaptedData.Builder
  - AdapterViewProtocols
  - CloseKeyboardAction
  - EditorAction
  - EspressoKey
  - EspressoKey.Builder
  - GeneralClickAction
  - GeneralSwipeAction
  - KeyEventAction
  - MotionEvents
  - MotionEvents.DownResultHolder
  - OpenLinkAction
  - ReplaceTextAction
  - ScrollToAction
  - TypeTextAction
  - ViewActions

- ## Enums

  - GeneralLocation
  - Press
  - Swipe
  - Swiper.Status
  - Tap
  - Tapper.Status