java根据id查询用户对象_Android 自动化测试 根据ID查找对象

[java]代码库package com.robot.dream.test;

import com.android.chimpchat.adb.AdbBackend;

import com.android.chimpchat.adb.LinearInterpolator.Point;

import com.android.chimpchat.core.IChimpDevice;

import com.android.chimpchat.core.TouchPressType;

import com.android.chimpchat.hierarchyviewer.HierarchyViewer;

import com.android.hierarchyviewerlib.models.ViewNode;

public class TestRobotDream {

public static Point getAbsoluteCenterOfView(ViewNode node) {

Point point = getAbsolutePositionOfView(node);

return new Point(point.getX() + node.width / 2, point.getY() + node.height / 2);

}

public static Point getAbsolutePositionOfView(ViewNode node) {

int x = node.left;

int y = node.top;

for(ViewNode p = node.parent; p != null; p = p.parent) {

x += p.left - p.scrollX;

y += p.top - p.scrollY;

}

return new Point(x, y);

}

/**

* @param args

*/

public static void main(String[] args) {

System.out.println("start");

IChimpDevice device = new AdbBackend().waitForConnection();

System.out.println("device ok");

device.shell("am start com.robot.dream/com.robot.dream.MainActivity");

System.out.println("monkey test connected");

HierarchyViewer view = device.getHierarchyViewer();

ViewNode viewNode = view.findViewById("id/center_image");

//Point p = HierarchyViewer.getAbsoluteCenterOfView(viewNode);

Point p = getAbsoluteCenterOfView(viewNode);

//EasyMonkeyDevice easyDevice = new EasyMonkeyDevice(null);

System.out.println(" x: "+p.getX() + " y: "+p.getY());

//By.id("");

//By selector = By.id("");

System.out.println("touch 1 ok");

device.touch(p.getX(), p.getY(), TouchPressType.DOWN_AND_UP);

System.out.println("touch 2 ok");

device.touch(p.getX(), p.getY(), TouchPressType.DOWN_AND_UP);

//easyDevice.touch(selector, TouchPressType.DOWN_AND_UP);

device.dispose();

}

}

//源代码片段来自云代码http://yuncode.net

694748ed64b9390909c0d88230893790.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值