# ViewInteraction

Artifact: [androidx.test.espresso:espresso-core](https://developer.android.com/jetpack/androidx/releases/test-espresso) [View Source](https://cs.android.com/search?q=file:androidx/test/espresso/ViewInteraction.java+class:androidx.test.espresso.ViewInteraction)

*** ** * ** ***


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

## Public methods

### check

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

Checks the given `https://developer.android.com/reference/androidx/test/espresso/ViewAssertion` on the view selected by the current view matcher.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/test/espresso/ViewAssertion viewAssert` | the assertion to check. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/test/espresso/ViewInteraction` | this interaction for further perform/verification calls. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/RuntimeException.html` | when being invoked on the main thread. |

### inRoot

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

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

### noActivity

```
public ViewInteraction noActivity()
```

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

### perform

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

If the test argument \`--enable_testflow_gallery\` is present, captures data for each of the interactions and generates an output artifact for the test run. NOTE, this is an experimental feature.

| Parameters |
|---|---|
| `ViewAction[] viewActions` | one or more actions to execute. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/test/espresso/ViewInteraction` | this interaction for further perform/verification calls. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/RuntimeException.html` | when being invoked on the main thread. |

### withFailureHandler

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

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

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/test/espresso/FailureHandler failureHandler` | a non-null FailureHandler to use to report failures. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/test/espresso/ViewInteraction` | this interaction for further perform/verification calls. |