Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable the new Autofill feature from Android Oreo for espresso tests

Running tests on android devices with sdk 26 causes them to fail because of the new Autofill feature that hides the fields when espresso are trying to click them.

Im running my tests on firebase test lab so I cannot disable them manually on my tests devices.

Some images:

1. Password is visible before clicking username field.

enter image description here

2. After clicking username field password field is hidden by this Autofill dialog:

enter image description here

3. After login it shows another Fill dialog:

enter image description here

Espresso cant click now password field since the autofill dialog is hiding my field and fail.

Using AutofillManager#disableAutofillServices() only disabled the #2. dialog but #3. is still there.

How to disable Autofill on test devices?

like image 325
Daniel Gomez Rico Avatar asked Oct 18 '17 14:10

Daniel Gomez Rico


1 Answers

Based on documentation, you can disable Autofill services using AutofillManager#disableAutofillServices() API:

If the app calling this API has enabled autofill services they will be disabled.

Usage:

      val autofillManager: AutofillManager = context.getSystemService(AutofillManager::class.java)     autofillManager.disableAutofillServices()  

You can do this in @Before step of your test.

like image 71
azizbekian Avatar answered Oct 24 '22 22:10

azizbekian