按边界/坐标单击 [英] Click by bounds / coordinates

查看:26
本文介绍了按边界/坐标单击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道 Espresso 可以按边界点击 UiAutomator 可以.(x 和 y 坐标)我已经通读了文档,但似乎找不到它.任何帮助表示赞赏.谢谢

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.

推荐答案

Espresso 有 GeneralClickAction,这是ViewActions的底层实现click()doubleClick()longClick().

Espresso has the GeneralClickAction, this is the underlying implementation of ViewActions click(), doubleClick(), and longClick().

GeneralClickAction 的构造函数将 CoordinatesProvider 作为第二个参数.所以基本的想法是创建一个静态的 ViewAction getter,它提供一个自定义的 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);
}

关于 Espresso 的一般建议:与其寻找文档(几乎没有),不如查看源代码.Espresso 是开源的,源代码本身质量非常好.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆