public final class

Configurator

extends java.lang.Object

 java.lang.Object

↳androidx.test.uiautomator.Configurator

Gradle dependencies

compile group: 'androidx.test.uiautomator', name: 'uiautomator', version: '2.2.0'

  • groupId: androidx.test.uiautomator
  • artifactId: uiautomator
  • version: 2.2.0

Artifact androidx.test.uiautomator:uiautomator:2.2.0 it located at Google repository (https://maven.google.com/)

Androidx artifact mapping:

androidx.test.uiautomator:uiautomator com.android.support.test.uiautomator:uiautomator

Androidx class mapping:

androidx.test.uiautomator.Configurator android.support.test.uiautomator.Configurator

Overview

Allows you to set key parameters for running uiautomator tests. The new settings take effect immediately and can be changed any time during a test run. To modify parameters using Configurator, first obtain an instance by calling 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

Methods
public longgetActionAcknowledgmentTimeout()

Gets the current timeout for waiting for an acknowledgment of generic uiautomator actions, such as clicks, text setting, and menu presses.

public static ConfiguratorgetInstance()

Retrieves a singleton instance of Configurator.

public longgetKeyInjectionDelay()

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

public longgetScrollAcknowledgmentTimeout()

Gets the timeout for waiting for an acknowledgement of an uiautomtor scroll swipe action.

public intgetToolType()

Gets the current tool type to use for motion events.

public intgetUiAutomationFlags()

Gets the current flags that are used to obtain a instance.

public longgetWaitForIdleTimeout()

Gets the current timeout used for waiting for the user interface to go into an idle state.

public longgetWaitForSelectorTimeout()

Gets the current timeout for waiting for a widget to become visible in the user interface so that it can be matched by a selector.

public ConfiguratorsetActionAcknowledgmentTimeout(long timeout)

Sets the timeout for waiting for an acknowledgment of generic uiautomator actions, such as clicks, text setting, and menu presses.

public ConfiguratorsetKeyInjectionDelay(long delay)

Sets a delay between key presses when injecting text input.

public ConfiguratorsetScrollAcknowledgmentTimeout(long timeout)

Sets the timeout for waiting for an acknowledgement of an uiautomtor scroll swipe action.

public ConfiguratorsetToolType(int toolType)

Sets the current tool type to use for motion events.

public ConfiguratorsetUiAutomationFlags(int flags)

Sets the flags to use when obtaining a instance.

public ConfiguratorsetWaitForIdleTimeout(long timeout)

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

public ConfiguratorsetWaitForSelectorTimeout(long timeout)

Sets the timeout for waiting for a widget to become visible in the user interface so that it can be matched by a selector.

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Methods

public static Configurator getInstance()

Retrieves a singleton instance of Configurator.

Returns:

Configurator instance

Since: API Level 18

public Configurator setWaitForIdleTimeout(long timeout)

Sets the timeout for waiting for the user interface to go into an idle state before starting a uiautomator action. By default, all core uiautomator objects except UiDevice will perform this wait before starting to search for the widget specified by the object's UiSelector. Once the idle state is detected or the timeout elapses (whichever occurs first), the object will start to wait for the selector to find a match. See Configurator.setWaitForSelectorTimeout(long)

Parameters:

timeout: Timeout value in milliseconds

Returns:

self

Since: API Level 18

public long getWaitForIdleTimeout()

Gets the current timeout used for waiting for the user interface to go into an idle state. By default, all core uiautomator objects except UiDevice will perform this wait before starting to search for the widget specified by the object's UiSelector. Once the idle state is detected or the timeout elapses (whichever occurs first), the object will start to wait for the selector to find a match. See Configurator.setWaitForSelectorTimeout(long)

Returns:

Current timeout value in milliseconds

Since: API Level 18

public Configurator setWaitForSelectorTimeout(long timeout)

Sets the timeout for waiting for a widget to become visible in the user interface so that it can be matched by a selector. Because user interface content is dynamic, sometimes a widget may not be visible immediately and won't be detected by a selector. This timeout allows the uiautomator framework to wait for a match to be found, up until the timeout elapses.

Parameters:

timeout: Timeout value in milliseconds.

Returns:

self

Since: API Level 18

public long getWaitForSelectorTimeout()

Gets the current timeout for waiting for a widget to become visible in the user interface so that it can be matched by a selector. Because user interface content is dynamic, sometimes a widget may not be visible immediately and won't be detected by a selector. This timeout allows the uiautomator framework to wait for a match to be found, up until the timeout elapses.

Returns:

Current timeout value in milliseconds

Since: API Level 18

public Configurator setScrollAcknowledgmentTimeout(long timeout)

Sets the timeout for waiting for an acknowledgement of an uiautomtor scroll swipe action. The acknowledgment is an AccessibilityEvent, corresponding to the scroll action, that lets the framework determine if the scroll action was successful. Generally, this timeout should not be modified. See UiScrollable

Parameters:

timeout: Timeout value in milliseconds

Returns:

self

Since: API Level 18

public long getScrollAcknowledgmentTimeout()

Gets the timeout for waiting for an acknowledgement of an uiautomtor scroll swipe action. The acknowledgment is an AccessibilityEvent, corresponding to the scroll action, that lets the framework determine if the scroll action was successful. Generally, this timeout should not be modified. See UiScrollable

Returns:

current timeout in milliseconds

Since: API Level 18

public Configurator setActionAcknowledgmentTimeout(long timeout)

Sets the timeout for waiting for an acknowledgment of generic uiautomator actions, such as clicks, text setting, and menu presses. The acknowledgment is an AccessibilityEvent, corresponding to an action, that lets the framework determine if the action was successful. Generally, this timeout should not be modified. See UiObject

Parameters:

timeout: Timeout value in milliseconds

Returns:

self

Since: API Level 18

public long getActionAcknowledgmentTimeout()

Gets the current timeout for waiting for an acknowledgment of generic uiautomator actions, such as clicks, text setting, and menu presses. The acknowledgment is an AccessibilityEvent, corresponding to an action, that lets the framework determine if the action was successful. Generally, this timeout should not be modified. See UiObject

Returns:

current timeout in milliseconds

Since: API Level 18

public Configurator setKeyInjectionDelay(long delay)

Sets a delay between key presses when injecting text input. See UiObject.setText(String)

Parameters:

delay: Delay value in milliseconds

Returns:

self

Since: API Level 18

public long getKeyInjectionDelay()

Gets the current delay between key presses when injecting text input. See UiObject.setText(String)

Returns:

current delay in milliseconds

Since: API Level 18

public Configurator setToolType(int toolType)

Sets the current tool type to use for motion events.

See also: MotionEvent

public int getToolType()

Gets the current tool type to use for motion events.

See also: MotionEvent

public Configurator setUiAutomationFlags(int flags)

Sets the flags to use when obtaining a instance.

Parameters:

flags: The UiAutomation flags to use.

Returns:

A reference to this object.

See also:

public int getUiAutomationFlags()

Gets the current flags that are used to obtain a instance.

Returns:

The UiAutomation flags.

See also:

Source

/*
 * Copyright (C) 2013 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package androidx.test.uiautomator;

import android.view.MotionEvent;

/**
 * Allows you to set key parameters for running uiautomator tests. The new
 * settings take effect immediately and can be changed any time during a test run.
 *
 * To modify parameters using Configurator, first obtain an instance by calling
 * {@link #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.
 * @since API Level 18
 */
public final class Configurator {
    private long mWaitForIdleTimeout = 10 * 1000;
    private long mWaitForSelector = 10 * 1000;
    private long mWaitForActionAcknowledgment = 3 * 1000;

    // The events for a scroll typically complete even before touchUp occurs.
    // This short timeout to make sure we get the very last in cases where the above isn't true.
    private long mScrollEventWaitTimeout = 200; // ms

    // Default is inject as fast as we can
    private long mKeyInjectionDelay = 0; // ms

    // Default tool type is a finger
    private int mToolType = MotionEvent.TOOL_TYPE_FINGER;

    // Default flags to use when calling Instrumentation.getUiAutomation(int)
    static final int DEFAULT_UIAUTOMATION_FLAGS = 0;
    private int mUiAutomationFlags = DEFAULT_UIAUTOMATION_FLAGS;

    // reference to self
    private static Configurator sConfigurator;

    private Configurator() {
        /* hide constructor */
    }

    /**
     * Retrieves a singleton instance of Configurator.
     *
     * @return Configurator instance
     * @since API Level 18
     */
    public static Configurator getInstance() {
        if (sConfigurator == null) {
            sConfigurator = new Configurator();
        }
        return sConfigurator;
    }

    /**
     * Sets the timeout for waiting for the user interface to go into an idle
     * state before starting a uiautomator action.
     *
     * By default, all core uiautomator objects except {@link UiDevice} will perform
     * this wait before starting to search for the widget specified by the
     * object's {@link UiSelector}. Once the idle state is detected or the
     * timeout elapses (whichever occurs first), the object will start to wait
     * for the selector to find a match.
     * See {@link #setWaitForSelectorTimeout(long)}
     *
     * @param timeout Timeout value in milliseconds
     * @return self
     * @since API Level 18
     */
    public Configurator setWaitForIdleTimeout(long timeout) {
        mWaitForIdleTimeout = timeout;
        return this;
    }

    /**
     * Gets the current timeout used for waiting for the user interface to go
     * into an idle state.
     *
     * By default, all core uiautomator objects except {@link UiDevice} will perform
     * this wait before starting to search for the widget specified by the
     * object's {@link UiSelector}. Once the idle state is detected or the
     * timeout elapses (whichever occurs first), the object will start to wait
     * for the selector to find a match.
     * See {@link #setWaitForSelectorTimeout(long)}
     *
     * @return Current timeout value in milliseconds
     * @since API Level 18
     */
    public long getWaitForIdleTimeout() {
        return mWaitForIdleTimeout;
    }

    /**
     * Sets the timeout for waiting for a widget to become visible in the user
     * interface so that it can be matched by a selector.
     *
     * Because user interface content is dynamic, sometimes a widget may not
     * be visible immediately and won't be detected by a selector. This timeout
     * allows the uiautomator framework to wait for a match to be found, up until
     * the timeout elapses.
     *
     * @param timeout Timeout value in milliseconds.
     * @return self
     * @since API Level 18
     */
    public Configurator setWaitForSelectorTimeout(long timeout) {
        mWaitForSelector = timeout;
        return this;
    }

    /**
     * Gets the current timeout for waiting for a widget to become visible in
     * the user interface so that it can be matched by a selector.
     *
     * Because user interface content is dynamic, sometimes a widget may not
     * be visible immediately and won't be detected by a selector. This timeout
     * allows the uiautomator framework to wait for a match to be found, up until
     * the timeout elapses.
     *
     * @return Current timeout value in milliseconds
     * @since API Level 18
     */
    public long getWaitForSelectorTimeout() {
        return mWaitForSelector;
    }

    /**
     * Sets the timeout for waiting for an acknowledgement of an
     * uiautomtor scroll swipe action.
     *
     * The acknowledgment is an <a href="http://developer.android.com/reference/android/view/accessibility/AccessibilityEvent.html">AccessibilityEvent</a>,
     * corresponding to the scroll action, that lets the framework determine if
     * the scroll action was successful. Generally, this timeout should not be modified.
     * See {@link UiScrollable}
     *
     * @param timeout Timeout value in milliseconds
     * @return self
     * @since API Level 18
     */
    public Configurator setScrollAcknowledgmentTimeout(long timeout) {
        mScrollEventWaitTimeout = timeout;
        return this;
    }

    /**
     * Gets the timeout for waiting for an acknowledgement of an
     * uiautomtor scroll swipe action.
     *
     * The acknowledgment is an <a href="http://developer.android.com/reference/android/view/accessibility/AccessibilityEvent.html">AccessibilityEvent</a>,
     * corresponding to the scroll action, that lets the framework determine if
     * the scroll action was successful. Generally, this timeout should not be modified.
     * See {@link UiScrollable}
     *
     * @return current timeout in milliseconds
     * @since API Level 18
     */
    public long getScrollAcknowledgmentTimeout() {
        return mScrollEventWaitTimeout;
    }

    /**
     * Sets the timeout for waiting for an acknowledgment of generic uiautomator
     * actions, such as clicks, text setting, and menu presses.
     *
     * The acknowledgment is an <a href="http://developer.android.com/reference/android/view/accessibility/AccessibilityEvent.html">AccessibilityEvent</a>,
     * corresponding to an action, that lets the framework determine if the
     * action was successful. Generally, this timeout should not be modified.
     * See {@link UiObject}
     *
     * @param timeout Timeout value in milliseconds
     * @return self
     * @since API Level 18
     */
    public Configurator setActionAcknowledgmentTimeout(long timeout) {
        mWaitForActionAcknowledgment = timeout;
        return this;
    }

    /**
     * Gets the current timeout for waiting for an acknowledgment of generic
     * uiautomator actions, such as clicks, text setting, and menu presses.
     *
     * The acknowledgment is an <a href="http://developer.android.com/reference/android/view/accessibility/AccessibilityEvent.html">AccessibilityEvent</a>,
     * corresponding to an action, that lets the framework determine if the
     * action was successful. Generally, this timeout should not be modified.
     * See {@link UiObject}
     *
     * @return current timeout in milliseconds
     * @since API Level 18
     */
    public long getActionAcknowledgmentTimeout() {
        return mWaitForActionAcknowledgment;
    }

    /**
     * Sets a delay between key presses when injecting text input.
     * See {@link UiObject#setText(String)}
     *
     * @param delay Delay value in milliseconds
     * @return self
     * @since API Level 18
     */
    public Configurator setKeyInjectionDelay(long delay) {
        mKeyInjectionDelay = delay;
        return this;
    }

    /**
     * Gets the current delay between key presses when injecting text input.
     * See {@link UiObject#setText(String)}
     *
     * @return current delay in milliseconds
     * @since API Level 18
     */
    public long getKeyInjectionDelay() {
        return mKeyInjectionDelay;
    }

    /**
     * Sets the current tool type to use for motion events.
     * @see MotionEvent#getToolType(int)
     */
    public Configurator setToolType(final int toolType) {
        mToolType = toolType;
        return this;
    }

    /**
     * Gets the current tool type to use for motion events.
     * @see MotionEvent#getToolType(int)
     */
    public int getToolType() {
        return mToolType;
    }

    /**
     * Sets the flags to use when obtaining a {@link UiAutomation} instance.
     * @param flags The UiAutomation flags to use.
     * @return A reference to this object.
     *
     * @see Instrumentation#getUiAutomation(int)
     * @see UiAutomation#FLAG_DONT_SUPPRESS_ACCESSIBILITY_SERVICES
     */
    public Configurator setUiAutomationFlags(int flags) {
        mUiAutomationFlags = flags;
        return this;
    }

    /**
     * Gets the current flags that are used to obtain a {@link UiAutomation} instance.
     * @return The UiAutomation flags.
     *
     * @see Instrumentation#getUiAutomation(int)
     * @see UiAutomation#FLAG_DONT_SUPPRESS_ACCESSIBILITY_SERVICES
     */
    public int getUiAutomationFlags() {
        return mUiAutomationFlags;
    }
}