Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 09282c5d authored by Felipe Leme's avatar Felipe Leme Committed by Android (Google) Code Review
Browse files

Merge "Fix first-time usage." into nyc-dev

parents 4a182358 3fb3d88d
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -113,7 +113,9 @@ public class ActionSendMultipleConsumerActivity extends Activity {
        Bundle getExtras() {
            Bundle bundle = null;
            try {
                bundle = mQueue.poll(TIMEOUT, TimeUnit.SECONDS);
                // UI operations can be slower the very first time the tests are run due
                // because ActionSendMultipleConsumer is not the default activity chosen.
                bundle = mQueue.poll(2 * TIMEOUT, TimeUnit.SECONDS);
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
+22 −15
Original line number Diff line number Diff line
@@ -144,37 +144,44 @@ final class UiBot {
        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");
            // Clicks the "Just Once" button.
            gotIt = mDevice
                    .wait(Until.hasObject(By.res("android", "button_once")), mTimeout);
            assertTrue("'Just Once' button not visible yet", gotIt);

            UiObject justOnce = mDevice
                    .findObject(new UiSelector().resourceId("android:id/button_once"));
            assertTrue("'Just Once' button not found", justOnce.exists());

            click(justOnce, "Just Once");
            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));

            UiObject activity;
            try {
                activitiesList.scrollForward();
                activity = getVisibleObject(name);
            } catch (UiObjectNotFoundException e) {
                throw new IllegalStateException("didn't find activity '" + name
                        + "' on activities chooser", 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();
            }
        }
    }

    private void clickJustOnce() {
        boolean gotIt = mDevice.wait(Until.hasObject(By.res("android", "button_once")), mTimeout);
        assertTrue("'Just Once' button not visible yet", gotIt);

        UiObject justOnce = mDevice
                .findObject(new UiSelector().resourceId("android:id/button_once"));
        assertTrue("'Just Once' button not found", justOnce.exists());

        click(justOnce, "Just Once");
    }

    public void pressBack() {
        mDevice.pressBack();
    }