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()方法来区分服务。