# Configurator

Artifact: [androidx.test.uiautomator:uiautomator](https://developer.android.com/jetpack/androidx/releases/test-uiautomator) [View Source](https://cs.android.com/search?q=file:androidx/test/uiautomator/Configurator.java+class:androidx.test.uiautomator.Configurator) Added in [2.2.0](https://developer.android.com/jetpack/androidx/releases/test-uiautomator#2.2.0)

*** ** * ** ***


```
public final class Configurator
```

<br />

*** ** * ** ***

Allows you to set key parameters for running UiAutomator tests. The new settings take effect immediately and can be changed at any time during a test run.

To modify parameters, first obtain an instance by calling `https://developer.android.com/reference/androidx/test/uiautomator/Configurator#getInstance()`. As a best practice, make sure you always save the original value of any parameter that you are modifying. After running your tests with the modified parameters, make sure to also restore the original parameter values, otherwise this will impact other tests cases.

## Summary

| ### Public methods |
|---|---|
| `void` | `https://developer.android.com/reference/androidx/test/uiautomator/Configurator#addUiAccessibilityValidator(androidx.test.uiautomator.UiAccessibilityValidator)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/test/uiautomator/UiAccessibilityValidator validator)` Adds a validator to be run before important test actions like click(), swipe(), etc. |
| `long` | `https://developer.android.com/reference/androidx/test/uiautomator/Configurator#getActionAcknowledgmentTimeout()()` Gets the current timeout for waiting for an acknowledgment of a `https://developer.android.com/reference/androidx/test/uiautomator/UiObject` click. |
| `int` | `https://developer.android.com/reference/androidx/test/uiautomator/Configurator#getDefaultDisplayId()()` Gets the default display ID to use when obtaining a `https://developer.android.com/reference/androidx/test/uiautomator/BySelector` instance, or returns `https://developer.android.com/reference/android/view/Display.html#INVALID_DISPLAY` if the default display ID is not set yet. |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/test/uiautomator/Configurator` | `https://developer.android.com/reference/androidx/test/uiautomator/Configurator#getInstance()()` Retrieves a singleton instance of Configurator. |
| `long` | `[getKeyInjectionDelay](https://developer.android.com/reference/androidx/test/uiautomator/Configurator#getKeyInjectionDelay())()` **This method is deprecated.** This parameter is no longer used (text is set directly rather than by key). <br /> |
| `long` | `https://developer.android.com/reference/androidx/test/uiautomator/Configurator#getScrollAcknowledgmentTimeout()()` Gets the current timeout for waiting for an acknowledgement of a `https://developer.android.com/reference/androidx/test/uiautomator/UiScrollable` scroll action. |
| `int` | `https://developer.android.com/reference/androidx/test/uiautomator/Configurator#getToolType()()` Gets the current tool type to use for motion events. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/test/uiautomator/UiAccessibilityValidator>` | `https://developer.android.com/reference/androidx/test/uiautomator/Configurator#getUiAccessibilityValidators()()` Gets the currently assigned UiAccessibilityValidators. |
| `int` | `https://developer.android.com/reference/androidx/test/uiautomator/Configurator#getUiAutomationFlags()()` Gets the current flags that are used to obtain a `https://developer.android.com/reference/android/app/UiAutomation.html` instance. |
| `long` | `https://developer.android.com/reference/androidx/test/uiautomator/Configurator#getWaitForIdleTimeout()()` Gets the current timeout used for waiting for the user interface to go into an idle state before starting a UiAutomator action. |
| `long` | `https://developer.android.com/reference/androidx/test/uiautomator/Configurator#getWaitForSelectorTimeout()()` Gets the current timeout for waiting for a `https://developer.android.com/reference/androidx/test/uiautomator/UiObject` to become visible in the user interface so that it can be matched by a `https://developer.android.com/reference/androidx/test/uiautomator/UiSelector`. |
| `void` | `https://developer.android.com/reference/androidx/test/uiautomator/Configurator#removeUiAccessibilityValidator(androidx.test.uiautomator.UiAccessibilityValidator)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/test/uiautomator/UiAccessibilityValidator validator )` Removes a validator added via `https://developer.android.com/reference/androidx/test/uiautomator/Configurator#addUiAccessibilityValidator(androidx.test.uiautomator.UiAccessibilityValidator)`. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/test/uiautomator/Configurator` | `https://developer.android.com/reference/androidx/test/uiautomator/Configurator#resetDefaultDisplayId()()` Resets the default display ID to use when obtaining a `https://developer.android.com/reference/androidx/test/uiautomator/BySelector` instance. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/test/uiautomator/Configurator` | `https://developer.android.com/reference/androidx/test/uiautomator/Configurator#setActionAcknowledgmentTimeout(long)(long timeout)` Sets the timeout for waiting for an acknowledgment of a `https://developer.android.com/reference/androidx/test/uiautomator/UiObject` click. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/test/uiautomator/Configurator` | `https://developer.android.com/reference/androidx/test/uiautomator/Configurator#setDefaultDisplayId(int)(int defaultDisplayId)` Sets the default display ID to use when obtaining a `https://developer.android.com/reference/androidx/test/uiautomator/BySelector` instance. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/test/uiautomator/Configurator` | `[setKeyInjectionDelay](https://developer.android.com/reference/androidx/test/uiautomator/Configurator#setKeyInjectionDelay(long))(long delay)` **This method is deprecated.** This parameter is no longer used (text is set directly rather than by key). <br /> |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/test/uiautomator/Configurator` | `https://developer.android.com/reference/androidx/test/uiautomator/Configurator#setScrollAcknowledgmentTimeout(long)(long timeout)` Sets the timeout for waiting for an acknowledgement of a `https://developer.android.com/reference/androidx/test/uiautomator/UiScrollable` scroll action. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/test/uiautomator/Configurator` | `https://developer.android.com/reference/androidx/test/uiautomator/Configurator#setToolType(int)(int toolType)` Sets the tool type to use for motion events. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/test/uiautomator/Configurator` | `https://developer.android.com/reference/androidx/test/uiautomator/Configurator#setUiAutomationFlags(int)(int flags)` Sets the flags to use when obtaining a `https://developer.android.com/reference/android/app/UiAutomation.html` instance. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/test/uiautomator/Configurator` | `https://developer.android.com/reference/androidx/test/uiautomator/Configurator#setWaitForIdleTimeout(long)(long timeout)` Sets the timeout for waiting for the user interface to go into an idle state before starting a UiAutomator action. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/test/uiautomator/Configurator` | `https://developer.android.com/reference/androidx/test/uiautomator/Configurator#setWaitForSelectorTimeout(long)(long timeout)` Sets the timeout for waiting for a `https://developer.android.com/reference/androidx/test/uiautomator/UiObject` to become visible in the user interface so that it can be matched by a `https://developer.android.com/reference/androidx/test/uiautomator/UiSelector`. |

## Public methods

### addUiAccessibilityValidator

Added in [2.4.1](https://developer.android.com/jetpack/androidx/releases/test-uiautomator#2.4.1)

```
public void addUiAccessibilityValidator(@NonNull UiAccessibilityValidator validator)
```

Adds a validator to be run before important test actions like click(), swipe(), etc.

The validator can provide custom accessibility checks. The validate method is called before performing any action on a UI element via `https://developer.android.com/reference/androidx/test/uiautomator/UiObject2`, or the display via `https://developer.android.com/reference/androidx/test/uiautomator/UiDevice`, such as clicking or scrolling.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/test/uiautomator/UiAccessibilityValidator validator` | to be invoked during UI actions |

### getActionAcknowledgmentTimeout

Added in [2.2.0](https://developer.android.com/jetpack/androidx/releases/test-uiautomator#2.2.0)

```
public long getActionAcknowledgmentTimeout()
```

Gets the current timeout for waiting for an acknowledgment of a `https://developer.android.com/reference/androidx/test/uiautomator/UiObject` click.

| Returns |
|---|---|
| `long` | current timeout in milliseconds |

### getDefaultDisplayId

Added in [2.4.1](https://developer.android.com/jetpack/androidx/releases/test-uiautomator#2.4.1)

```
public int getDefaultDisplayId()
```

Gets the default display ID to use when obtaining a `https://developer.android.com/reference/androidx/test/uiautomator/BySelector` instance, or returns `https://developer.android.com/reference/android/view/Display.html#INVALID_DISPLAY` if the default display ID is not set yet.

| Returns |
|---|---|
| `int` | the default display ID |

### getInstance

Added in [2.2.0](https://developer.android.com/jetpack/androidx/releases/test-uiautomator#2.2.0)

```
public static @NonNull Configurator getInstance()
```

Retrieves a singleton instance of Configurator.

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/test/uiautomator/Configurator` | Configurator instance |

### getKeyInjectionDelay

Added in [2.2.0](https://developer.android.com/jetpack/androidx/releases/test-uiautomator#2.2.0) Deprecated in [2.4.1](https://developer.android.com/jetpack/androidx/releases/test-uiautomator#2.4.1)

```
public long [getKeyInjectionDelay](https://developer.android.com/reference/androidx/test/uiautomator/Configurator#getKeyInjectionDelay())()
```

> [!CAUTION]
> **This method is deprecated.**   
>
> This parameter is no longer used (text is set directly rather than by key).

Gets the current delay between key presses when injecting text input.

| Returns |
|---|---|
| `long` | current delay in milliseconds |

### getScrollAcknowledgmentTimeout

Added in [2.2.0](https://developer.android.com/jetpack/androidx/releases/test-uiautomator#2.2.0)

```
public long getScrollAcknowledgmentTimeout()
```

Gets the current timeout for waiting for an acknowledgement of a `https://developer.android.com/reference/androidx/test/uiautomator/UiScrollable` scroll action.

| Returns |
|---|---|
| `long` | current timeout in milliseconds |

### getToolType

Added in [2.2.0](https://developer.android.com/jetpack/androidx/releases/test-uiautomator#2.2.0)

```
public int getToolType()
```

Gets the current tool type to use for motion events.

| Returns |
|---|---|
| `int` | current tool type |

| See also |
|---|---|
| `https://developer.android.com/reference/android/view/MotionEvent.html#getToolType(int)` |   |

### getUiAccessibilityValidators

Added in [2.4.1](https://developer.android.com/jetpack/androidx/releases/test-uiautomator#2.4.1)

```
public @NonNull List<UiAccessibilityValidator> getUiAccessibilityValidators()
```

Gets the currently assigned UiAccessibilityValidators.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/test/uiautomator/Configurator#addUiAccessibilityValidator(androidx.test.uiautomator.UiAccessibilityValidator)` |   |

### getUiAutomationFlags

Added in [2.2.0](https://developer.android.com/jetpack/androidx/releases/test-uiautomator#2.2.0)

```
public int getUiAutomationFlags()
```

Gets the current flags that are used to obtain a `https://developer.android.com/reference/android/app/UiAutomation.html` instance.

| Returns |
|---|---|
| `int` | UiAutomation flags |

| See also |
|---|---|
| `https://developer.android.com/reference/android/app/Instrumentation.html#getUiAutomation(int)` |   |
| `https://developer.android.com/reference/android/app/UiAutomation.html#FLAG_DONT_SUPPRESS_ACCESSIBILITY_SERVICES` |   |

### getWaitForIdleTimeout

Added in [2.2.0](https://developer.android.com/jetpack/androidx/releases/test-uiautomator#2.2.0)

```
public long getWaitForIdleTimeout()
```

Gets the current timeout used for waiting for the user interface to go into an idle state before starting a UiAutomator action.

| Returns |
|---|---|
| `long` | current timeout in milliseconds |

### getWaitForSelectorTimeout

Added in [2.2.0](https://developer.android.com/jetpack/androidx/releases/test-uiautomator#2.2.0)

```
public long getWaitForSelectorTimeout()
```

Gets the current timeout for waiting for a `https://developer.android.com/reference/androidx/test/uiautomator/UiObject` to become visible in the user interface so that it can be matched by a `https://developer.android.com/reference/androidx/test/uiautomator/UiSelector`.

| Returns |
|---|---|
| `long` | current timeout in milliseconds |

### removeUiAccessibilityValidator

Added in [2.4.1](https://developer.android.com/jetpack/androidx/releases/test-uiautomator#2.4.1)

```
public void removeUiAccessibilityValidator(
    @NonNull UiAccessibilityValidator validator
)
```

Removes a validator added via `https://developer.android.com/reference/androidx/test/uiautomator/Configurator#addUiAccessibilityValidator(androidx.test.uiautomator.UiAccessibilityValidator)`.

### resetDefaultDisplayId

Added in [2.4.1](https://developer.android.com/jetpack/androidx/releases/test-uiautomator#2.4.1)

```
public @NonNull Configurator resetDefaultDisplayId()
```

Resets the default display ID to use when obtaining a `https://developer.android.com/reference/androidx/test/uiautomator/BySelector` instance.

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/test/uiautomator/Configurator` | self |

### setActionAcknowledgmentTimeout

Added in [2.2.0](https://developer.android.com/jetpack/androidx/releases/test-uiautomator#2.2.0)

```
public @NonNull Configurator setActionAcknowledgmentTimeout(long timeout)
```

Sets the timeout for waiting for an acknowledgment of a `https://developer.android.com/reference/androidx/test/uiautomator/UiObject` click.

The acknowledgment is an `https://developer.android.com/reference/android/view/accessibility/AccessibilityEvent.html` corresponding to a content change that lets the framework determine if the action was successful. Generally, this timeout should not be modified.

Has no effect on `https://developer.android.com/reference/androidx/test/uiautomator/UiDevice` and `https://developer.android.com/reference/androidx/test/uiautomator/UiObject2` clicks.

| Parameters |
|---|---|
| `long timeout` | Timeout value in milliseconds |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/test/uiautomator/Configurator` | self |

### setDefaultDisplayId

Added in [2.4.1](https://developer.android.com/jetpack/androidx/releases/test-uiautomator#2.4.1)

```
public @NonNull Configurator setDefaultDisplayId(int defaultDisplayId)
```

Sets the default display ID to use when obtaining a `https://developer.android.com/reference/androidx/test/uiautomator/BySelector` instance. To avoid interfering with other tests, the caller must call `https://developer.android.com/reference/androidx/test/uiautomator/Configurator#resetDefaultDisplayId()` when the test is finished.

| Parameters |
|---|---|
| `int defaultDisplayId` | the default display ID to use |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/test/uiautomator/Configurator` | self |

### setKeyInjectionDelay

Added in [2.2.0](https://developer.android.com/jetpack/androidx/releases/test-uiautomator#2.2.0) Deprecated in [2.4.1](https://developer.android.com/jetpack/androidx/releases/test-uiautomator#2.4.1)

```
public @NonNull Configurator [setKeyInjectionDelay](https://developer.android.com/reference/androidx/test/uiautomator/Configurator#setKeyInjectionDelay(long))(long delay)
```

> [!CAUTION]
> **This method is deprecated.**   
>
> This parameter is no longer used (text is set directly rather than by key).

Sets a delay between key presses when injecting text input.

| Parameters |
|---|---|
| `long delay` | Delay value in milliseconds |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/test/uiautomator/Configurator` | self |

### setScrollAcknowledgmentTimeout

Added in [2.2.0](https://developer.android.com/jetpack/androidx/releases/test-uiautomator#2.2.0)

```
public @NonNull Configurator setScrollAcknowledgmentTimeout(long timeout)
```

Sets the timeout for waiting for an acknowledgement of a `https://developer.android.com/reference/androidx/test/uiautomator/UiScrollable` scroll action.

The acknowledgment is an `https://developer.android.com/reference/android/view/accessibility/AccessibilityEvent.html` corresponding to the scroll action that lets the framework determine if it was successful. Generally, this timeout should not be modified.

Has no effect on `https://developer.android.com/reference/androidx/test/uiautomator/UiObject2` scrolls.

| Parameters |
|---|---|
| `long timeout` | Timeout value in milliseconds |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/test/uiautomator/Configurator` | self |

### setToolType

Added in [2.2.0](https://developer.android.com/jetpack/androidx/releases/test-uiautomator#2.2.0)

```
public @NonNull Configurator setToolType(int toolType)
```

Sets the tool type to use for motion events.

| Parameters |
|---|---|
| `int toolType` | The tool type to use |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/test/uiautomator/Configurator` | self |

| See also |
|---|---|
| `https://developer.android.com/reference/android/view/MotionEvent.html#getToolType(int)` |   |
| `https://developer.android.com/reference/android/view/MotionEvent.html#TOOL_TYPE_FINGER` |   |
| `https://developer.android.com/reference/android/view/MotionEvent.html#TOOL_TYPE_STYLUS` |   |
| `https://developer.android.com/reference/android/view/MotionEvent.html#TOOL_TYPE_MOUSE` |   |
| `https://developer.android.com/reference/android/view/MotionEvent.html#TOOL_TYPE_ERASER` |   |
| `https://developer.android.com/reference/android/view/MotionEvent.html#TOOL_TYPE_UNKNOWN` |   |

### setUiAutomationFlags

Added in [2.2.0](https://developer.android.com/jetpack/androidx/releases/test-uiautomator#2.2.0)

```
public @NonNull Configurator setUiAutomationFlags(int flags)
```

Sets the flags to use when obtaining a `https://developer.android.com/reference/android/app/UiAutomation.html` instance.

| Parameters |
|---|---|
| `int flags` | The UiAutomation flags to use |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/test/uiautomator/Configurator` | self |

| See also |
|---|---|
| `https://developer.android.com/reference/android/app/Instrumentation.html#getUiAutomation(int)` |   |
| `https://developer.android.com/reference/android/app/UiAutomation.html#FLAG_DONT_SUPPRESS_ACCESSIBILITY_SERVICES` |   |

### setWaitForIdleTimeout

Added in [2.2.0](https://developer.android.com/jetpack/androidx/releases/test-uiautomator#2.2.0)

```
public @NonNull Configurator setWaitForIdleTimeout(long timeout)
```

Sets the timeout for waiting for the user interface to go into an idle state before starting a UiAutomator action.

| Parameters |
|---|---|
| `long timeout` | Timeout value in milliseconds |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/test/uiautomator/Configurator` | self |

### setWaitForSelectorTimeout

Added in [2.2.0](https://developer.android.com/jetpack/androidx/releases/test-uiautomator#2.2.0)

```
public @NonNull Configurator setWaitForSelectorTimeout(long timeout)
```

Sets the timeout for waiting for a `https://developer.android.com/reference/androidx/test/uiautomator/UiObject` to become visible in the user interface so that it can be matched by a `https://developer.android.com/reference/androidx/test/uiautomator/UiSelector`.

For `https://developer.android.com/reference/androidx/test/uiautomator/UiObject`s, the underlying node is fetched with this timeout before every action.

Has no effect on `https://developer.android.com/reference/androidx/test/uiautomator/UiObject2`s, which cache the underlying node. Instead, use `https://developer.android.com/reference/androidx/test/uiautomator/UiDevice#wait(androidx.test.uiautomator.SearchCondition<U>,long)` and `https://developer.android.com/reference/androidx/test/uiautomator/Until#findObject(androidx.test.uiautomator.BySelector)` to wait for the object to become visible.

| Parameters |
|---|---|
| `long timeout` | Timeout value in milliseconds |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/test/uiautomator/Configurator` | self |