# ViewAction

Summary:[Methods](https://developer.android.com/reference/android/support/test/espresso/ViewAction#pubmethods)\|[\[Expand All\]](https://developer.android.com/reference/android/support/test/espresso/ViewAction#)  

# ViewAction

| This package is part of the Android[support library](https://developer.android.com/topic/libraries/support-library)which is no longer maintained. The support library has been superseded by[AndroidX](https://developer.android.com/jetpack/androidx)which is part of[Jetpack](https://developer.android.com/jetpack). We recommend using the AndroidX libraries in all new projects. You should also consider[migrating](https://developer.android.com/jetpack/androidx/migrate)existing projects to AndroidX. To find the AndroidX class that maps to this deprecated class, see the AndroidX support library[class mappings](https://developer.android.com/jetpack/androidx/migrate/class-mappings).

`
public


interface
ViewAction
`  
`


`

|------------------------------------------|
| android.support.test.espresso.ViewAction |

|---|---|
| [![](https://developer.android.com/static/assets/images/styles/disclosure_down.png)](https://developer.android.com/reference/android/support/test/espresso/ViewAction#)Known Indirect Subclasses [AdapterDataLoaderAction](https://developer.android.com/reference/android/support/test/espresso/action/AdapterDataLoaderAction),[AtomAction](https://developer.android.com/reference/android/support/test/espresso/web/action/AtomAction)\<E\>,[CloseKeyboardAction](https://developer.android.com/reference/android/support/test/espresso/action/CloseKeyboardAction),[EditorAction](https://developer.android.com/reference/android/support/test/espresso/action/EditorAction),[EnableJavascriptAction](https://developer.android.com/reference/android/support/test/espresso/web/action/EnableJavascriptAction),[GeneralClickAction](https://developer.android.com/reference/android/support/test/espresso/action/GeneralClickAction),[GeneralSwipeAction](https://developer.android.com/reference/android/support/test/espresso/action/GeneralSwipeAction),[KeyEventAction](https://developer.android.com/reference/android/support/test/espresso/action/KeyEventAction),[OpenLinkAction](https://developer.android.com/reference/android/support/test/espresso/action/OpenLinkAction),[PressBackAction](https://developer.android.com/reference/android/support/test/espresso/action/PressBackAction),[RecyclerViewActions.PositionableRecyclerViewAction](https://developer.android.com/reference/android/support/test/espresso/contrib/RecyclerViewActions.PositionableRecyclerViewAction),[RepeatActionUntilViewState](https://developer.android.com/reference/android/support/test/espresso/action/RepeatActionUntilViewState),[ReplaceTextAction](https://developer.android.com/reference/android/support/test/espresso/action/ReplaceTextAction),[ScrollToAction](https://developer.android.com/reference/android/support/test/espresso/action/ScrollToAction),[TypeTextAction](https://developer.android.com/reference/android/support/test/espresso/action/TypeTextAction) |----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------| | [AdapterDataLoaderAction](https://developer.android.com/reference/android/support/test/espresso/action/AdapterDataLoaderAction)                                                        | Forces an AdapterView to ensure that the data matching a provided data matcher is loaded into the current view hierarchy.                     | | [AtomAction](https://developer.android.com/reference/android/support/test/espresso/web/action/AtomAction)\<E\>                                                                         | A ViewAction which causes the provided Atom to be evaluated within a webview.                                                                 | | [CloseKeyboardAction](https://developer.android.com/reference/android/support/test/espresso/action/CloseKeyboardAction)                                                                | Closes soft keyboard.                                                                                                                         | | [EditorAction](https://developer.android.com/reference/android/support/test/espresso/action/EditorAction)                                                                              | Performs whatever editor (IME) action is available on a view.                                                                                 | | [EnableJavascriptAction](https://developer.android.com/reference/android/support/test/espresso/web/action/EnableJavascriptAction)                                                      | Forcibly enables Javascript on a WebView.                                                                                                     | | [GeneralClickAction](https://developer.android.com/reference/android/support/test/espresso/action/GeneralClickAction)                                                                  | Enables clicking on views.                                                                                                                    | | [GeneralSwipeAction](https://developer.android.com/reference/android/support/test/espresso/action/GeneralSwipeAction)                                                                  | Enables swiping across a view.                                                                                                                | | [KeyEventAction](https://developer.android.com/reference/android/support/test/espresso/action/KeyEventAction)                                                                          | Enables pressing KeyEvents on views.                                                                                                          | | [OpenLinkAction](https://developer.android.com/reference/android/support/test/espresso/action/OpenLinkAction)                                                                          | Invokes onClick of a link within a TextView (made with Linkify or via another method).                                                        | | [PressBackAction](https://developer.android.com/reference/android/support/test/espresso/action/PressBackAction)                                                                        | Performs an Android press back action                                                                                                         | | [RecyclerViewActions.PositionableRecyclerViewAction](https://developer.android.com/reference/android/support/test/espresso/contrib/RecyclerViewActions.PositionableRecyclerViewAction) | Most RecyclerViewActions are given a matcher to select a particular view / viewholder within the RecyclerView.                                | | [RepeatActionUntilViewState](https://developer.android.com/reference/android/support/test/espresso/action/RepeatActionUntilViewState)                                                  | Enables performing a given action on a view until it reaches desired state matched by given View matcher.                                     | | [ReplaceTextAction](https://developer.android.com/reference/android/support/test/espresso/action/ReplaceTextAction)                                                                    | Replaces view text by setting[EditText](https://developer.android.com/reference/android/widget/EditText.html)s text property to given String. | | [ScrollToAction](https://developer.android.com/reference/android/support/test/espresso/action/ScrollToAction)                                                                          | Enables scrolling to the given view.                                                                                                          | | [TypeTextAction](https://developer.android.com/reference/android/support/test/espresso/action/TypeTextAction)                                                                          | Enables typing text on views.                                                                                                                 | ||

<br />

*** ** * ** ***

Responsible for performing an interaction on the given View element.  

This is part of the test framework public API - developers are free to write their own ViewAction implementations when necessary. When implementing a new ViewAction, follow these rules:

- Inject motion events or key events via the UiController to simulate user interactions.
- Do not mutate the view directly via setter methods and other state changing methods on the view parameter.
- Do not throw AssertionErrors. Assertions belong in ViewAssertion classes.
- View action code will executed on the UI thread, therefore you should not block, perform sleeps, or perform other expensive computations.
- The test framework will wait for the UI thread to be idle both before and after perform() is called. This means that the action is guaranteed to be synchronized with any other view operations.
- Downcasting the View object to an expected subtype is allowed, so long as the object expresses the subtype matches the constraints as specified in`getConstraints`.

<br />

## Summary

|                                                                                                                                                                                                                                                ### Public methods                                                                                                                                                                                                                                                 ||
|-----------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` abstract Matcher<`[View](https://developer.android.com/reference/android/view/View.html)`>` | ` `[getConstraints](https://developer.android.com/reference/android/support/test/espresso/ViewAction#getConstraints())`() ` A mechanism for ViewActions to specify what type of views they can operate on.                                                                                                                                                                                                         |
| ` abstract `[String](https://developer.android.com/reference/java/lang/String.html)           | ` `[getDescription](https://developer.android.com/reference/android/support/test/espresso/ViewAction#getDescription())`() ` Returns a description of the view action.                                                                                                                                                                                                                                              |
| ` abstract void`                                                                              | ` `[perform](https://developer.android.com/reference/android/support/test/espresso/ViewAction#perform(android.support.test.espresso.UiController, android.view.View))`(`[UiController](https://developer.android.com/reference/android/support/test/espresso/UiController)` uiController, `[View](https://developer.android.com/reference/android/view/View.html)` view) ` Performs this action on the given view. |

## Public methods

### getConstraints

```
Matcher<View> getConstraints ()
```

A mechanism for ViewActions to specify what type of views they can operate on.

A ViewAction can demand that the view passed to perform meets certain constraints. For example it may want to ensure the view is already in the viewable physical screen of the device or is of a certain type.

<br />

|                                                                                                            Returns                                                                                                            ||
|-------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------|
| `Matcher<`[View](https://developer.android.com/reference/android/view/View.html)`>` | a[`Matcher`](http://hamcrest.org/JavaHamcrest/javadoc/1.3/org/hamcrest/Matcher.html)that will be tested prior to calling perform. <br /> |

### getDescription

```
String getDescription ()
```

Returns a description of the view action. The description should not be overly long and should fit nicely in a sentence like: "performing %description% action on view with id ..."

<br />

|                                     Returns                                     ||
|-------------------------------------------------------------------------|--------|
| [String](https://developer.android.com/reference/java/lang/String.html) | <br /> |

### perform

```
void perform (UiController uiController, 
                View view)
```

Performs this action on the given view.

<br />

|                                      Parameters                                       ||
|----------------|-----------------------------------------------------------------------|
| `uiController` | `UiController`: the controller to use to interact with the UI. <br /> |
| `view`         | `View`: the view to act upon. never null. <br />                      |

-

  ## Interfaces

  - [EspressoException](https://developer.android.com/reference/android/support/test/espresso/EspressoException)
  - [FailureHandler](https://developer.android.com/reference/android/support/test/espresso/FailureHandler)
  - [IdlingResource](https://developer.android.com/reference/android/support/test/espresso/IdlingResource)
  - [IdlingResource.ResourceCallback](https://developer.android.com/reference/android/support/test/espresso/IdlingResource.ResourceCallback)
  - [UiController](https://developer.android.com/reference/android/support/test/espresso/UiController)
  - [ViewAction](https://developer.android.com/reference/android/support/test/espresso/ViewAction)
  - [ViewAssertion](https://developer.android.com/reference/android/support/test/espresso/ViewAssertion)
  - [ViewFinder](https://developer.android.com/reference/android/support/test/espresso/ViewFinder)
  - [ViewInteractionComponent](https://developer.android.com/reference/android/support/test/espresso/ViewInteractionComponent)
-

  ## Classes

  - [AmbiguousViewMatcherException.Builder](https://developer.android.com/reference/android/support/test/espresso/AmbiguousViewMatcherException.Builder)
  - [DataInteraction](https://developer.android.com/reference/android/support/test/espresso/DataInteraction)
  - [DataInteraction.DisplayDataMatcher](https://developer.android.com/reference/android/support/test/espresso/DataInteraction.DisplayDataMatcher)
  - [Espresso](https://developer.android.com/reference/android/support/test/espresso/Espresso)
  - [IdlingPolicies](https://developer.android.com/reference/android/support/test/espresso/IdlingPolicies)
  - [IdlingPolicy](https://developer.android.com/reference/android/support/test/espresso/IdlingPolicy)
  - [IdlingRegistry](https://developer.android.com/reference/android/support/test/espresso/IdlingRegistry)
  - [NoMatchingViewException.Builder](https://developer.android.com/reference/android/support/test/espresso/NoMatchingViewException.Builder)
  - [PerformException.Builder](https://developer.android.com/reference/android/support/test/espresso/PerformException.Builder)
  - [Root](https://developer.android.com/reference/android/support/test/espresso/Root)
  - [Root.Builder](https://developer.android.com/reference/android/support/test/espresso/Root.Builder)
  - [ViewInteraction](https://developer.android.com/reference/android/support/test/espresso/ViewInteraction)
-

  ## Exceptions

  - [AmbiguousViewMatcherException](https://developer.android.com/reference/android/support/test/espresso/AmbiguousViewMatcherException)
  - [AppNotIdleException](https://developer.android.com/reference/android/support/test/espresso/AppNotIdleException)
  - [IdlingResourceTimeoutException](https://developer.android.com/reference/android/support/test/espresso/IdlingResourceTimeoutException)
  - [InjectEventSecurityException](https://developer.android.com/reference/android/support/test/espresso/InjectEventSecurityException)
  - [NoActivityResumedException](https://developer.android.com/reference/android/support/test/espresso/NoActivityResumedException)
  - [NoMatchingRootException](https://developer.android.com/reference/android/support/test/espresso/NoMatchingRootException)
  - [NoMatchingViewException](https://developer.android.com/reference/android/support/test/espresso/NoMatchingViewException)
  - [PerformException](https://developer.android.com/reference/android/support/test/espresso/PerformException)