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

Commit c5d14e1a authored by Helen Cheuk's avatar Helen Cheuk Committed by Android (Google) Code Review
Browse files

Merge "Add test to launch Lens from PSB" into main

parents 42a06b04 2de7a979
Loading
Loading
Loading
Loading
+33 −0
Original line number Diff line number Diff line
@@ -29,6 +29,8 @@ public abstract class Qsb {

    private static final String ASSISTANT_APP_PACKAGE = "com.google.android.googlequicksearchbox";
    private static final String ASSISTANT_ICON_RES_ID = "mic_icon";
    private static final String LENS_ICON_RES_ID = "lens_icon";
    private static final String LENS_APP_TEXT_RES_ID = "lens_camera_cutout_text";
    protected final LauncherInstrumentation mLauncher;
    private final UiObject2 mContainer;
    private final String mQsbResName;
@@ -75,6 +77,37 @@ public abstract class Qsb {
        }
    }

    /**
     * Launches lens app by tapping lens icon on qsb.
     */
    @NonNull
    public LaunchedAppState launchLens() {
        try (LauncherInstrumentation.Closable c = mLauncher.addContextLayer(
                "want to click lens icon button");
             LauncherInstrumentation.Closable e = mLauncher.eventsCheck()) {
            UiObject2 lensIcon = mLauncher.waitForLauncherObject(LENS_ICON_RES_ID);

            LauncherInstrumentation.log("Qsb.launchLens before click "
                    + lensIcon.getVisibleCenter() + " in "
                    + mLauncher.getVisibleBounds(lensIcon));

            mLauncher.clickLauncherObject(lensIcon);

            try (LauncherInstrumentation.Closable c2 = mLauncher.addContextLayer("clicked")) {
                // Package name is not enough to check if the app is launched, because many
                // elements are having googlequicksearchbox as package name. So it checks if the
                // corresponding text resource is displayed
                BySelector selector = By.res(ASSISTANT_APP_PACKAGE, LENS_APP_TEXT_RES_ID);
                mLauncher.assertTrue(
                        "Lens app didn't start: (" + selector + ")",
                        mLauncher.getDevice().wait(Until.hasObject(selector),
                                LauncherInstrumentation.WAIT_TIME_MS)
                );
                return new LaunchedAppState(mLauncher);
            }
        }
    }

    /**
     * Show search result page from tapping qsb.
     */