Search in sources :

Example 1 with UiObjectNotFoundException

use of android.support.test.uiautomator.UiObjectNotFoundException 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 2 with UiObjectNotFoundException

use of android.support.test.uiautomator.UiObjectNotFoundException in project android_frameworks_base by AOSPA.

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 3 with UiObjectNotFoundException

use of android.support.test.uiautomator.UiObjectNotFoundException in project android_frameworks_base by ResurrectionRemix.

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 4 with UiObjectNotFoundException

use of android.support.test.uiautomator.UiObjectNotFoundException in project chefly_android by chef-ly.

the class PermissionGranter method allowPermissionsIfNeeded.

public static void allowPermissionsIfNeeded(String permissionNeeded) {
    try {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !hasNeededPermission(permissionNeeded)) {
            sleep(PERMISSIONS_DIALOG_DELAY);
            UiDevice device = UiDevice.getInstance(getInstrumentation());
            UiObject allowPermissions = device.findObject(new UiSelector().clickable(true).checkable(false).index(GRANT_BUTTON_INDEX));
            if (allowPermissions.exists()) {
                allowPermissions.click();
            }
        }
    } catch (UiObjectNotFoundException e) {
        System.out.println("There is no permissions dialog to interact with");
    }
}
Also used : UiObject(android.support.test.uiautomator.UiObject) UiSelector(android.support.test.uiautomator.UiSelector) UiDevice(android.support.test.uiautomator.UiDevice) UiObjectNotFoundException(android.support.test.uiautomator.UiObjectNotFoundException)

Example 5 with UiObjectNotFoundException

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

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)

Aggregations

UiObject (android.support.test.uiautomator.UiObject)7 UiObjectNotFoundException (android.support.test.uiautomator.UiObjectNotFoundException)7 UiSelector (android.support.test.uiautomator.UiSelector)7 UiScrollable (android.support.test.uiautomator.UiScrollable)5 UiDevice (android.support.test.uiautomator.UiDevice)2