MonkeyRunner_Monkeyrunner里使用Java做为脚本语言(1)
来源:互联网 发布:显示屏超频软件 编辑:程序博客网 时间:2024/06/05 02:28
monkeyrunner官网和很多地方都是使用的python做为脚本语言的,但是实际上monkeyrunner是支持Java做为脚本语言的,下面是对在monkeyrunner中使用Java的一些尝试,已经全部使用过是可行的,需要引入的jar包包括:
ddmlib.jar;guavalib.jar;sdklib.jar和monkeyrunner.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_Monkeyrunner里使用Java做为脚本语言(1)
- 在Java中使用脚本语言
- Java中使用LUA脚本语言
- Java中使用Lua脚本语言
- JAVA中脚本语言的使用
- MonkeyRunner_MonkeyRunner API简单使用帮助.(附示例)
- 在Java中使用Lua脚本语言
- 如何在Java中使用Lua脚本语言
- 在Java中使用Lua脚本语言
- Java中使用Lua脚本语言2
- 使用脚本语言
- maven 项目 springmvc spring 使用SLF4J和 LogBack 做为日志 xml里配置即可
- 做为脚本语言来说perl和python那个更有优势?
- ASP系列讲座(四)使用脚本语言
- java中调用lua脚本语言1
- java中调用lua脚本语言1
- STM32 systick做为系统时间使用(非简单延时)
- 在Java中使用脚本语言 javax.script探秘
- PLSQL经验
- 备份服务器上的sql server数据库到本机
- Mac OS,读取plist文件的方法
- 与其哭泣,还不如学会坚强
- 黑马程序员_android笔记7
- MonkeyRunner_Monkeyrunner里使用Java做为脚本语言(1)
- asp.net操作 META信息
- 在window 2003中删除一定时间内文件的批处理
- Oracle开发包
- MSSQL数据库数据导出insert
- 解决Xcode模拟器attaching卡死问题
- SQL Server 创建用户
- mmap实现进程间共享内存
- Window.Event.KeyCode 中键的含义