12

在安卓設備上運行sdk 26的測試會導致它們失敗,因爲當特濃咖啡嘗試點擊它們時隱藏字段的新功能Autofill如何從Android Oreo禁用新的自動填充功能以進行濃咖啡測試

我在firebase測試實驗室運行我的測試,所以我不能在我的測試設備上手動禁用它們。

部分圖片:

1.密碼在點擊用戶名字段之前是可見的。點擊用戶名密碼場場是由該自動填充對話框隱藏

enter image description here

2.後:

enter image description here

3.登錄後,它顯示了另一種填充對話框:

enter image description here

濃咖啡不能立即點擊密碼字段自autofi ll對話框隱藏了我的字段並fail。使用AutofillManager#disableAutofillServices()僅禁用#2。對話框但#3。仍然在那裏。

如何在測試設備上禁用自動填充功能?

+0

每一個答案被刪除,設置>系統>高級>自動填充服務>設置爲 「無」。 – CommonsWare

+0

@CommonsWare我沒有權限訪問雲端設備上的設置,比如firebase,我需要在運行測試之前禁用這些設置 – Caipivara

回答

1

adb shell pm disable com.google.android.gms/com.google.android.gms.autofill.service.AutofillService

這應該禁用自動填充服務。這與手動在系統設置中關閉自動填充服務相同。它至少在仿真器上工作過。但是這需要root權限。

禁用自動填充服務的另一種方法是更改​​autofill_service設置。

adb shell settings put secure autofill_service null

+0

最後一個'adb shell設置把安全autofill_service null'工作!謝啦 – Caipivara

2

基於文檔,可以禁止使用AutofillManager#disableAutofillServices() API自動填充服務:

如果應用程序在調用此API已啓用自動填充服務,它們將被禁用。

用法:

 

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

您可以在@Before步測試的做到這一點。

+0

它刪除了「點擊以讓Google」對話框,但它仍然顯示「使用GOOGLE保存與AUTOFILL的密碼」對話框。 – Caipivara

+1

我沒有O設備,我無法在模擬器中找到「使用Google自動填充」應用程序。我想你可以嘗試通過adb shell命令([how?](https://stackoverflow.com/a/35157119/1083957))在執行測試時禁用該應用程序:'adb shell pm disable package.name.of。 autofill.with.google'。 – azizbekian

+0

你可以在Android O仿真器的'Settings'中找到它。 – Caipivara

0

測試時禁用自動填充。在gradle這個定義的TestRunner類

defaultConfig { 
    testInstrumentationRunner "com.cover.android.TestRunner" 
} 

然後

public class TestRunner extends AndroidJUnitRunner { 

@Override 
public void onCreate(Bundle arguments) { 
    super.onCreate(arguments); 
    CustomEditText.TESTING = TRUE; 
    } 

再使用的EditText

public class CustomEditText extends AppCompatEditText { 
public static boolean TESTING = false; 
public CustomEditText(Context context) { 
    super(context); 
} 

@Override 
public int getAutofillType() { 
    return TESTING? AUTOFILL_TYPE_NONE : super.getAutofillType(); 
} 
+0

在我的應用程序中更改所有'EditText'只是爲了這個purpuse感覺不好,但是謝謝 – Caipivara

0

的定製版本根據文件: 視圖時重點是數據集的一部分。當通過registerCallback(AutofillCallback)註冊AutofillManager.AutofillCallback來顯示可供件時,可以通知應用程序。當用戶從可供件中選擇一個數據集時,通過調用自動填充(AutofillValue)或自動填充(SparseArray)來自動填充數據集中的所有視圖。

當發生下列情況之一的上下文然後在完成:

  1. 提交()被調用或所有可轉存的視圖都消失了。
  2. cancel()被調用。

從任何線程調用它的方法是安全的。

必須使用Context.getSystemService(Class)和參數AutofillManager.class來獲取此類的實例。

使用:disableAutofillServices()方法來區分服務。