点击通过边界/坐标坐标、边界

由网友(拥挤得只剩下寂寞)分享简介:我知道它有可能居preSSO通过边界的方式UiAutomator确实。 (x和y坐标),我已经通过文档阅读,但我似乎无法找到它。任何帮助是AP preciated。谢谢I know it is possible for Espresso to click by bounds the way UiAutomator d...

我知道它有可能居preSSO通过边界的方式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

修改 我发现此链接,但没有例子如何使用它,我主要关注的是这种 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有GeneralClickAction,这是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.

阅读全文

相关推荐

最新文章