浓咖啡测试,单击X/Y坐标 [英] Espresso test, click X/Y coordinates

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

问题描述

任何想法如何为android做到这一点?我似乎无法创建实际点击的方法.

Any idea how to do this for android? I can't seem to create a method that actually clicks.

我知道您可以通过onview来做到这一点,但是我只想要一个x/y位置.

I know you can do it with onview, but I just want an x/y position.

推荐答案

已经在此处给出了答案.. >

The answer is already given here.

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);
}

这篇关于浓咖啡测试,单击X/Y坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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