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.4.0-alpha01'

  • groupId: androidx.test.uiautomator
  • artifactId: uiautomator
  • version: 2.4.0-alpha01

Artifact androidx.test.uiautomator:uiautomator:2.4.0-alpha01 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 at any time during a test run.

To modify parameters, 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 a UiObject click.

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 current timeout for waiting for an acknowledgement of a UiScrollable scroll 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 android.app.UiAutomation instance.

public longgetWaitForIdleTimeout()

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

public longgetWaitForSelectorTimeout()

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.

public ConfiguratorsetActionAcknowledgmentTimeout(long timeout)

Sets the timeout for waiting for an acknowledgment of a UiObject click.

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 a UiScrollable scroll action.

public ConfiguratorsetToolType(int toolType)

Sets the tool type to use for motion events.

public ConfiguratorsetUiAutomationFlags(int flags)

Sets the flags to use when obtaining a android.app.UiAutomation 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 UiObject to become visible in the user interface so that it can be matched by a UiSelector.

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

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.

Parameters:

timeout: Timeout value in milliseconds

Returns:

self

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:

current timeout in milliseconds

public 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 UiDevice.wait(SearchCondition, long) and Until.findObject(BySelector) to wait for the object to become visible.

Parameters:

timeout: Timeout value in milliseconds

Returns:

self

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:

current timeout in milliseconds

public Configurator setScrollAcknowledgmentTimeout(long timeout)

Sets the timeout for waiting for an acknowledgement of a UiScrollable scroll action.

The acknowledgment is an 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: Timeout value in milliseconds

Returns:

self

public long getScrollAcknowledgmentTimeout()

Gets the current timeout for waiting for an acknowledgement of a UiScrollable scroll action.

Returns:

current timeout in milliseconds

public Configurator setActionAcknowledgmentTimeout(long timeout)

Sets the timeout for waiting for an acknowledgment of a UiObject click.

The acknowledgment is an 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: Timeout value in milliseconds

Returns:

self

public long getActionAcknowledgmentTimeout()

Gets the current timeout for waiting for an acknowledgment of a UiObject click.

Returns:

current timeout in milliseconds

public Configurator setKeyInjectionDelay(long delay)

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:

delay: Delay value in milliseconds

Returns:

self

public long getKeyInjectionDelay()

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:

current delay in milliseconds

public Configurator setToolType(int toolType)

Sets the tool type to use for motion events.

Parameters:

toolType: The tool type to use

Returns:

self

See also: MotionEvent, MotionEvent, MotionEvent, MotionEvent, MotionEvent, MotionEvent

public int getToolType()

Gets the current tool type to use for motion events.

Returns:

current tool type

See also: MotionEvent

public Configurator setUiAutomationFlags(int flags)

Sets the flags to use when obtaining a android.app.UiAutomation instance.

Parameters:

flags: The UiAutomation flags to use

Returns:

self

See also: android.app.Instrumentation, android.app.UiAutomation

public int getUiAutomationFlags()

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

Returns:

UiAutomation flags

See also: android.app.Instrumentation, android.app.UiAutomation

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;

import androidx.annotation.NonNull;

/**
 * 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.
 *
 * <p>To modify parameters, 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.
 */
public final class Configurator {

    private long mWaitForIdleTimeout = 10_000; // ms
    private long mWaitForSelector = 10_000; // ms
    private long mWaitForActionAcknowledgment = 3_000; // ms

    // Scroll timeout used only in InteractionController
    private long mScrollEventWaitTimeout = 1_000; // 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;

    // Singleton instance.
    private static Configurator sConfigurator;

    private Configurator() {}

    /**
     * Retrieves a singleton instance of Configurator.
     *
     * @return Configurator instance
     */
    public static @NonNull 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.
     *
     * @param timeout Timeout value in milliseconds
     * @return self
     */
    public @NonNull 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
     * before starting a UiAutomator action.
     *
     * @return current timeout in milliseconds
     */
    public long getWaitForIdleTimeout() {
        return mWaitForIdleTimeout;
    }

    /**
     * Sets the timeout for waiting for a {@link UiObject} to become visible in the user
     * interface so that it can be matched by a {@link UiSelector}.
     *
     * <p>For {@link UiObject}s, the underlying node is fetched with this timeout before every
     * action.
     *
     * <p>Has no effect on {@link UiObject2}s, which cache the underlying node. Instead, use
     * {@link UiDevice#wait} and {@link Until#findObject} to wait for the object to become visible.
     *
     * @param timeout Timeout value in milliseconds
     * @return self
     */
    public @NonNull Configurator setWaitForSelectorTimeout(long timeout) {
        mWaitForSelector = timeout;
        return this;
    }

    /**
     * Gets the current timeout for waiting for a {@link UiObject} to become visible in the user
     * interface so that it can be matched by a {@link UiSelector}.
     *
     * @return current timeout in milliseconds
     */
    public long getWaitForSelectorTimeout() {
        return mWaitForSelector;
    }

    /**
     * Sets the timeout for waiting for an acknowledgement of a {@link UiScrollable} scroll action.
     *
     * <p>The acknowledgment is an {@link 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.
     *
     * <p>Has no effect on {@link UiObject2} scrolls.
     *
     * @param timeout Timeout value in milliseconds
     * @return self
     */
    public @NonNull Configurator setScrollAcknowledgmentTimeout(long timeout) {
        mScrollEventWaitTimeout = timeout;
        return this;
    }

    /**
     * Gets the current timeout for waiting for an acknowledgement of a {@link UiScrollable}
     * scroll action.
     *
     * @return current timeout in milliseconds
     */
    public long getScrollAcknowledgmentTimeout() {
        return mScrollEventWaitTimeout;
    }

    /**
     * Sets the timeout for waiting for an acknowledgment of a {@link UiObject} click.
     *
     * <p>The acknowledgment is an {@link 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.
     *
     * <p>Has no effect on {@link UiDevice} and {@link UiObject2} clicks.
     *
     * @param timeout Timeout value in milliseconds
     * @return self
     */
    public @NonNull Configurator setActionAcknowledgmentTimeout(long timeout) {
        mWaitForActionAcknowledgment = timeout;
        return this;
    }

    /**
     * Gets the current timeout for waiting for an acknowledgment of a {@link UiObject} click.
     *
     * @return current timeout in milliseconds
     */
    public long getActionAcknowledgmentTimeout() {
        return mWaitForActionAcknowledgment;
    }

    /**
     * Sets a delay between key presses when injecting text input.
     *
     * @param delay Delay value in milliseconds
     * @return self
     * @deprecated This parameter is no longer used (text is set directly rather than by key).
     */
    @Deprecated
    public @NonNull Configurator setKeyInjectionDelay(long delay) {
        mKeyInjectionDelay = delay;
        return this;
    }

    /**
     * Gets the current delay between key presses when injecting text input.
     *
     * @return current delay in milliseconds
     * @deprecated This parameter is no longer used (text is set directly rather than by key).
     */
    @Deprecated
    public long getKeyInjectionDelay() {
        return mKeyInjectionDelay;
    }

    /**
     * Sets the tool type to use for motion events.
     *
     * @param toolType The tool type to use
     * @return self
     * @see MotionEvent#getToolType(int)
     * @see MotionEvent#TOOL_TYPE_FINGER
     * @see MotionEvent#TOOL_TYPE_STYLUS
     * @see MotionEvent#TOOL_TYPE_MOUSE
     * @see MotionEvent#TOOL_TYPE_ERASER
     * @see MotionEvent#TOOL_TYPE_UNKNOWN
     */
    public @NonNull Configurator setToolType(final int toolType) {
        mToolType = toolType;
        return this;
    }

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

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

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