From 9e9799b28c7a05794257e58fc00df6dd18c586e2 Mon Sep 17 00:00:00 2001 From: Jagrut Desai Date: Thu, 14 Dec 2023 15:30:35 -0800 Subject: [PATCH] Refactoring testDragIcon() test - refactoring getWidget method to add support for different app packages. - removing platinum test annotation since adding test on platform scenario test. Test: Presubmit, Local Bug: 303258153 Flag: NONE Change-Id: Ifd5e50cfe8019984ba25312f52266e8b1774318e --- .../ui/widget/TaplAddWidgetTest.java | 1 - .../com/android/launcher3/tapl/Widgets.java | 26 +++++++++++++++---- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/tests/src/com/android/launcher3/ui/widget/TaplAddWidgetTest.java b/tests/src/com/android/launcher3/ui/widget/TaplAddWidgetTest.java index 27fda9b680..d75b387cc9 100644 --- a/tests/src/com/android/launcher3/ui/widget/TaplAddWidgetTest.java +++ b/tests/src/com/android/launcher3/ui/widget/TaplAddWidgetTest.java @@ -47,7 +47,6 @@ public class TaplAddWidgetTest extends AbstractLauncherUiTest { @Rule public ShellCommandRule mGrantWidgetRule = ShellCommandRule.grantWidgetBind(); - @PlatinumTest(focusArea = "launcher") @Test @PortraitLandscape @ScreenRecordRule.ScreenRecord // b/289161193 diff --git a/tests/tapl/com/android/launcher3/tapl/Widgets.java b/tests/tapl/com/android/launcher3/tapl/Widgets.java index 105bc3bf50..6387b05cc8 100644 --- a/tests/tapl/com/android/launcher3/tapl/Widgets.java +++ b/tests/tapl/com/android/launcher3/tapl/Widgets.java @@ -19,6 +19,7 @@ package com.android.launcher3.tapl; import static com.android.launcher3.tapl.LauncherInstrumentation.WAIT_TIME_MS; import static com.android.launcher3.tapl.LauncherInstrumentation.log; +import android.annotation.Nullable; import android.graphics.Rect; import androidx.test.uiautomator.By; @@ -114,7 +115,13 @@ public final class Widgets extends LauncherInstrumentation.VisibleContainer .getInt(TestProtocol.TEST_INFO_RESPONSE_FIELD); } + /** Get widget with supplied text. */ public Widget getWidget(String labelText) { + return getWidget(labelText, null); + } + + /** Get widget with supplied text and app package */ + public Widget getWidget(String labelText, @Nullable String testAppWidgetPackage) { try (LauncherInstrumentation.Closable e = mLauncher.eventsCheck(); LauncherInstrumentation.Closable c = mLauncher.addContextLayer( "getting widget " + labelText + " in widgets list")) { @@ -124,7 +131,8 @@ public final class Widgets extends LauncherInstrumentation.VisibleContainer mLauncher.assertTrue("Widgets container didn't become scrollable", fullWidgetsPicker.wait(Until.scrollable(true), WAIT_TIME_MS)); - final UiObject2 widgetsContainer = findTestAppWidgetsTableContainer(); + final UiObject2 widgetsContainer = + findTestAppWidgetsTableContainer(testAppWidgetPackage); mLauncher.assertTrue("Can't locate widgets list for the test app: " + mLauncher.getLauncherPackageName(), widgetsContainer != null); @@ -180,14 +188,22 @@ public final class Widgets extends LauncherInstrumentation.VisibleContainer return searchBar; } - /** Finds the widgets list of this test app from the collapsed full widgets picker. */ - private UiObject2 findTestAppWidgetsTableContainer() { + /** + * Finds the widgets list of this test app or supplied test app package from the collapsed full + * widgets picker. + */ + private UiObject2 findTestAppWidgetsTableContainer(@Nullable String testAppWidgetPackage) { final BySelector headerSelector = By.res(mLauncher.getLauncherPackageName(), "widgets_list_header"); final BySelector widgetPickerSelector = By.res(mLauncher.getLauncherPackageName(), "container"); - final BySelector targetAppSelector = By.clazz("android.widget.TextView").text( - mLauncher.getContext().getPackageName()); + + String packageName = mLauncher.getContext().getPackageName(); + final BySelector targetAppSelector = By + .clazz("android.widget.TextView") + .text((testAppWidgetPackage == null || testAppWidgetPackage.isEmpty()) + ? packageName + : testAppWidgetPackage); final BySelector widgetsContainerSelector = By.res(mLauncher.getLauncherPackageName(), "widgets_table");