# DataInteraction

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/DataInteraction.java+class:androidx.test.espresso.DataInteraction)

*** ** * ** ***


```
class DataInteraction
```

<br />

*** ** * ** ***

An interface to interact with data displayed in AdapterViews.

This interface builds on top of `https://developer.android.com/reference/kotlin/androidx/test/espresso/ViewInteraction` and should be the preferred way to interact with elements displayed inside AdapterViews.

This is necessary because an AdapterView may not load all the data held by its Adapter into the view hierarchy until a user interaction makes it necessary. Also it is more fluent / less brittle to match upon the data object being rendered into the display then the rendering itself.

By default, a DataInteraction takes place against any AdapterView found within the current screen, if you have multiple AdapterView objects displayed, you will need to narrow the selection by using the inAdapterView method.

The check and perform method operate on the top level child of the adapter view, if you need to operate on a subview (eg: a Button within the list) use the onChildView method before calling perform or check.

## Summary

| ### Nested types |
|---|
| `class https://developer.android.com/reference/kotlin/androidx/test/espresso/DataInteraction.DisplayDataMatcher : https://junit.org/junit4/javadoc/latest/org/hamcrest/TypeSafeMatcher.html<https://developer.android.com/reference/android/view/View.html!>` Internal matcher that is required for `https://developer.android.com/reference/kotlin/androidx/test/espresso/Espresso#onData(org.hamcrest.Matcher<? extends java.lang.Object>)`. |

| ### Public functions |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/test/espresso/DataInteraction!` | `@https://docs.oracle.com/javase/8/docs/api/javax/annotation/CheckReturnValue.html https://developer.android.com/reference/kotlin/androidx/test/espresso/DataInteraction#atPosition(java.lang.Integer)(atPosition: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html!)` Selects the view which matches the nth position on the adapter based on the data matcher. |
| `https://developer.android.com/reference/kotlin/androidx/test/espresso/ViewInteraction!` | `https://developer.android.com/reference/kotlin/androidx/test/espresso/DataInteraction#check(androidx.test.espresso.ViewAssertion)(assertion: https://developer.android.com/reference/kotlin/androidx/test/espresso/ViewAssertion!)` Performs an assertion on the state of the view after we force the data to be loaded. |
| `https://developer.android.com/reference/kotlin/androidx/test/espresso/DataInteraction!` | `@https://docs.oracle.com/javase/8/docs/api/javax/annotation/CheckReturnValue.html https://developer.android.com/reference/kotlin/androidx/test/espresso/DataInteraction#inAdapterView(org.hamcrest.Matcher<android.view.View>)(adapterMatcher: https://junit.org/junit4/javadoc/latest/org/hamcrest/Matcher.html<https://developer.android.com/reference/android/view/View.html!>!)` Selects a particular adapter view to operate on, by default we operate on any adapter view on the screen. |
| `https://developer.android.com/reference/kotlin/androidx/test/espresso/DataInteraction!` | `@https://docs.oracle.com/javase/8/docs/api/javax/annotation/CheckReturnValue.html https://developer.android.com/reference/kotlin/androidx/test/espresso/DataInteraction#inRoot(org.hamcrest.Matcher<androidx.test.espresso.Root>)(rootMatcher: https://junit.org/junit4/javadoc/latest/org/hamcrest/Matcher.html<https://developer.android.com/reference/kotlin/androidx/test/espresso/Root!>!)` Causes this data interaction to work within the Root specified by the given root matcher. |
| `https://developer.android.com/reference/kotlin/androidx/test/espresso/DataInteraction!` | `@https://docs.oracle.com/javase/8/docs/api/javax/annotation/CheckReturnValue.html https://developer.android.com/reference/kotlin/androidx/test/espresso/DataInteraction#onChildView(org.hamcrest.Matcher<android.view.View>)(childMatcher: https://junit.org/junit4/javadoc/latest/org/hamcrest/Matcher.html<https://developer.android.com/reference/android/view/View.html!>!)` Causes perform and check methods to take place on a specific child view of the view returned by Adapter.getView() |
| `https://developer.android.com/reference/kotlin/androidx/test/espresso/ViewInteraction!` | `https://developer.android.com/reference/kotlin/androidx/test/espresso/DataInteraction#perform(androidx.test.espresso.ViewAction...)(actions: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<https://developer.android.com/reference/kotlin/androidx/test/espresso/ViewAction!>!)` Performs an action on the view after we force the data to be loaded. |
| `https://developer.android.com/reference/kotlin/androidx/test/espresso/DataInteraction!` | `@https://docs.oracle.com/javase/8/docs/api/javax/annotation/CheckReturnValue.html https://developer.android.com/reference/kotlin/androidx/test/espresso/DataInteraction#usingAdapterViewProtocol(androidx.test.espresso.action.AdapterViewProtocol)( adapterViewProtocol: androidx.test.espresso.action.AdapterViewProtocol! )` Use a different AdapterViewProtocol if the Adapter implementation does not satisfy the AdapterView contract like (@code ExpandableListView) |

## Public functions

### atPosition

```
@CheckReturnValue
fun atPosition(atPosition: Int!): DataInteraction!
```

Selects the view which matches the nth position on the adapter based on the data matcher.

### check

```
fun check(assertion: ViewAssertion!): ViewInteraction!
```

Performs an assertion on the state of the view after we force the data to be loaded.

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/test/espresso/ViewInteraction!` | an `https://developer.android.com/reference/kotlin/androidx/test/espresso/ViewInteraction` for more assertions or actions. |

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

### inAdapterView

```
@CheckReturnValue
fun inAdapterView(adapterMatcher: Matcher<View!>!): DataInteraction!
```

Selects a particular adapter view to operate on, by default we operate on any adapter view on the screen.

### inRoot

```
@CheckReturnValue
fun inRoot(rootMatcher: Matcher<Root!>!): DataInteraction!
```

Causes this data interaction to work within the Root specified by the given root matcher.

### onChildView

```
@CheckReturnValue
fun onChildView(childMatcher: Matcher<View!>!): DataInteraction!
```

Causes perform and check methods to take place on a specific child view of the view returned by Adapter.getView()

### perform

```
fun perform(actions: Array<ViewAction!>!): ViewInteraction!
```

Performs an action on the view after we force the data to be loaded.

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/test/espresso/ViewInteraction!` | an `https://developer.android.com/reference/kotlin/androidx/test/espresso/ViewInteraction` for more assertions or actions. |

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

### usingAdapterViewProtocol

```
@CheckReturnValue
fun usingAdapterViewProtocol(
    adapterViewProtocol: androidx.test.espresso.action.AdapterViewProtocol!
): DataInteraction!
```

Use a different AdapterViewProtocol if the Adapter implementation does not satisfy the AdapterView contract like (@code ExpandableListView)