From c636900a907149489b6b4214d7c1d501070df1ec Mon Sep 17 00:00:00 2001 From: vadimt Date: Tue, 15 Jun 2021 18:52:31 -0700 Subject: [PATCH] Improving diagnostics for objects disappearing from screen Test: presubmit Bug: 187761685 Change-Id: Id932e8100399990d791f7825787708d5d459f61e --- tests/tapl/com/android/launcher3/tapl/AllApps.java | 9 ++++++++- .../android/launcher3/tapl/LauncherInstrumentation.java | 5 ++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/tests/tapl/com/android/launcher3/tapl/AllApps.java b/tests/tapl/com/android/launcher3/tapl/AllApps.java index e32250eaa5..1cb6b2debf 100644 --- a/tests/tapl/com/android/launcher3/tapl/AllApps.java +++ b/tests/tapl/com/android/launcher3/tapl/AllApps.java @@ -25,6 +25,7 @@ import androidx.annotation.NonNull; import androidx.test.uiautomator.By; import androidx.test.uiautomator.BySelector; import androidx.test.uiautomator.Direction; +import androidx.test.uiautomator.StaleObjectException; import androidx.test.uiautomator.UiObject2; import com.android.launcher3.testing.TestProtocol; @@ -61,7 +62,13 @@ public class AllApps extends LauncherInstrumentation.VisibleContainer { private boolean hasClickableIcon(UiObject2 allAppsContainer, UiObject2 appListRecycler, BySelector appIconSelector, int displayBottom) { - final UiObject2 icon = appListRecycler.findObject(appIconSelector); + final UiObject2 icon; + try { + icon = appListRecycler.findObject(appIconSelector); + } catch (StaleObjectException e) { + mLauncher.fail("All apps recycler disappeared from screen"); + return false; + } if (icon == null) { LauncherInstrumentation.log("hasClickableIcon: icon not visible"); return false; diff --git a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java index 426af19084..e80d8cac9d 100644 --- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java +++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java @@ -492,7 +492,7 @@ public final class LauncherInstrumentation { } } - private void fail(String message) { + void fail(String message) { checkForAnomaly(); Assert.fail(formatSystemHealthMessage(formatErrorWithEvents( "http://go/tapl test failure:\nSummary: " + getContextDescription() @@ -1445,6 +1445,9 @@ public final class LauncherInstrumentation { Rect getVisibleBounds(UiObject2 object) { try { return object.getVisibleBounds(); + } catch (StaleObjectException e) { + fail("Object " + object + " disappeared from screen"); + return null; } catch (Throwable t) { fail(t.toString()); return null;