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

am: 09282c5

* commit '09282c5dc5808073ae4f9d8e9a8a9cb61c93f0c9':
  Fix first-time usage.

Change-Id: Ie6640dc0632abf39250ff56278ffd17c0285a3ac
This commit is contained in:
Felipe Leme
2016-04-15 21:31:47 +00:00
committed by android-build-merger
2 changed files with 25 additions and 16 deletions

View File

@@ -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();
}

View File

@@ -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();
}