[android]android自动化测试十三之JavaMonkey跨APP操作

使用到的jar包均在android sdk中,chimpchat.jar,ddmlib.jar,guavalib.jar,sdklib.jar

代码

import java.util.TreeMap;

import com.android.chimpchat.ChimpChat;
import com.android.chimpchat.core.IChimpDevice;


public class JavaMonkey {

private static final String ADB = "/home/eamon/android-sdk/android-sdk-linux_x86/platform-tools/adb";
private static final long TIMEOUT = 5000;
private ChimpChat mChimpchat;
private IChimpDevice mDevice;

/**
* Constructor
*/
public JavaMonkey() {
super();
TreeMap<String, String> options = new TreeMap<String, String>();
options.put("backend", "adb");
options.put("adbLocation", ADB);
mChimpchat = ChimpChat.getInstance(options);
}

/**
* Initializes the JavaMonkey.
*/
private void init() {
mDevice = mChimpchat.waitForConnection(TIMEOUT, ".*");
if ( mDevice == null ) {
throw new RuntimeException("Couldn't connect.");
}
mDevice.wake();
}

/**
* List all properties.
*/
private void listProperties() {
if ( mDevice == null ) {
throw new IllegalStateException("init() must be called first.");
}

mDevice.drag(10, 10, 140, 280, 136, 2);
for (String prop: mDevice.getPropertyList()) {
System.out.println(prop + ": " + mDevice.getProperty(prop));
}
}

/**
* Terminates this JavaMonkey.
*/
private void shutdown() {
mChimpchat.shutdown();
mDevice = null;
}

/**
* @param args
*/
public static void main(String[] args) {
final JavaMonkey javaMonkey = new JavaMonkey();
javaMonkey.init();
javaMonkey.listProperties();
javaMonkey.shutdown();
}

}




此方法可以拖拽statusbar,可以获取手机基本信息等。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值