点击通过边界/坐标 [英] Click by bounds / coordinates
问题描述
我知道它有可能居preSSO通过边界的方式<一点击href="http://stackoverflow.com/questions/20519905/uiautomator-click-on-a-imagebutton-with-no-text-or-content-desc">UiAutomator确实。 (x和y坐标),我已经通过文档阅读,但我似乎无法找到它。任何帮助是AP preciated。谢谢
I know it is possible for Espresso to click by bounds the way UiAutomator does. (x and y coordinates) I have read through the documentation but I can't seem to find it. Any help is appreciated. Thanks
修改
我发现<一href="https://android-test-kit.google$c$c.com/git/docs/javadocs/apidocs/com/google/android/apps/common/testing/ui/es$p$psso/action/Tapper.html"相对=nofollow>此链接,但没有例子如何使用它,我主要关注的是这种 UiController
是,或如何使用它。
Edit
I found this link, but no examples how to use it, My main concern with this is the UiController
is or how to use it.
推荐答案
居preSSO有<一个href="http://$c$c.google.com/p/android-test-kit/source/browse/es$p$psso/lib/src/main/java/com/google/android/apps/common/testing/ui/es$p$psso/action/GeneralClickAction.java"><$c$c>GeneralClickAction$c$c>,这是ViewActions的底层实现点击()
, doubleClick如果()
和 longClick( )
。
Espresso has the GeneralClickAction
, this is the underlying implementation of ViewActions click()
, doubleClick()
, and longClick()
.
在 GeneralClickAction
的构造函数需要 CoordinatesProvider
作为第二个参数。
所以基本的想法是创建一个静态 ViewAction
吸气它提供了一个自定义的 CoordinatesProvider
。事情是这样的:
The GeneralClickAction
's constructor takes a CoordinatesProvider
as second argument.
So the basic idea is to create a static ViewAction
getter which provides a custom CoordinatesProvider
. Something like this:
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);
}
与长者preSSO一般的建议:与其找文件(有几乎没有),看看源$ C $ C。居preSSO是开源和源$ C $ C本身是真正的好品质。
A general advice with Espresso: instead of looking for documentation (there's virtually none), look at the source code. Espresso is open source and the source code itself is of really good quality.
这篇关于点击通过边界/坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!