monkeyrunner官网和很多地方都是使用的python做为脚本语言的,但是实际上monkeyrunner是支持Java做为脚本语言的,下面是对在monkeyrunner中使用Java的一些尝试,已经全部使用过是可行的,需要引入的jar包包括:
ddmlib.jar;guavalib.jar;sdklib.jar和monkeyrunner.jar
package com.test
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import com.aliyun.smoking.monkeyrunner.extend.ImageProcess;
import com.android.monkeyrunner.adb.AdbBackend;
import com.android.monkeyrunner.core.IMonkeyDevice;
import com.android.monkeyrunner.core.IMonkeyImage;
import com.android.monkeyrunner.core.TouchPressType;
/**
* this class provide java code to call monkeyrunner.jar to execute test case
*
* @author cx
*
*/
public class RunnerProxy {
private IMonkeyDevice device;
private AdbBackend adb;
private static RunnerProxy instance;
public static RunnerProxy getInstance() {
if (instance == null) {
instance = new RunnerProxy();
}
return instance;
}
private RunnerProxy() {
adb = new AdbBackend();
}
/**
* this function will connect to a device, emulator or phone
*/
public void connect() {
assert (adb != null);
device = adb.waitForConnection();
}
/**
* this function clear device connect
*/
public void dispose() {
if (device != null) {
device.dispose();
device = null;
}
}
private String imageDir;
public void setImageDir(String imageDir) {
this.imageDir = imageDir;
}
public String getImageDir() {
return imageDir;
}
private String logDir;
public void setLogDir(String logDir) {
this.logDir = logDir;
}
public String getLogDir() {
return logDir;
}
/**
* this function finish touch operation
*
* @param x
* : x coordinate
* @param y
* : y coordinate
*/
public void touch(int x, int y) {
assert (device != null);
device.shell("sendevent /dev/input/event6 3 48 1");
device.shell("sendevent /dev/input/event6 3 53 " + x);
device.shell("sendevent /dev/input/event6 3 54 " + y);
device.shell("sendevent /dev/input/event6 0 2 0");
device.shell("sendevent /dev/input/event6 0 0 0");
device.shell("sendevent /dev/input/event6 3 48 0");
device.shell("sendevent /dev/input/event6 0 2 0");
device.shell("sendevent /dev/input/event6 0 0 0");
}
/**
* this function finish long touch operation
*
* @param x
* : x coordinate
* @param y
* : y coordinate
*/
public void longTouch(int x, int y) {
assert (device != null);
device.drag(x, y, x, y, 10, 2);
}
/**
* this function finish drag from one point to another point
*
* @param x
* : x coordinate of start point
* @param y
* : y coordinate of start point
* @param endX
* : x coordinate of end point
* @param endY
* : Y coordinate of end point
*
*/
public void drag(int x, int y, int endX, int endY) {
assert (device != null);
device.drag(x, y, endX, endY, 10, 2);
}
/**
* this function finish type a text to view operation
*
* @param value
* : text to type in
*/
public void type(String value) {
assert (device != null);
device.type(value);
}
/**
* this function finish click a key operation
*
* @param keyCode
* : key code
*/
public void press(String keyCode) {
assert (device != null);
device.press(keyCode, TouchPressType.DOWN_AND_UP);
}
/**
* this function finish start an activity operation
*
* @param component
* : activity what to start
*/
public void startActivity(String component) {
assert (device != null);
String action = "android.intent.action.MAIN";
Collection<String> categories = new ArrayList<String>();
categories.add("android.intent.category.LAUNCHER");
device.startActivity(null, action, null, null, categories,
new HashMap<String, Object>(), component, 0);
}
}
分享到:
相关推荐
monkeyrunner+python脚本 monkeyrunner+python脚本 monkeyrunner+python脚本 . monkeyrunner+python脚本 monkeyrunner+python脚本
MonkeyRunner的java代码实现,测试例子,以及用到的测试apk
这是monkeyrunner的自动录制的脚本文件,把此文件放在sdk的tools文件下方,手机连接电脑后直接在命令行运行monkeyrunner recorder.py就可以实现录制功能,前提是电脑上配置好了java、android已经python的环境
用于测试Android计算器,适合初学monkeyrunner测试脚本编写者
MonkeyRunner工具是使用Jython(使用Java编程语言实现的Python)写出来的,它提供了多个API,通过monkeyrunner API 可以写一个Python的程序来模拟操作控制Android设备app,测试其稳定性并通过截屏可以方便地记录出现的...
关于monkeyrunner录制与回放的实现
MonkeyRunner录制脚本相关工具,具体介绍,可以关注公众号,承香墨影(cxmyDev)
附件是MonkeyRunner的相关源码,有需要的可以下载看看。
Monkeyrunner入门使用总结,非常适合初学者学习
monkeyrunner 脚本包括:打印手机屏幕分辨率,阅读页自动翻页功能 下载好以后,首先要确定pc客户端:adb devices 有设备连接
用于回放recorder录制的脚本的工具
monkeyrunner_py脚本
Android应用Monkeyrunner测试脚本,通过脚本记录测试指令后进行回放,可实现自动化功能测试
NULL 博文链接:https://jasonshieh.iteye.com/blog/1169583
monkeyrunner为android系统新公开的一个测试工具。有助于开发人员通过脚本部署较大规模的自动化测试。
比较了monkeyrunner和monkey这两个好兄弟,同时把monkeyrunner实现的脚本集成到eclipse-pydev的环境中运行
MonkeyRunner工具是使用Jython(使用Java编程语言实现的Python)写出来的,它提供了多个API,通过monkeyrunner API 可以写一个Python的程序来模拟操作控制Android设备app,测试其稳定性并通过截屏可以方便地记录出现的...
1.在窗口输入 monkeyrunner monkey_recorder.py 调用录制脚本工具 2.在窗口输入 monkeyrunner monkey_playback.py d:\game 执行已经录制的脚本工具 3.E:\Android SDK\ tools>monkeyrunner test.mr 自行写的脚本...
主要描述如何使用monkeyrunner,以及脚本的使用
通过android SDK monkeyrunner编写的自动发送email的自动化脚本,基于python语言,使用者可以自定义发送的次数,自定义发送的内容,自定义发送给指定邮箱。