Configurator
class Configurator
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 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 functions |
|
|---|---|
Unit |
addUiAccessibilityValidator(validator: UiAccessibilityValidator)Adds a validator to be run before important test actions like click(), swipe(), etc. |
Long |
Gets the current timeout for waiting for an acknowledgment of a |
Int |
Gets the default display ID to use when obtaining a |
java-static Configurator |
Retrieves a singleton instance of Configurator. |
Long |
This function is deprecated. This parameter is no longer used (text is set directly rather than by key). |
Long |
Gets the current timeout for waiting for an acknowledgement of a |
Int |
Gets the current tool type to use for motion events. |
(Mutable)List<UiAccessibilityValidator!> |
Gets the currently assigned UiAccessibilityValidators. |
Int |
Gets the current flags that are used to obtain a |
Long |
Gets the current timeout used for waiting for the user interface to go into an idle state before starting a UiAutomator action. |
Long |
Gets the current timeout for waiting for a |
Unit |
Removes a validator added via |
Configurator |
Resets the default display ID to use when obtaining a |
Configurator |
setActionAcknowledgmentTimeout(timeout: Long)Sets the timeout for waiting for an acknowledgment of a |
Configurator |
setDefaultDisplayId(defaultDisplayId: Int)Sets the default display ID to use when obtaining a |
Configurator |
This function is deprecated. This parameter is no longer used (text is set directly rather than by key). |
Configurator |
setScrollAcknowledgmentTimeout(timeout: Long)Sets the timeout for waiting for an acknowledgement of a |
Configurator |
setToolType(toolType: Int)Sets the tool type to use for motion events. |
Configurator |
setUiAutomationFlags(flags: Int)Sets the flags to use when obtaining a |
Configurator |
setWaitForIdleTimeout(timeout: Long)Sets the timeout for waiting for the user interface to go into an idle state before starting a UiAutomator action. |
Configurator |
setWaitForSelectorTimeout(timeout: Long)Sets the timeout for waiting for a |
Public functions
addUiAccessibilityValidator
fun addUiAccessibilityValidator(validator: UiAccessibilityValidator): Unit
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 UiObject2, or the display via UiDevice, such as clicking or scrolling.
| Parameters | |
|---|---|
validator: UiAccessibilityValidator |
to be invoked during UI actions |
getActionAcknowledgmentTimeout
fun getActionAcknowledgmentTimeout(): Long
Gets the current timeout for waiting for an acknowledgment of a UiObject click.
| Returns | |
|---|---|
Long |
current timeout in milliseconds |
getDefaultDisplayId
fun getDefaultDisplayId(): Int
Gets the default display ID to use when obtaining a androidx.test.uiautomator.BySelector instance, or returns INVALID_DISPLAY if the default display ID is not set yet.
| Returns | |
|---|---|
Int |
the default display ID |
getInstance
java-static fun getInstance(): Configurator
Retrieves a singleton instance of Configurator.
| Returns | |
|---|---|
Configurator |
Configurator instance |
getKeyInjectionDelay
fungetKeyInjectionDelay(): Long
Gets the current delay between key presses when injecting text input.
| Returns | |
|---|---|
Long |
current delay in milliseconds |
getScrollAcknowledgmentTimeout
fun getScrollAcknowledgmentTimeout(): Long
Gets the current timeout for waiting for an acknowledgement of a UiScrollable scroll action.
| Returns | |
|---|---|
Long |
current timeout in milliseconds |
getToolType
fun getToolType(): Int
Gets the current tool type to use for motion events.
| Returns | |
|---|---|
Int |
current tool type |
| See also | |
|---|---|
getToolType |
getUiAccessibilityValidators
fun getUiAccessibilityValidators(): (Mutable)List<UiAccessibilityValidator!>
Gets the currently assigned UiAccessibilityValidators.
| See also | |
|---|---|
addUiAccessibilityValidator |
getUiAutomationFlags
fun getUiAutomationFlags(): Int
Gets the current flags that are used to obtain a android.app.UiAutomation instance.
| Returns | |
|---|---|
Int |
UiAutomation flags |
getWaitForIdleTimeout
fun getWaitForIdleTimeout(): Long
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
fun getWaitForSelectorTimeout(): Long
Gets the current timeout for waiting for a UiObject to become visible in the user interface so that it can be matched by a UiSelector.
| Returns | |
|---|---|
Long |
current timeout in milliseconds |
removeUiAccessibilityValidator
fun removeUiAccessibilityValidator(validator: UiAccessibilityValidator): Unit
Removes a validator added via addUiAccessibilityValidator.
resetDefaultDisplayId
fun resetDefaultDisplayId(): Configurator
Resets the default display ID to use when obtaining a androidx.test.uiautomator.BySelector instance.
| Returns | |
|---|---|
Configurator |
self |
setActionAcknowledgmentTimeout
fun setActionAcknowledgmentTimeout(timeout: Long): Configurator
Sets the timeout for waiting for an acknowledgment of a UiObject click.
The acknowledgment is an android.view.accessibility.AccessibilityEvent 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 UiDevice and UiObject2 clicks.
| Parameters | |
|---|---|
timeout: Long |
Timeout value in milliseconds |
| Returns | |
|---|---|
Configurator |
self |
setDefaultDisplayId
fun setDefaultDisplayId(defaultDisplayId: Int): Configurator
Sets the default display ID to use when obtaining a androidx.test.uiautomator.BySelector instance. To avoid interfering with other tests, the caller must call resetDefaultDisplayId when the test is finished.
| Parameters | |
|---|---|
defaultDisplayId: Int |
the default display ID to use |
| Returns | |
|---|---|
Configurator |
self |
setKeyInjectionDelay
funsetKeyInjectionDelay(delay: Long): Configurator
Sets a delay between key presses when injecting text input.
| Parameters | |
|---|---|
delay: Long |
Delay value in milliseconds |
| Returns | |
|---|---|
Configurator |
self |
setScrollAcknowledgmentTimeout
fun setScrollAcknowledgmentTimeout(timeout: Long): Configurator
Sets the timeout for waiting for an acknowledgement of a UiScrollable scroll action.
The acknowledgment is an android.view.accessibility.AccessibilityEvent 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 UiObject2 scrolls.
| Parameters | |
|---|---|
timeout: Long |
Timeout value in milliseconds |
| Returns | |
|---|---|
Configurator |
self |
setToolType
fun setToolType(toolType: Int): Configurator
Sets the tool type to use for motion events.
| Parameters | |
|---|---|
toolType: Int |
The tool type to use |
| Returns | |
|---|---|
Configurator |
self |
setUiAutomationFlags
fun setUiAutomationFlags(flags: Int): Configurator
Sets the flags to use when obtaining a android.app.UiAutomation instance.
| Parameters | |
|---|---|
flags: Int |
The UiAutomation flags to use |
| Returns | |
|---|---|
Configurator |
self |
setWaitForIdleTimeout
fun setWaitForIdleTimeout(timeout: Long): Configurator
Sets the timeout for waiting for the user interface to go into an idle state before starting a UiAutomator action.
| Parameters | |
|---|---|
timeout: Long |
Timeout value in milliseconds |
| Returns | |
|---|---|
Configurator |
self |
setWaitForSelectorTimeout
fun setWaitForSelectorTimeout(timeout: Long): Configurator
Sets the timeout for waiting for a UiObject to become visible in the user interface so that it can be matched by a UiSelector.
For UiObjects, the underlying node is fetched with this timeout before every action.
Has no effect on UiObject2s, which cache the underlying node. Instead, use wait and findObject to wait for the object to become visible.
| Parameters | |
|---|---|
timeout: Long |
Timeout value in milliseconds |
| Returns | |
|---|---|
Configurator |
self |