我知道浓缩咖啡有可能以这种方式点击UiAutomator 可以 https://stackoverflow.com/questions/20519905/uiautomator-click-on-a-imagebutton-with-no-text-or-content-desc。 (x 和 y 坐标)我已阅读文档,但似乎找不到它。任何帮助表示赞赏。谢谢
Edit
我发现这个链接 https://android-test-kit.googlecode.com/git/docs/javadocs/apidocs/com/google/android/apps/common/testing/ui/espresso/action/Tapper.html,但没有如何使用它的示例,我主要关心的是UiController
是或如何使用它。
浓缩咖啡有GeneralClickAction http://code.google.com/p/android-test-kit/source/browse/espresso/lib/src/main/java/com/google/android/apps/common/testing/ui/espresso/action/GeneralClickAction.java,这是ViewActions的底层实现click()
, doubleClick()
, and longClick()
.
The GeneralClickAction
的构造函数需要一个CoordinatesProvider
作为第二个参数。
所以基本的想法是创建一个静态的ViewAction
getter 提供自定义CoordinatesProvider
。像这样的事情:
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);
}
关于 Espresso 的一般建议:不要寻找文档(实际上没有),而是查看源代码。 Espresso 是开源的,源代码本身质量非常好。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)