Configurator
public final 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 methods |
|
|---|---|
void |
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 |
static @NonNull Configurator |
Retrieves a singleton instance of Configurator. |
long |
This method 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. |
@NonNull 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 |
void |
Removes a validator added via |
@NonNull Configurator |
Resets the default display ID to use when obtaining a |
@NonNull Configurator |
setActionAcknowledgmentTimeout(long timeout)Sets the timeout for waiting for an acknowledgment of a |
@NonNull Configurator |
setDefaultDisplayId(int defaultDisplayId)Sets the default display ID to use when obtaining a |
@NonNull Configurator |
This method is deprecated. This parameter is no longer used (text is set directly rather than by key). |
@NonNull Configurator |
setScrollAcknowledgmentTimeout(long timeout)Sets the timeout for waiting for an acknowledgement of a |
@NonNull Configurator |
setToolType(int toolType)Sets the tool type to use for motion events. |
@NonNull Configurator |
setUiAutomationFlags(int flags)Sets the flags to use when obtaining a |
@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. |
@NonNull Configurator |
setWaitForSelectorTimeout(long timeout)Sets the timeout for waiting for a |
Public methods
addUiAccessibilityValidator
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 UiObject2, or the display via UiDevice, such as clicking or scrolling.
| Parameters | |
|---|---|
@NonNull UiAccessibilityValidator validator |
to be invoked during UI actions |
getActionAcknowledgmentTimeout
public long getActionAcknowledgmentTimeout()
Gets the current timeout for waiting for an acknowledgment of a UiObject click.
| Returns | |
|---|---|
long |
current timeout in milliseconds |
getDefaultDisplayId
public int getDefaultDisplayId()
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
public static @NonNull Configurator getInstance()
Retrieves a singleton instance of Configurator.
| Returns | |
|---|---|
@NonNull Configurator |
Configurator instance |
getKeyInjectionDelay
public long getKeyInjectionDelay()Gets the current delay between key presses when injecting text input.
| Returns | |
|---|---|
long |
current delay in milliseconds |
getScrollAcknowledgmentTimeout
public long getScrollAcknowledgmentTimeout()
Gets the current timeout for waiting for an acknowledgement of a UiScrollable scroll action.
| Returns | |
|---|---|
long |
current timeout in milliseconds |
getToolType
public int getToolType()
Gets the current tool type to use for motion events.
| Returns | |
|---|---|
int |
current tool type |
| See also | |
|---|---|
getToolType |
getUiAccessibilityValidators
public @NonNull List<UiAccessibilityValidator> getUiAccessibilityValidators()
Gets the currently assigned UiAccessibilityValidators.
| See also | |
|---|---|
addUiAccessibilityValidator |
getUiAutomationFlags
public int getUiAutomationFlags()
Gets the current flags that are used to obtain a android.app.UiAutomation instance.
| Returns | |
|---|---|
int |
UiAutomation flags |
getWaitForIdleTimeout
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
public long getWaitForSelectorTimeout()
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
public void removeUiAccessibilityValidator(
@NonNull UiAccessibilityValidator validator
)
Removes a validator added via addUiAccessibilityValidator.
resetDefaultDisplayId
public @NonNull Configurator resetDefaultDisplayId()
Resets the default display ID to use when obtaining a androidx.test.uiautomator.BySelector instance.
| Returns | |
|---|---|
@NonNull Configurator |
self |
setActionAcknowledgmentTimeout
public @NonNull Configurator setActionAcknowledgmentTimeout(long timeout)
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 | |
|---|---|
long timeout |
Timeout value in milliseconds |
| Returns | |
|---|---|
@NonNull Configurator |
self |
setDefaultDisplayId
public @NonNull Configurator setDefaultDisplayId(int defaultDisplayId)
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 | |
|---|---|
int defaultDisplayId |
the default display ID to use |
| Returns | |
|---|---|
@NonNull Configurator |
self |
setKeyInjectionDelay
public @NonNull ConfiguratorsetKeyInjectionDelay(long delay)
Sets a delay between key presses when injecting text input.
| Parameters | |
|---|---|
long delay |
Delay value in milliseconds |
| Returns | |
|---|---|
@NonNull Configurator |
self |
setScrollAcknowledgmentTimeout
public @NonNull Configurator setScrollAcknowledgmentTimeout(long timeout)
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 | |
|---|---|
long timeout |
Timeout value in milliseconds |
| Returns | |
|---|---|
@NonNull Configurator |
self |
setToolType
public @NonNull Configurator setToolType(int toolType)
Sets the tool type to use for motion events.
| Parameters | |
|---|---|
int toolType |
The tool type to use |
| Returns | |
|---|---|
@NonNull Configurator |
self |
setUiAutomationFlags
public @NonNull Configurator setUiAutomationFlags(int flags)
Sets the flags to use when obtaining a android.app.UiAutomation instance.
| Parameters | |
|---|---|
int flags |
The UiAutomation flags to use |
| Returns | |
|---|---|
@NonNull Configurator |
self |
setWaitForIdleTimeout
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 | |
|---|---|
@NonNull Configurator |
self |
setWaitForSelectorTimeout
public @NonNull Configurator setWaitForSelectorTimeout(long timeout)
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 | |
|---|---|
long timeout |
Timeout value in milliseconds |
| Returns | |
|---|---|
@NonNull Configurator |
self |