android - 如何使用 espresso 在 android 上模拟 AlertDialog 窗口外的触摸

标签 android testing integration-testing android-espresso

我的依赖项:

androidTestCompile 'com.android.support.test:runner:0.3' 
androidTestCompile 'com.android.support.test:rules:0.3' 
androidTestCompile 'com.android.support:support-annotations:23.0.1'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2' 
androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.2') { 
    exclude group: 'com.android.support', module: 'appcompat'
    exclude group: 'com.android.support', module: 'support-v4'
    exclude module: 'recyclerview-v7' 
} 
androidTestCompile 'junit:junit:4.12'

我找不到一种方法来模拟在 AlertDialog 窗口外单击以在它关闭时检查某些内容...

我该怎么做?

最佳答案

检查 my answer.

Espresso 做不到这一点。

您需要在 Espresso 测试中使用 uiautomator,将其添加到项目的 gradle 中:

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

对话框出现后,您可以在屏幕上的任意坐标处单击:

UiDevice device = UiDevice.getInstance(getInstrumentation());
        device.click(x,y);

这将关闭你的对话框

关于android - 如何使用 espresso 在 android 上模拟 AlertDialog 窗口外的触摸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32600334/

相关文章:

android - Android APK 签名存在哪些陷阱?

android - onActivityResult 未在 fragment 中调用

java - 使用资源构建java库

ruby - 赛璐珞代码测试方法

java - 在phpbb3中获取form_token和time_creation

angularjs - 如何修改 Protractor html 屏幕截图报告器以显示每个 “expect”(断言)而不是规范文件中每个 “it” block 的报告

oracle - 如何使用 Liquibase 更改 Oracle 和 HSQL DB 上的 View (HSQLDB 不支持 ReplaceIfExists)

Android:在 map 上显示和移动当前位置

testing - Gradle Testkit无法将插件添加到自定义源集

git - 在 Git-Flow 中一次测试多个功能