4

We are running Espresso tests on FireBase TestLab. I noticed tests are failing on certain devices (ex. LG Nexus 5) due to a AutofillWithGooglePopUp which appears after signing into application. I want to handle (dismiss) this popUp. I can turn off this feature on the real device we have, but on TestLab this feature is sometimes ON, and I do not think I will be able to turn it off (or could I?). I've tried numerous things: Tried locating with Espresso - did not work out (I guess since it is not a part of application):

onView(withText("alert_dialog_text")).perform(pressBack());

Tried to click back and launch activity again, popUp is still there (though with manual clicks turns off)

Espreso.pressBack();
ActivityTestRule.launchActivity(null);

tried to locate it by numerous selectors with UIAutomator - did not work. UIAutomatorViewer does not see this popUp. AndroidStudio monitor does not see this popUp as well. Seems like Google sends it as Information message. Is there a way to dismiss it programmatically? Maybe there is way to send an adb command to close it? Any guidance is really appreciated.

1 Answers1

-2

Duplicating my answer in a similar question:

I've had luck disabling autofill during Espresso tests with custom ViewActions applied whenever text is entered.

        .onView(...)
        .perform(
                new ViewAction() {
                    @Override
                    public Matcher<View> getConstraints() {
                        return Matchers.any(View.class);
                    }

                    @Override
                    public String getDescription() {
                        return "Marking view not important for autofill";
                    }

                    @Override
                    public void perform(UiController uiController, View view) {
                        // Required to disable autofill suggestions during tests on API 26+
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                            view.setImportantForAutofill(View.IMPORTANT_FOR_AUTOFILL_NO);
                        }
                    }
                })
        .perform(click())
        .perform(clearText())
        .perform(typeText(textToType))
        .perform(
                new ViewAction() {
                    @Override
                    public Matcher<View> getConstraints() {
                        return Matchers.any(View.class);
                    }

                    @Override
                    public String getDescription() {
                        return "Dismissing autofill picker";
                    }

                    @Override
                    public void perform(UiController uiController, View view) {
                        // Required to dismiss the autofill picker during tests on API 26+
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                            AutofillManager autofillManager =
                                    view.getContext()
                                            .getSystemService(AutofillManager.class);
                            if (autofillManager != null) autofillManager.cancel();
                        }
                    }
                });
Alan K.
  • 217
  • 1
  • 7