public class

UiAutomatorTestCase

extends InstrumentationTestCase

 java.lang.Object

↳InstrumentationTestCase

↳androidx.test.uiautomator.UiAutomatorTestCase

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.UiAutomatorTestCase android.support.test.uiautomator.UiAutomatorTestCase

Overview

UI Automator test case that is executed on the device.

Summary

Constructors
publicUiAutomatorTestCase()

Methods
public IAutomationSupportgetAutomationSupport()

Provides support for running tests to report interim status

public BundlegetParams()

Get command line parameters.

public UiDevicegetUiDevice()

Get current instance of UiDevice.

public voidsleep(long ms)

Calls to sleep

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

Constructors

public UiAutomatorTestCase()

Methods

public UiDevice getUiDevice()

Get current instance of UiDevice. Works similar to calling the static UiDevice.getInstance() from anywhere in the test classes.

Since: API Level 16

public Bundle getParams()

Get command line parameters. On the command line when passing -e key value pairs, the will have the key value pairs conveniently available to the tests.

Since: API Level 16

public IAutomationSupport getAutomationSupport()

Deprecated: Use instead

Provides support for running tests to report interim status

Returns:

IAutomationSupport

Since: API Level 16

public void sleep(long ms)

Deprecated: Use instead.

Calls to sleep

Parameters:

ms: is in milliseconds.

Since: API Level 16

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.app.Instrumentation;
import android.os.Bundle;
import android.os.SystemClock;
import android.test.InstrumentationTestCase;

/**
 * UI Automator test case that is executed on the device.
 * @deprecated It is no longer necessary to extend UiAutomatorTestCase. You can use
 * {@link UiDevice#getInstance(Instrumentation)} from any test class as long as you have access to
 * an {@link Instrumentation} instance.
 */
@Deprecated
public class UiAutomatorTestCase extends InstrumentationTestCase {

    private UiDevice mDevice;
    private Bundle mParams;
    private IAutomationSupport mAutomationSupport;

    /**
     * Get current instance of {@link UiDevice}. Works similar to calling the static
     * {@link UiDevice#getInstance()} from anywhere in the test classes.
     * @since API Level 16
     */
    public UiDevice getUiDevice() {
        return mDevice;
    }

    /**
     * Get command line parameters. On the command line when passing <code>-e key value</code>
     * pairs, the {@link Bundle} will have the key value pairs conveniently available to the
     * tests.
     * @since API Level 16
     */
    public Bundle getParams() {
        return mParams;
    }

    /**
     * Provides support for running tests to report interim status
     *
     * @return IAutomationSupport
     * @since API Level 16
     * @deprecated Use {@link Instrumentation#sendStatus(int, Bundle)} instead
     */
    @Deprecated
    public IAutomationSupport getAutomationSupport() {
        if (mAutomationSupport == null) {
            mAutomationSupport = new InstrumentationAutomationSupport(getInstrumentation());
        }
        return mAutomationSupport;
    }

    /**
     * Initializes this test case.
     *
     * @param params Instrumentation arguments.
     */
    void initialize(Bundle params) {
        mParams = params;

        // Pre-initialize UiDevice
        mDevice = UiDevice.getInstance(getInstrumentation());

        // check if this is a monkey test mode
        String monkeyVal = mParams.getString("monkey");
        if (monkeyVal != null) {
            // only if the monkey key is specified, we alter the state of monkey
            // else we should leave things as they are.
            getUiDevice().getUiAutomation().setRunAsMonkey(Boolean.valueOf(monkeyVal));
        }
    }

    /**
     * Calls {@link SystemClock#sleep(long)} to sleep
     * @param ms is in milliseconds.
     * @since API Level 16
     * @deprecated Use {@link SystemClock#sleep(long)} instead.
     */
    @Deprecated
    public void sleep(long ms) {
        SystemClock.sleep(ms);
    }
}