From 2ec9f290bf45aaef86edf6e31c1e070bef8b7a68 Mon Sep 17 00:00:00 2001 From: vadimt Date: Fri, 15 Mar 2019 19:29:10 -0700 Subject: [PATCH] Hopefully reducing flakes by waiting for SysUI objects Looks like when orientation change is involved, it takes some time for SysUI object to reappear. Change-Id: Id08d385ea1a535d8bcd87b123f0373cd28d90a92 --- tests/tapl/com/android/launcher3/tapl/Background.java | 4 ++-- .../android/launcher3/tapl/LauncherInstrumentation.java | 9 +++++---- tests/tapl/com/android/launcher3/tapl/Overview.java | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/tests/tapl/com/android/launcher3/tapl/Background.java b/tests/tapl/com/android/launcher3/tapl/Background.java index 3220691d64..7031cd34c0 100644 --- a/tests/tapl/com/android/launcher3/tapl/Background.java +++ b/tests/tapl/com/android/launcher3/tapl/Background.java @@ -71,7 +71,7 @@ public class Background extends LauncherInstrumentation.VisibleContainer { mLauncher.swipe(centerX, startY, centerX, startY - swipeHeight - slop, expectedState); } else { - mLauncher.getSystemUiObject("recent_apps").click(); + mLauncher.waitForSystemUiObject("recent_apps").click(); } } @@ -80,6 +80,6 @@ public class Background extends LauncherInstrumentation.VisibleContainer { } protected int getSwipeStartY() { - return mLauncher.getSystemUiObject("home").getVisibleBounds().centerY(); + return mLauncher.waitForSystemUiObject("home").getVisibleBounds().centerY(); } } diff --git a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java index 926e4702cc..ce37348d3d 100644 --- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java +++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java @@ -288,7 +288,7 @@ public final class LauncherInstrumentation { executeAndWaitForEvent( () -> { log("LauncherInstrumentation.pressHome before clicking"); - getSystemUiObject("home").click(); + waitForSystemUiObject("home").click(); }, event -> true, "Pressing Home didn't produce any events"); @@ -298,7 +298,7 @@ public final class LauncherInstrumentation { executeAndWaitForEvent( () -> { log("LauncherInstrumentation.pressHome before clicking"); - getSystemUiObject("home").click(); + waitForSystemUiObject("home").click(); }, event -> true, "Pressing Home didn't produce any events"); @@ -394,8 +394,9 @@ public final class LauncherInstrumentation { } @NonNull - UiObject2 getSystemUiObject(String resId) { - final UiObject2 object = mDevice.findObject(By.res(SYSTEMUI_PACKAGE, resId)); + UiObject2 waitForSystemUiObject(String resId) { + final UiObject2 object = mDevice.wait( + Until.findObject(By.res(SYSTEMUI_PACKAGE, resId)), WAIT_TIME_MS); assertNotNull("Can't find a systemui object with id: " + resId, object); return object; } diff --git a/tests/tapl/com/android/launcher3/tapl/Overview.java b/tests/tapl/com/android/launcher3/tapl/Overview.java index 02081449b1..5c8d5eb12a 100644 --- a/tests/tapl/com/android/launcher3/tapl/Overview.java +++ b/tests/tapl/com/android/launcher3/tapl/Overview.java @@ -50,7 +50,7 @@ public final class Overview extends BaseOverview { verifyActiveContainer(); // Swipe from navbar to the top. - final UiObject2 navBar = mLauncher.getSystemUiObject("navigation_bar_frame"); + final UiObject2 navBar = mLauncher.waitForSystemUiObject("navigation_bar_frame"); final Point start = navBar.getVisibleCenter(); LauncherInstrumentation.log("Overview.switchToAllApps before swipe"); mLauncher.swipe(start.x, start.y, start.x, 0, ALL_APPS_STATE_ORDINAL);