# ViewInteraction

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

# ViewInteraction

| 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

final

class
ViewInteraction
`  
`

extends `[Object](https://developer.android.com/reference/java/lang/Object.html)`


``


`

|---|-----------------------------------------------|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) ||
| ↳ | android.support.test.espresso.ViewInteraction |

<br />

*** ** * ** ***

Provides the primary interface for test authors to perform actions or asserts on views.

Each interaction is associated with a view identified by a view matcher. All view actions and asserts are performed on the UI thread (thus ensuring sequential execution). The same goes for retrieval of views (this is done to ensure that view state is "fresh" prior to execution of each operation).

## Summary

|                                                                                                                                                                                                                                                                        ### Public methods                                                                                                                                                                                                                                                                         ||
|-------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` `[ViewInteraction](https://developer.android.com/reference/android/support/test/espresso/ViewInteraction) | ` `[check](https://developer.android.com/reference/android/support/test/espresso/ViewInteraction#check(android.support.test.espresso.ViewAssertion))`(`[ViewAssertion](https://developer.android.com/reference/android/support/test/espresso/ViewAssertion)` viewAssert) ` Checks the given[ViewAssertion](https://developer.android.com/reference/android/support/test/espresso/ViewAssertion)on the the view selected by the current view matcher. |
| ` `[ViewInteraction](https://developer.android.com/reference/android/support/test/espresso/ViewInteraction) | ` `[inRoot](https://developer.android.com/reference/android/support/test/espresso/ViewInteraction#inRoot(org.hamcrest.Matcher<android.support.test.espresso.Root>))`(Matcher<`[Root](https://developer.android.com/reference/android/support/test/espresso/Root)`> rootMatcher) ` Makes this ViewInteraction scoped to the root selected by the given root matcher.                                                                                  |
| ` `[ViewInteraction](https://developer.android.com/reference/android/support/test/espresso/ViewInteraction) | ` `[noActivity](https://developer.android.com/reference/android/support/test/espresso/ViewInteraction#noActivity())`() ` Removes the need of waiting for an Activity before performing a ViewAction/ViewAssertion                                                                                                                                                                                                                                    |
| ` `[ViewInteraction](https://developer.android.com/reference/android/support/test/espresso/ViewInteraction) | ` `[perform](https://developer.android.com/reference/android/support/test/espresso/ViewInteraction#perform(android.support.test.espresso.ViewAction...))`(`[ViewAction...](https://developer.android.com/reference/android/support/test/espresso/ViewAction)` viewActions) ` Performs the given action(s) on the view selected by the current view matcher.                                                                                          |
| ` `[ViewInteraction](https://developer.android.com/reference/android/support/test/espresso/ViewInteraction) | ` `[withFailureHandler](https://developer.android.com/reference/android/support/test/espresso/ViewInteraction#withFailureHandler(android.support.test.espresso.FailureHandler))`(`[FailureHandler](https://developer.android.com/reference/android/support/test/espresso/FailureHandler)` failureHandler) ` Replaces the default failure handler (@see Espresso.setFailureHandler) with a custom failurehandler for this particular interaction.     |

| ### Inherited methods |
|-----------------------|---|
| [![](https://developer.android.com/static/assets/images/styles/disclosure_down.png)](https://developer.android.com/reference/android/support/test/espresso/ViewInteraction#)From class` `[java.lang.Object](https://developer.android.com/reference/java/lang/Object.html)` ` |-------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------| | ` `[Object](https://developer.android.com/reference/java/lang/Object.html)          | ` clone() `                                                                                | | ` boolean`                                                                          | ` equals(`[Object](https://developer.android.com/reference/java/lang/Object.html)` arg0) ` | | ` void`                                                                             | ` finalize() `                                                                             | | ` final `[Class](https://developer.android.com/reference/java/lang/Class.html)`<?>` | ` getClass() `                                                                             | | ` int`                                                                              | ` hashCode() `                                                                             | | ` final void`                                                                       | ` notify() `                                                                               | | ` final void`                                                                       | ` notifyAll() `                                                                            | | ` `[String](https://developer.android.com/reference/java/lang/String.html)          | ` toString() `                                                                             | | ` final void`                                                                       | ` wait(long arg0, int arg1) `                                                              | | ` final void`                                                                       | ` wait(long arg0) `                                                                        | | ` final void`                                                                       | ` wait() `                                                                                 | ||

## Public methods

### check

```
ViewInteraction check (ViewAssertion viewAssert)
```

Checks the given[ViewAssertion](https://developer.android.com/reference/android/support/test/espresso/ViewAssertion)on the the view selected by the current view matcher.

<br />

|                          Parameters                           ||
|--------------|-------------------------------------------------|
| `viewAssert` | `ViewAssertion`: the assertion to check. <br /> |

|                                                                                  Returns                                                                                  ||
|----------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------|
| [ViewInteraction](https://developer.android.com/reference/android/support/test/espresso/ViewInteraction) | this interaction for further perform/verification calls. <br /> |

### inRoot

```
ViewInteraction inRoot (Matcher<Root> rootMatcher)
```

Makes this ViewInteraction scoped to the root selected by the given root matcher.

<br />

|           Parameters            ||
|---------------|------------------|
| `rootMatcher` | `Matcher` <br /> |

|                                                     Returns                                                      ||
|----------------------------------------------------------------------------------------------------------|--------|
| [ViewInteraction](https://developer.android.com/reference/android/support/test/espresso/ViewInteraction) | <br /> |

### noActivity

```
ViewInteraction noActivity ()
```

Removes the need of waiting for an Activity before performing a ViewAction/ViewAssertion

<br />

|                                                     Returns                                                      ||
|----------------------------------------------------------------------------------------------------------|--------|
| [ViewInteraction](https://developer.android.com/reference/android/support/test/espresso/ViewInteraction) | <br /> |

### perform

```
ViewInteraction perform (ViewAction... viewActions)
```

Performs the given action(s) on the view selected by the current view matcher. If more than one action is provided, actions are executed in the order provided with precondition checks running prior to each action.

<br />

|                             Parameters                              ||
|---------------|------------------------------------------------------|
| `viewActions` | `ViewAction`: one or more actions to execute. <br /> |

|                                                                                  Returns                                                                                  ||
|----------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------|
| [ViewInteraction](https://developer.android.com/reference/android/support/test/espresso/ViewInteraction) | this interaction for further perform/verification calls. <br /> |

### withFailureHandler

```
ViewInteraction withFailureHandler (FailureHandler failureHandler)
```

Replaces the default failure handler (@see Espresso.setFailureHandler) with a custom failurehandler for this particular interaction.

<br />

|                                           Parameters                                            ||
|------------------|-------------------------------------------------------------------------------|
| `failureHandler` | `FailureHandler`: a non-null failurehandler to use to report failures. <br /> |

|                                                                                  Returns                                                                                  ||
|----------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------|
| [ViewInteraction](https://developer.android.com/reference/android/support/test/espresso/ViewInteraction) | this interaction for further perform/verification calls. <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)