在android上做espresso ui测试,并试图绕过智能锁屏。问题是,我们正在firebase中进行测试,而且无法关闭整个设备上的智能锁,因为它们在云中(我不相信)。弹出窗口也不是应用程序本身的一部分,因此我无法使用听诊器或布局检查器获取ID。我相信这是另一个应用程序(或操作系统功能)在我们的应用程序之上绘图。
我怎样才能按下浓缩咖啡里的“不谢谢”或“从不”按钮?
android - Espresso测试:以编程方式选择“永不”智能锁保存密码-LMLPHP

最佳答案

你可以使用uiautomator
graddle:

androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.3'

并将其添加到代码中:
waitSeconds(10) // Waiting for smartlock window
val uiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
val currentPackageName = uiDevice.currentPackageName
if (currentPackageName != "your.app.package") {
     uiDevice.pressBack()
}

07-27 17:13