From 55da87181cae4ed53884910ab5fca8b1917d7fe6 Mon Sep 17 00:00:00 2001 From: vadimt Date: Thu, 30 May 2019 14:45:18 -0700 Subject: Waiting for the recycler to populate when opening all apps Change-Id: Ia6d452f9b02f02c1414eaaa9eaee9a70a4664a4a --- tests/tapl/com/android/launcher3/tapl/AllApps.java | 8 +++++++- .../launcher3/tapl/LauncherInstrumentation.java | 21 +++++++++++---------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/tests/tapl/com/android/launcher3/tapl/AllApps.java b/tests/tapl/com/android/launcher3/tapl/AllApps.java index 18a8f2755..d03035a87 100644 --- a/tests/tapl/com/android/launcher3/tapl/AllApps.java +++ b/tests/tapl/com/android/launcher3/tapl/AllApps.java @@ -20,8 +20,10 @@ import static com.android.launcher3.tapl.LauncherInstrumentation.NavigationModel import android.graphics.Point; import android.graphics.Rect; +import android.widget.TextView; import androidx.annotation.NonNull; +import androidx.test.uiautomator.By; import androidx.test.uiautomator.BySelector; import androidx.test.uiautomator.Direction; import androidx.test.uiautomator.UiObject2; @@ -42,6 +44,10 @@ public class AllApps extends LauncherInstrumentation.VisibleContainer { super(launcher); final UiObject2 allAppsContainer = verifyActiveContainer(); mHeight = allAppsContainer.getVisibleBounds().height(); + final UiObject2 appListRecycler = mLauncher.waitForObjectInContainer(allAppsContainer, + "apps_list_view"); + // Wait for the recycler to populate. + mLauncher.waitForObjectInContainer(appListRecycler, By.clazz(TextView.class)); } @Override @@ -115,7 +121,7 @@ public class AllApps extends LauncherInstrumentation.VisibleContainer { verifyActiveContainer(); } - final UiObject2 appIcon = mLauncher.getObjectInContainer(allAppsContainer, + final UiObject2 appIcon = mLauncher.getObjectInContainer(appListRecycler, appIconSelector); ensureIconVisible(appIcon, allAppsContainer, appListRecycler); return new AppIcon(mLauncher, appIcon); diff --git a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java index f7befd140..443bc1af1 100644 --- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java +++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java @@ -21,9 +21,9 @@ import static android.content.pm.PackageManager.DONT_KILL_APP; import static android.content.pm.PackageManager.MATCH_ALL; import static android.content.pm.PackageManager.MATCH_DISABLED_COMPONENTS; +import static com.android.launcher3.tapl.TestHelpers.getOverviewPackageName; import static com.android.launcher3.testing.TestProtocol.BACKGROUND_APP_STATE_ORDINAL; import static com.android.launcher3.testing.TestProtocol.NORMAL_STATE_ORDINAL; -import static com.android.launcher3.tapl.TestHelpers.getOverviewPackageName; import android.app.ActivityManager; import android.app.Instrumentation; @@ -570,6 +570,16 @@ public final class LauncherInstrumentation { return object; } + @NonNull + UiObject2 waitForObjectInContainer(UiObject2 container, BySelector selector) { + final UiObject2 object = container.wait( + Until.findObject(selector), + WAIT_TIME_MS); + assertNotNull("Can't find a launcher object id: " + selector + " in container: " + + container.getResourceName(), object); + return object; + } + @Nullable private boolean hasLauncherObject(String resId) { return mDevice.hasObject(getLauncherObjectSelector(resId)); @@ -580,11 +590,6 @@ public final class LauncherInstrumentation { return waitForObjectBySelector(getLauncherObjectSelector(resName)); } - @NonNull - UiObject2 waitForLauncherObjectByClass(String clazz) { - return waitForObjectBySelector(getLauncherObjectSelectorByClass(clazz)); - } - @NonNull UiObject2 waitForFallbackLauncherObject(String resName) { return waitForObjectBySelector(getFallbackLauncherObjectSelector(resName)); @@ -600,10 +605,6 @@ public final class LauncherInstrumentation { return By.res(getLauncherPackageName(), resName); } - BySelector getLauncherObjectSelectorByClass(String clazz) { - return By.pkg(getLauncherPackageName()).clazz(clazz); - } - BySelector getFallbackLauncherObjectSelector(String resName) { return By.res(getOverviewPackageName(), resName); } -- cgit v1.2.3