FileDocCategorySizeDatePackage
UiAutomatorTestCase.javaAPI DocAndroid 5.1 API4513Thu Mar 12 22:22:08 GMT 2015com.android.uiautomator.testrunner

UiAutomatorTestCase

public class UiAutomatorTestCase extends TestCase
UI automation test should extend this class. This class provides access to the following: {@link UiDevice} instance {@link Bundle} for command line parameters.
since
API Level 16

Fields Summary
private static final String
DISABLE_IME
private static final String
DUMMY_IME_PACKAGE
private com.android.uiautomator.core.UiDevice
mUiDevice
private android.os.Bundle
mParams
private IAutomationSupport
mAutomationSupport
private boolean
mShouldDisableIme
Constructors Summary
Methods Summary
public IAutomationSupportgetAutomationSupport()
Provides support for running tests to report interim status

return
IAutomationSupport
since
API Level 16

        return mAutomationSupport;
    
public android.os.BundlegetParams()
Get command line parameters. On the command line when passing -e key value pairs, the {@link Bundle} will have the key value pairs conveniently available to the tests.

since
API Level 16

        return mParams;
    
public com.android.uiautomator.core.UiDevicegetUiDevice()
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

        return mUiDevice;
    
private voidrestoreActiveIme()

        // TODO: figure out a way to restore active IME
        // Currently retrieving active IME requires querying secure settings provider, which is hard
        // to do without a Context; so the caveat here is that to make the post test device usable,
        // the active IME needs to be manually switched.
    
voidsetAutomationSupport(IAutomationSupport automationSupport)

        mAutomationSupport = automationSupport;
    
private voidsetDummyIme()

        IInputMethodManager im = IInputMethodManager.Stub.asInterface(ServiceManager
                .getService(Context.INPUT_METHOD_SERVICE));
        List<InputMethodInfo> infos = im.getInputMethodList();
        String id = null;
        for (InputMethodInfo info : infos) {
            if (DUMMY_IME_PACKAGE.equals(info.getComponent().getPackageName())) {
                id = info.getId();
            }
        }
        if (id == null) {
            throw new RuntimeException(String.format(
                    "Required testing fixture missing: IME package (%s)", DUMMY_IME_PACKAGE));
        }
        im.setInputMethod(null, id);
    
voidsetParams(android.os.Bundle params)
package private

param
params

        mParams = params;
    
voidsetUiDevice(com.android.uiautomator.core.UiDevice uiDevice)
package private

param
uiDevice

        mUiDevice = uiDevice;
    
protected voidsetUp()


    
         
        super.setUp();
        mShouldDisableIme = "true".equals(mParams.getString(DISABLE_IME));
        if (mShouldDisableIme) {
            setDummyIme();
        }
    
public voidsleep(long ms)
Calls {@link SystemClock#sleep(long)} to sleep

param
ms is in milliseconds.
since
API Level 16

        SystemClock.sleep(ms);
    
protected voidtearDown()

        if (mShouldDisableIme) {
            restoreActiveIme();
        }
        super.tearDown();