# DeviceInteraction

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

*** ** * ** ***


```
class DeviceInteraction
```

<br />

*** ** * ** ***

API surface for performing device-centric operations.

## Summary

| ### Public companion functions |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/test/espresso/device/DeviceInteraction` | `https://developer.android.com/reference/kotlin/androidx/test/espresso/device/DeviceInteraction.https://developer.android.com/reference/kotlin/androidx/test/espresso/device/DeviceInteraction#(androidx.test.espresso.device.DeviceInteraction).setBookMode()()` Set device screen to be folded with the hinge in the vertical position. |
| `https://developer.android.com/reference/kotlin/androidx/test/espresso/device/DeviceInteraction` | `https://developer.android.com/reference/kotlin/androidx/test/espresso/device/DeviceInteraction.https://developer.android.com/reference/kotlin/androidx/test/espresso/device/DeviceInteraction#(androidx.test.espresso.device.DeviceInteraction).setClosedMode()()` Set device screen to be closed. |
| `https://developer.android.com/reference/kotlin/androidx/test/espresso/device/DeviceInteraction` | `https://developer.android.com/reference/kotlin/androidx/test/espresso/device/DeviceInteraction.https://developer.android.com/reference/kotlin/androidx/test/espresso/device/DeviceInteraction#(androidx.test.espresso.device.DeviceInteraction).setDisplaySize(androidx.test.espresso.device.sizeclass.WidthSizeClass,androidx.test.espresso.device.sizeclass.HeightSizeClass)( widthSizeClass: https://developer.android.com/reference/kotlin/androidx/test/espresso/device/sizeclass/WidthSizeClass, heightSizeClass: https://developer.android.com/reference/kotlin/androidx/test/espresso/device/sizeclass/HeightSizeClass )` Set device's display size. |
| `https://developer.android.com/reference/kotlin/androidx/test/espresso/device/DeviceInteraction` | `https://developer.android.com/reference/kotlin/androidx/test/espresso/device/DeviceInteraction.https://developer.android.com/reference/kotlin/androidx/test/espresso/device/DeviceInteraction#(androidx.test.espresso.device.DeviceInteraction).setFlatMode()()` Set device screen to be completely flat, like a tablet. |
| `https://developer.android.com/reference/kotlin/androidx/test/espresso/device/DeviceInteraction` | `https://developer.android.com/reference/kotlin/androidx/test/espresso/device/DeviceInteraction.https://developer.android.com/reference/kotlin/androidx/test/espresso/device/DeviceInteraction#(androidx.test.espresso.device.DeviceInteraction).setScreenOrientation(androidx.test.espresso.device.action.ScreenOrientation)(orientation: https://developer.android.com/reference/kotlin/androidx/test/espresso/device/action/ScreenOrientation)` Set device's screen orientation. |
| `https://developer.android.com/reference/kotlin/androidx/test/espresso/device/DeviceInteraction` | `https://developer.android.com/reference/kotlin/androidx/test/espresso/device/DeviceInteraction.https://developer.android.com/reference/kotlin/androidx/test/espresso/device/DeviceInteraction#(androidx.test.espresso.device.DeviceInteraction).setTabletopMode()()` Set device screen to be folded with the hinge in the horizontal position. |

| ### Public constructors |
|---|
| `@https://docs.oracle.com/javaee/7/api/javax/inject/Inject.html https://developer.android.com/reference/kotlin/androidx/test/espresso/device/DeviceInteraction#DeviceInteraction(androidx.test.platform.device.DeviceController)(deviceController: https://developer.android.com/reference/kotlin/androidx/test/platform/device/DeviceController)` |

| ### Public functions |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/test/espresso/device/DeviceInteraction` | `https://developer.android.com/reference/kotlin/androidx/test/espresso/device/DeviceInteraction#perform(androidx.test.espresso.device.action.DeviceAction)(action: https://developer.android.com/reference/kotlin/androidx/test/espresso/device/action/DeviceAction)` Performs the given action on the test device. |

## Public companion functions

### DeviceInteraction.setBookMode

Artifact: [androidx.test.espresso:espresso-device](https://developer.android.com/jetpack/androidx/releases/test-espresso) [View Source](https://cs.android.com/search?q=file:androidx/test/espresso/device/DeviceInteraction.kt+function:setBookMode)

```
fun DeviceInteraction.setBookMode(): DeviceInteraction
```

Set device screen to be folded with the hinge in the vertical position. For details on foldable postures, see https://developer.android.com/guide/topics/large-screens/learn-about-foldables#foldable_postures

This action is for foldable devices only. Currently only supported for tests run on Android Emulators.

| Throws |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/test/platform/device/UnsupportedDeviceOperationException` | if used on a real device. |
| `https://developer.android.com/reference/kotlin/androidx/test/espresso/device/controller/DeviceControllerOperationException` | when called on a non-foldable Emulator. |

### DeviceInteraction.setClosedMode

Artifact: [androidx.test.espresso:espresso-device](https://developer.android.com/jetpack/androidx/releases/test-espresso) [View Source](https://cs.android.com/search?q=file:androidx/test/espresso/device/DeviceInteraction.kt+function:setClosedMode)

```
fun DeviceInteraction.setClosedMode(): DeviceInteraction
```

Set device screen to be closed.

This action is for foldable devices only. Currently only supported for tests run on Android Emulators.

| Throws |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/test/platform/device/UnsupportedDeviceOperationException` | if used on a real device. |
| `https://developer.android.com/reference/kotlin/androidx/test/espresso/device/controller/DeviceControllerOperationException` | when called on a non-foldable Emulator. |

### DeviceInteraction.setDisplaySize

Artifact: [androidx.test.espresso:espresso-device](https://developer.android.com/jetpack/androidx/releases/test-espresso) [View Source](https://cs.android.com/search?q=file:androidx/test/espresso/device/DeviceInteraction.kt+function:setDisplaySize)

```
fun DeviceInteraction.setDisplaySize(
    widthSizeClass: WidthSizeClass,
    heightSizeClass: HeightSizeClass
): DeviceInteraction
```

Set device's display size.

| Parameters |
|---|---|
| `widthSizeClass: https://developer.android.com/reference/kotlin/androidx/test/espresso/device/sizeclass/WidthSizeClass` | the width to set the device display to |
| `heightSizeClass: https://developer.android.com/reference/kotlin/androidx/test/espresso/device/sizeclass/HeightSizeClass` | the height to set the device display to |

### DeviceInteraction.setFlatMode

Artifact: [androidx.test.espresso:espresso-device](https://developer.android.com/jetpack/androidx/releases/test-espresso) [View Source](https://cs.android.com/search?q=file:androidx/test/espresso/device/DeviceInteraction.kt+function:setFlatMode)

```
fun DeviceInteraction.setFlatMode(): DeviceInteraction
```

Set device screen to be completely flat, like a tablet. For details on foldable postures, see https://developer.android.com/guide/topics/large-screens/learn-about-foldables#foldable_postures

This action is for foldable devices only. Currently only supported for tests run on Android Emulators.

| Throws |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/test/platform/device/UnsupportedDeviceOperationException` | if used on a real device. |
| `https://developer.android.com/reference/kotlin/androidx/test/espresso/device/controller/DeviceControllerOperationException` | when called on a non-foldable Emulator. |

### DeviceInteraction.setScreenOrientation

Artifact: [androidx.test.espresso:espresso-device](https://developer.android.com/jetpack/androidx/releases/test-espresso) [View Source](https://cs.android.com/search?q=file:androidx/test/espresso/device/DeviceInteraction.kt+function:setScreenOrientation)

```
fun DeviceInteraction.setScreenOrientation(orientation: ScreenOrientation): DeviceInteraction
```

Set device's screen orientation.

| Parameters |
|---|---|
| `orientation: https://developer.android.com/reference/kotlin/androidx/test/espresso/device/action/ScreenOrientation` | the orientation to set the device to (portait or landscape) |

### DeviceInteraction.setTabletopMode

Artifact: [androidx.test.espresso:espresso-device](https://developer.android.com/jetpack/androidx/releases/test-espresso) [View Source](https://cs.android.com/search?q=file:androidx/test/espresso/device/DeviceInteraction.kt+function:setTabletopMode)

```
fun DeviceInteraction.setTabletopMode(): DeviceInteraction
```

Set device screen to be folded with the hinge in the horizontal position. For details on foldable postures, see https://developer.android.com/guide/topics/large-screens/learn-about-foldables#foldable_postures

This action is for foldable devices only. Currently only supported for tests run on Android Emulators.

| Throws |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/test/platform/device/UnsupportedDeviceOperationException` | if used on a real device. |
| `https://developer.android.com/reference/kotlin/androidx/test/espresso/device/controller/DeviceControllerOperationException` | when called on a non-foldable Emulator. |

## Public constructors

### DeviceInteraction

```
@Inject
DeviceInteraction(deviceController: DeviceController)
```

## Public functions

### perform

```
fun perform(action: DeviceAction): DeviceInteraction
```

Performs the given action on the test device. This method should not be called on the main thread. The calling thread is blocked until the requested device action is completed.

| Parameters |
|---|---|
| `action: https://developer.android.com/reference/kotlin/androidx/test/espresso/device/action/DeviceAction` | the DeviceAction to execute. |

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

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html` | when being invoked on the main thread. |