8

I am unable to perform my android espresso unit test and it has failed with:

// (kotlin syntax)
closeSoftKeyboard()
onView(withId(R.id.et_login_mobile_number)).perform(TypeTextAction(invalidMobileNo))
closeSoftKeyboard()

androidx.test.espresso.InjectEventSecurityException: java.lang.SecurityException: Injecting to another application requires INJECT_EVENTS permission.

I finally learned that: ANY UNEXPECTED animation appeared on UI that is undergoing automated testing could interrupt the process.

So I suspect this is due to the Google Password Manager that suggesting the list of saved password keep popping up and it might be the one causing the interruption.

enter image description here

What I'm looking now is: THE WAY OF TURNING OFF GOOGLE PASSWORD MANAGER FROM SUGGESTING SAVED PASSWORD

All I keep found is

Manage offers to save passwords

And there is no way to turn it off / disable it


enter image description here


After I ended up delete all the saved passwords from Google Password Manager and now it turned up suggest autofill text (Kindly compare both screenshot)

I have included attributes as followed, it still DOES NOT PREVENT autofill to device with Android 8 and above.

android:inputType="number|textNoSuggestions|textFilter"

enter image description here


elliotching
  • 972
  • 1
  • 10
  • 33

3 Answers3

12

According to this Answer ,

android:importantForAutofill="no"

works to prevent both default autofill and Google Password Manager from Android 8 and above.

elliotching
  • 972
  • 1
  • 10
  • 33
2

I think you should try deleting the current saved passwords and adding this app in declined apps' list. This was the app will not have any options to autofill and the pop-up will not show.

Let me know if this helps. Good luck.

Akanshi Srivastava
  • 1,160
  • 13
  • 24
  • Yes, one way is delete all the saved password for this app, however, what if I want to enable it in future? all the password has been cleared. This is why I prefer if there is a setting to enable and disable it. – elliotching Oct 01 '19 at 09:17
2

Insert below line after onCreate method:

getWindow().getDecorView().setImportantForAutofill(View.IMPORTANT_FOR_AUTOFILL_NO_EXCLUDE_DESCENDANTS);

Jay makwana
  • 97
  • 1
  • 4