MonkeyRunner 录制和播放脚本,及碰到的一些问题整理


MonkeyRunner 录制和播放脚本,及碰到的一些问题整理

自己的SDK位置:比如d:\android_sdk_windows,下文都当做$SDK

1.$SDK\tools下面如果没有monkeyrunner可能是因为SDK版本过低。最好升级到2.3

2.$SDK\tools\lib一定要存在。

3.系统的环境变量里面一定要指向$SDK\tools

4.建议下载eclipse ,在eclipse里面点击DDMS监控monkeyrunner的操作

5.建议下载最新版本adb.exe,解决有的模拟器或者真机连接电脑,无法使用adb,一输入adb.exe回车就提示error ,killing

下载连接:http://android.googlecode.com/issues/attachment?aid=8293722374312378755&name=adb.exe&token=b5fbe373d5474fb0ee49239fa8accd03

6

在使用monkeyrunner之前,请大家到这里  http://www.skycn.com/search.php?ss_name=activepython&sf=index 下载activepython 并安装好它。

7.$SDK\tools\monkeyrunner.bat  运行之后,如果提示如下:

Exception in thread "main" java.lang.NoClassDefFoundError: com/android/chimpchat/ChimpChat
        at com.android.monkeyrunner.MonkeyRunnerStarter.<init>(MonkeyRunnerStarter.java:60)
        at com.android.monkeyrunner.MonkeyRunnerStarter.main(MonkeyRunnerStarter.java:188)
Caused by: java.lang.ClassNotFoundException: com.android.chimpchat.ChimpChat
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 2 more

说明SDK中缺少了 ChimpChat.jar,可以去 http://code.google.com/p/aster/downloads/list 下载一个最新的aster 的压缩包。这个aster 的意思是 Android System Testing Environment and Runtime. 在这个压缩包内有 aster\dist\jar\chimpchat.jar  请将这个jar包复制到你的SDK\tools\lib 目录。








#Usage: monkeyrunner recorder.py
#recorder.py  http://mirror.yongbok.net/linux/android/repository/platform/sdk/monkeyrunner/scripts/monkey_recorder.py
from com.android.monkeyrunner import MonkeyRunner as mr
from com.android.monkeyrunner.recorder import MonkeyRecorder as recorder

device = mr.waitForConnection()
recorder.start(device)
#END recorder.py
#Press ExportAction to save recorded scrip to a file
#Example of result:
#PRESS|{'name':'MENU','type':'downAndUp',}
#TOUCH|{'x':190,'y':195,'type':'downAndUp',}
#TYPE|{'message':'',}
============================================================================================
#Usage: monkeyrunner playback.py "myscript"
#playback.py   http://mirror.yongbok.net/linux/android/repository/platform/sdk/monkeyrunner/scripts/monkey_playback.py
import sys
from com.android.monkeyrunner import MonkeyRunner

# The format of the file we are parsing is very carfeully constructed.
# Each line corresponds to a single command.  The line is split into 2
# parts with a | character.  Text to the left of the pipe denotes
# which command to run.  The text to the right of the pipe is a python
# dictionary (it can be evaled into existence) that specifies the
# arguments for the command.  In most cases, this directly maps to the
# keyword argument dictionary that could be passed to the underlying
# command. 

# Lookup table to map command strings to functions that implement that
# command.
CMD_MAP = {
    'TOUCH': lambda dev, arg: dev.touch(**arg),
    'DRAG': lambda dev, arg: dev.drag(**arg),
    'PRESS': lambda dev, arg: dev.press(**arg),
    'TYPE': lambda dev, arg: dev.type(**arg),
    'WAIT': lambda dev, arg: MonkeyRunner.sleep(**arg)
    }

# Process a single file for the specified device.
def process_file(fp, device):
    for line in fp:
        (cmd, rest) = line.split('|')
        try:
            # Parse the pydict
            rest = eval(rest)
        except:
            print 'unable to parse options'
            continue

        if cmd not in CMD_MAP:
            print 'unknown command: ' + cmd
            continue

        CMD_MAP[cmd](device, rest)


def main():
    file = sys.argv[1]
    fp = open(file, 'r')

    device = MonkeyRunner.waitForConnection()
    
    process_file(fp, device)
    fp.close();
    

if __name__ == '__main__':
    main()


  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值