前一篇文章是写 Android 自己的自动化测试(1)如何安装和卸载应用程序(java) ,以下再探索一下假设在普通java应用程序中,依据ID来查找对象

1、类库依赖:

The library dependencies are:

chimpchat.jar,common.jar,ddmlib.jar,guava-13.0.1.jar,sdklib.jar,hierchyviewer2lib.jar

They can all be found in the sdk/tools/lib subdirectory of the ADT bundle.

2、代码:

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

3、局限性:

以上的自己主动化測试,这样的方式是採用monkeyrunner相应的java, lib来实现的。

所以其本质上就是java版的monkey runner

它能够实现的功能。基本上monkey runner也都能实现,假设用java实现。文档少。材料少。有点得不偿失。

探索用java来实现,最大的收获,是对这些測试相关类的学习。

4、后面会介绍些 Android monkeyrunner&Android Unit Auto Test&Android Code Coverage Test

Android 自己的自动化测试(2)依据ID查找对象(java)的更多相关文章

  1. Android 自己主动化測试(3)<monkeyrunner> 依据ID查找对象&touch&type (python)

    我在之前的两篇文章中用java来实现过 Android 自己主动化測试(1)怎样安装和卸载一个应用(java).Android 自己主动化測试(2)依据ID查找对象(java). 可是本质上都是用mo ...

  2. Android 自己的自动化测试(4)<uiautomator>

    在前面的系列文章.我与介绍java实现 Android 自己主动化測试(1)怎样安装和卸载一个应用(java).Android 自己主动化測试(2)依据ID查找对象(java):然后又介绍了用pyth ...

  3. Android 自己的自动化测试(5)<robotium>

    大约Android自己的自动化测试UI测试,前出台Android 自己主动化測试(4)<uiautomator>, 在android原生的单元測试框架上,利用uiautomator.jar ...

  4. android真机自动化测试

    appium执行用例时报错问题: 问题解析: 一般该种情况都是因为来连接了多个设备,验证办法:cmd->执行adb devices  看结果是否是多个devices ,如果是这个问题,停掉多余设 ...

  5. Android Native App自动化测试实战讲解(上)(基于python)

    1.Native App自动化测试及Appuim框架介绍 android平台提供了一个基于java语言的测试框架uiautomator,它一个测试的Java库,包含了创建UI测试的各种API和执行自动 ...

  6. Android Hybrid App自动化测试实战讲解(基于python)

    1.Hybrid App自动化测试概要 什么是Hybrid App? Hybrid App(混合模式移动应用)是指介于web-app.native-app这两者之间的app,兼具“Native App ...

  7. python在Android下的自动化测试用法

    # This Python file uses the following encoding: utf-8from com.android.monkeyrunner import MonkeyRunn ...

  8. 使用FindControl("id")查找控件 返回值都是Null的问题

    做了一个通过字符串ID查找页面控件并且给页面控件赋值的功能,过程中遇到了this.FindControl("id")返回值都是Null的问题,记录一下解决办法. 问题的原因是我所要 ...

  9. Android Native App自动化测试实战讲解(下)(基于python)

    6.Appuim自动化测试框架API讲解与案例实践(三) 如图1,可以在主函数里通过TestSuite来指定执行某一个测试用例: 6.1,scroll():如图2 从图3中可以看到当前页面的所有元素r ...

随机推荐

  1. VirtualBox集群建立和网络配置

    安装 1. 安装 安装Oracle VM VirtualBox之后,新建一个虚拟机,制定好内存等信息,开始安装操作系统,这里安装ubuntu-12.04.2-desktop-i386版本. 2. 拷贝 ...

  2. datarow用linq查询

    List<string> f_guids = (from DataRow dr in dt2.Rows select dr["f_GUID"].ToString()). ...

  3. 获取option中间的值

    <select name="wytype" id="wytype"> <option value="">—请选择—& ...

  4. Common Lisp学习笔记(0):从SLIME开始 | 优哉·幽斋

    Common Lisp学习笔记(0):从SLIME开始 | 优哉·幽斋 Common Lisp学习笔记(0):从SLIME开始

  5. premake 在64位Ubuntu系统下编译32位GCC程序

    首先,要安装GCC 4.8, 参考前文:Ubuntu 12.04 & 13.04 安装 GCC4.8.1 其中,重点是安装multilib apt-get install gcc-4.8-mu ...

  6. Cocos2d-x 3.0 创建一个场景,并设置现场的时候,项目开始执行上主动

    头 #ifndef __TEST_H__ #define __TEST_H__ #include "cocos2d.h" USING_NS_CC; class Test : pub ...

  7. 拆分字符串,GetHtmlByWebBrowser,UnicodeToMBCS,提升进程权限

    1. // 根据字符串,拆分字符串,相当于vb中的split函数 function SplitString(const Source, ch: string): TStringList; var te ...

  8. linux expect, spawn用法小记

    linux expect, spawn用法小记_IT民工_百度空间 linux expect, spawn用法小记 版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明http://sys ...

  9. achieve aop through xml

    The main way to achive AOP is deploying a xml file. Now a xml file is presented to be a explanation ...

  10. 在C#中子线程如何操作主窗口线程上的控件

    在C#中子线程怎样操作主线程中窗口上控件 在C#中,直接在子线程中对窗口上的控件操作是会出现异常,这是因为子线程和运行窗口的线程是不同的空间,因此想要在子线程来操作窗口上的控件.是不可能简单的通过控件 ...