如何使用浓缩咖啡在android上模拟AlertDialog窗口外的触摸
我的依赖项:如何使用浓缩咖啡在android上模拟AlertDialog窗口外的触摸,android,testing,integration-testing,android-espresso,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:espres
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窗口外的点击,以在关闭时检查某些内容
如何操作?在许多情况下,您可以通过创建自定义的ClickAction来执行此操作:
public static ViewAction clickXY(final int x, final int y){
return new GeneralClickAction(
Tap.SINGLE,
new CoordinatesProvider() {
@Override
public float[] calculateCoordinates(View view) {
final int[] screenPos = new int[2];
view.getLocationOnScreen(screenPos);
final float screenX = screenPos[0] + x;
final float screenY = screenPos[1] + y;
float[] coordinates = {screenX, screenY};
return coordinates;
}
},
Press.FINGER);
}
然后,您可以在对话框中找到一个已知视图(说“确定”按钮),并按如下方式调用它:
onView(withText("OK")).perform(clickXY(-200, 200));
显然,您使用的x/y值将取决于您的具体情况。检查
浓缩咖啡做不到这一点
您需要在浓缩咖啡测试中使用uiautomator,将此添加到项目的分数中:
androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.1'
对话框出现后,您可以单击屏幕上的任意坐标:
UiDevice device = UiDevice.getInstance(getInstrumentation());
device.click(x,y);
这将关闭您的对话框您是如何解决此问题的?@Rakesh未解决:(