From e02e06a9d4bf84ef55b9a218e235065cb9f9022b Mon Sep 17 00:00:00 2001 From: Vadim Tryshev Date: Fri, 7 Sep 2018 15:46:59 -0700 Subject: [PATCH] Including go/tapl in error messages Bug: 110103162 Test: making a test fail, checking a link Change-Id: If64948a6656214c5065150803b2a1a7020fb82c5 --- .../com/android/launcher3/tapl/AllApps.java | 10 +++---- .../com/android/launcher3/tapl/AppIcon.java | 6 ++-- .../tapl/LauncherInstrumentation.java | 30 ++++++++++++++++--- .../com/android/launcher3/tapl/Overview.java | 4 +-- .../android/launcher3/tapl/OverviewTask.java | 4 +-- 5 files changed, 36 insertions(+), 18 deletions(-) diff --git a/tests/tapl/com/android/launcher3/tapl/AllApps.java b/tests/tapl/com/android/launcher3/tapl/AllApps.java index d5b2c878e7..84fd908c28 100644 --- a/tests/tapl/com/android/launcher3/tapl/AllApps.java +++ b/tests/tapl/com/android/launcher3/tapl/AllApps.java @@ -16,8 +16,6 @@ package com.android.launcher3.tapl; -import static org.junit.Assert.assertTrue; - import androidx.annotation.NonNull; import androidx.test.uiautomator.BySelector; import androidx.test.uiautomator.Direction; @@ -62,7 +60,8 @@ public class AllApps extends LauncherInstrumentation.VisibleContainer { int attempts = 0; while (!allAppsContainer.hasObject(appIconSelector) && allAppsContainer.scroll(Direction.DOWN, 0.8f)) { - assertTrue("Exceeded max scroll attempts: " + MAX_SCROLL_ATTEMPTS, + LauncherInstrumentation.assertTrue( + "Exceeded max scroll attempts: " + MAX_SCROLL_ATTEMPTS, ++attempts <= MAX_SCROLL_ATTEMPTS); verifyActiveContainer(); } @@ -85,9 +84,10 @@ public class AllApps extends LauncherInstrumentation.VisibleContainer { for (int scroll = getScroll(allAppsContainer); scroll != 0; scroll = getScroll(allAppsContainer)) { - assertTrue("Negative scroll position", scroll > 0); + LauncherInstrumentation.assertTrue("Negative scroll position", scroll > 0); - assertTrue("Exceeded max scroll attempts: " + MAX_SCROLL_ATTEMPTS, + LauncherInstrumentation.assertTrue( + "Exceeded max scroll attempts: " + MAX_SCROLL_ATTEMPTS, ++attempts <= MAX_SCROLL_ATTEMPTS); allAppsContainer.scroll(Direction.UP, 1); diff --git a/tests/tapl/com/android/launcher3/tapl/AppIcon.java b/tests/tapl/com/android/launcher3/tapl/AppIcon.java index a0f32a4569..17bf5fcece 100644 --- a/tests/tapl/com/android/launcher3/tapl/AppIcon.java +++ b/tests/tapl/com/android/launcher3/tapl/AppIcon.java @@ -16,13 +16,12 @@ package com.android.launcher3.tapl; -import static org.junit.Assert.assertTrue; +import android.widget.TextView; import androidx.test.uiautomator.By; import androidx.test.uiautomator.BySelector; import androidx.test.uiautomator.UiObject2; import androidx.test.uiautomator.Until; -import android.widget.TextView; /** * App icon, whether in all apps or in workspace/ @@ -44,7 +43,8 @@ public final class AppIcon { * Clicks the icon to launch its app. */ public Background launch() { - assertTrue("Launching an app didn't open a new window: " + mIcon.getText(), + LauncherInstrumentation.assertTrue( + "Launching an app didn't open a new window: " + mIcon.getText(), mIcon.clickAndWait(Until.newWindow(), LauncherInstrumentation.WAIT_TIME_MS)); return new Background(mLauncher); } diff --git a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java index 99dd914889..434e421b69 100644 --- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java +++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java @@ -18,10 +18,6 @@ package com.android.launcher3.tapl; import static com.android.systemui.shared.system.SettingsCompat.SWIPE_UP_SETTING_NAME; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - import android.app.ActivityManager; import android.app.Instrumentation; import android.app.UiAutomation; @@ -40,6 +36,8 @@ import androidx.test.uiautomator.Until; import com.android.launcher3.TestProtocol; import com.android.quickstep.SwipeUpSetting; +import org.junit.Assert; + import java.lang.ref.WeakReference; import java.util.concurrent.TimeoutException; @@ -121,6 +119,30 @@ public final class LauncherInstrumentation { return mSwipeUpEnabledOverride != null ? mSwipeUpEnabledOverride : mSwipeUpEnabled; } + private static void fail(String message) { + Assert.fail("http://go/tapl : " + message); + } + + static void assertTrue(String message, boolean condition) { + if (!condition) { + fail(message); + } + } + + static void assertNotNull(String message, Object object) { + assertTrue(message, object != null); + } + + static private void failEquals(String message, Object actual) { + fail(message + ". " + "Actual: " + actual); + } + + static void assertNotEquals(String message, int unexpected, int actual) { + if (unexpected == actual) { + failEquals(message, actual); + } + } + private UiObject2 verifyContainerType(ContainerType containerType) { switch (containerType) { case WORKSPACE: { diff --git a/tests/tapl/com/android/launcher3/tapl/Overview.java b/tests/tapl/com/android/launcher3/tapl/Overview.java index be1d219af2..db0e6c5dbc 100644 --- a/tests/tapl/com/android/launcher3/tapl/Overview.java +++ b/tests/tapl/com/android/launcher3/tapl/Overview.java @@ -16,8 +16,6 @@ package com.android.launcher3.tapl; -import static org.junit.Assert.assertNotEquals; - import android.graphics.Point; import androidx.test.uiautomator.Direction; import androidx.test.uiautomator.UiObject2; @@ -73,7 +71,7 @@ public final class Overview extends LauncherInstrumentation.VisibleContainer { verifyActiveContainer(); final List taskViews = mLauncher.getDevice().findObjects( LauncherInstrumentation.getLauncherObjectSelector("snapshot")); - assertNotEquals("Unable to find a task", 0, taskViews.size()); + LauncherInstrumentation.assertNotEquals("Unable to find a task", 0, taskViews.size()); // taskViews contains up to 3 task views: the 'main' (having the widest visible // part) one in the center, and parts of its right and left siblings. Find the diff --git a/tests/tapl/com/android/launcher3/tapl/OverviewTask.java b/tests/tapl/com/android/launcher3/tapl/OverviewTask.java index ecad768539..2b67cc0233 100644 --- a/tests/tapl/com/android/launcher3/tapl/OverviewTask.java +++ b/tests/tapl/com/android/launcher3/tapl/OverviewTask.java @@ -16,8 +16,6 @@ package com.android.launcher3.tapl; -import static org.junit.Assert.assertTrue; - import androidx.test.uiautomator.Direction; import androidx.test.uiautomator.UiObject2; import androidx.test.uiautomator.Until; @@ -56,7 +54,7 @@ public final class OverviewTask { */ public Background open() { verifyActiveContainer(); - assertTrue("Launching task didn't open a new window: " + + LauncherInstrumentation.assertTrue("Launching task didn't open a new window: " + mTask.getParent().getContentDescription(), mTask.clickAndWait(Until.newWindow(), LauncherInstrumentation.WAIT_TIME_MS)); return new Background(mLauncher);