Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9e9799b2 authored by Jagrut Desai's avatar Jagrut Desai
Browse files

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
parent 2be2b932
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -47,7 +47,6 @@ public class TaplAddWidgetTest extends AbstractLauncherUiTest {
    @Rule
    public ShellCommandRule mGrantWidgetRule = ShellCommandRule.grantWidgetBind();

    @PlatinumTest(focusArea = "launcher")
    @Test
    @PortraitLandscape
    @ScreenRecordRule.ScreenRecord // b/289161193
+21 −5
Original line number Diff line number Diff line
@@ -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");