From 3fb3d88d2b81122038a47c831d10f6b5ecf2b83a Mon Sep 17 00:00:00 2001 From: Felipe Leme Date: Fri, 15 Apr 2016 11:32:53 -0700 Subject: Fix first-time usage. When tests run for the first time, the list of activities that can handle ACTION_SEND_MULTIPLE might not be scrollable, which was cause the scrollForward() method to fail. BUG: 27431998 Change-Id: I5992bc9fec6291c74c4af7887ee66eb4f96e87c0 --- .../shell/ActionSendMultipleConsumerActivity.java | 4 ++- .../Shell/tests/src/com/android/shell/UiBot.java | 37 +++++++++++++--------- 2 files changed, 25 insertions(+), 16 deletions(-) (limited to 'packages/Shell/tests') diff --git a/packages/Shell/tests/src/com/android/shell/ActionSendMultipleConsumerActivity.java b/packages/Shell/tests/src/com/android/shell/ActionSendMultipleConsumerActivity.java index e3e99b0d5711..e34f5c85c0b8 100644 --- a/packages/Shell/tests/src/com/android/shell/ActionSendMultipleConsumerActivity.java +++ b/packages/Shell/tests/src/com/android/shell/ActionSendMultipleConsumerActivity.java @@ -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(); } diff --git a/packages/Shell/tests/src/com/android/shell/UiBot.java b/packages/Shell/tests/src/com/android/shell/UiBot.java index 5bfe1a084bc4..30f16928ba52 100644 --- a/packages/Shell/tests/src/com/android/shell/UiBot.java +++ b/packages/Shell/tests/src/com/android/shell/UiBot.java @@ -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(); } -- cgit v1.2.3-59-g8ed1b