Search in sources :

Example 11 with UiObject

use of android.support.test.uiautomator.UiObject in project platform_frameworks_base by android.

the class UiBot method chooseActivity.

/**
     * Chooses a given activity to handle an Intent, using the "Just Once" button.
     *
     * @param name name of the activity as displayed in the UI (typically the value set by
     *            {@code android:label} in the manifest).
     */
// TODO: UI Automator should provide such logic.
public void chooseActivity(String name) {
    // First check if the activity is the default option.
    String shareText = "Share with " + name;
    Log.v(TAG, "Waiting for ActivityChooser text: '" + shareText + "'");
    boolean gotIt = mDevice.wait(Until.hasObject(By.text(shareText)), mTimeout);
    boolean justOnceHack = false;
    if (gotIt) {
        Log.v(TAG, "Found activity " + name + ", it's the default action");
        clickJustOnce();
    } else {
        // Since it's not, need to find it in the scrollable list...
        Log.v(TAG, "Activity " + name + " is not default action");
        UiScrollable activitiesList = new UiScrollable(new UiSelector().scrollable(true));
        try {
            activitiesList.scrollForward();
        } catch (UiObjectNotFoundException e) {
            // TODO: for some paranormal issue, the first time a test is run the scrollable
            // activity list is displayed but calling scrollForwad() (or even isScrollable())
            // throws a "UiObjectNotFoundException: UiSelector[SCROLLABLE=true]" exception
            justOnceHack = true;
            Log.d(TAG, "could not scroll forward", e);
        }
        UiObject activity = getVisibleObject(name);
        // ... then select it.
        click(activity, name);
        if (justOnceHack) {
            clickJustOnce();
        }
    }
}
Also used : UiObject(android.support.test.uiautomator.UiObject) UiSelector(android.support.test.uiautomator.UiSelector) UiObjectNotFoundException(android.support.test.uiautomator.UiObjectNotFoundException) UiScrollable(android.support.test.uiautomator.UiScrollable)

Example 12 with UiObject

use of android.support.test.uiautomator.UiObject in project android_frameworks_base by DirtyUnicorns.

the class DirectoryListBot method selectDocument.

public UiObject selectDocument(String label) throws UiObjectNotFoundException {
    UiObject doc = findDocument(label);
    doc.longClick();
    return doc;
}
Also used : UiObject(android.support.test.uiautomator.UiObject)

Example 13 with UiObject

use of android.support.test.uiautomator.UiObject in project android_frameworks_base by DirtyUnicorns.

the class DirectoryListBot method assertDocumentsCountOnList.

public void assertDocumentsCountOnList(boolean exists, int count) throws UiObjectNotFoundException {
    UiObject docsList = findDocumentsList();
    assertEquals(exists, docsList.exists());
    if (docsList.exists()) {
        assertEquals(count, docsList.getChildCount());
    }
}
Also used : UiObject(android.support.test.uiautomator.UiObject)

Example 14 with UiObject

use of android.support.test.uiautomator.UiObject in project android_frameworks_base by DirtyUnicorns.

the class DirectoryListBot method findDocument.

public UiObject findDocument(String label) throws UiObjectNotFoundException {
    final UiSelector docList = new UiSelector().resourceId("com.android.documentsui:id/container_directory").childSelector(new UiSelector().resourceId(DIR_LIST_ID));
    // Wait for the first list item to appear
    new UiObject(docList.childSelector(new UiSelector())).waitForExists(mTimeout);
    // new UiScrollable(docList).scrollIntoView(new UiSelector().text(label));
    return mDevice.findObject(docList.childSelector(new UiSelector().text(label)));
}
Also used : UiObject(android.support.test.uiautomator.UiObject) UiSelector(android.support.test.uiautomator.UiSelector)

Example 15 with UiObject

use of android.support.test.uiautomator.UiObject in project android_frameworks_base by DirtyUnicorns.

the class DirectoryListBot method openDocument.

public void openDocument(String label) throws UiObjectNotFoundException {
    int toolType = Configurator.getInstance().getToolType();
    Configurator.getInstance().setToolType(MotionEvent.TOOL_TYPE_FINGER);
    UiObject doc = findDocument(label);
    doc.click();
    Configurator.getInstance().setToolType(toolType);
}
Also used : UiObject(android.support.test.uiautomator.UiObject)

Aggregations

UiObject (android.support.test.uiautomator.UiObject)140 UiSelector (android.support.test.uiautomator.UiSelector)44 UiScrollable (android.support.test.uiautomator.UiScrollable)13 UiObjectNotFoundException (android.support.test.uiautomator.UiObjectNotFoundException)7 DownloadManager (android.app.DownloadManager)5 Request (android.app.DownloadManager.Request)5 Bundle (android.os.Bundle)5 Suppress (android.test.suitebuilder.annotation.Suppress)5 NumberFormat (java.text.NumberFormat)5 Test (org.junit.Test)3 MediumTest (android.support.test.filters.MediumTest)2 UiDevice (android.support.test.uiautomator.UiDevice)2 RelativeLayout (android.widget.RelativeLayout)1