当前位置: 代码迷 >> Android >> [android]android自动化测试4之Monkey与MonkeyRunner
  详细解决方案

[android]android自动化测试4之Monkey与MonkeyRunner

热度:82   发布时间:2016-05-01 19:47:59.0
[android]android自动化测试四之Monkey与MonkeyRunner
请大家用下面的范例来做Monkey test . 时间延迟设为300毫秒,基本上符合实际上的触摸间隔。各位只需要改变标记为黄色的部分。

adb shell monkey -p com.xxxx.news -s 12345 --pct-trackball 0 --pct-nav 0 --throttle 300 --pct-anyevent 4 --ignore-crashes 30000 &
adb shell monkey -p com.xxxx.systeminfo -s 12345 --pct-trackball 0 --pct-nav 0 --throttle 300 --pct-anyevent 4 --ignore-crashes 30000 &
adb shell monkey -p com.xxxx.todo -s 12345 --pct-trackball 0 --pct-nav 0 --throttle 300 --pct-anyevent 4 --ignore-crashes 30000


具体参数查看
http://developer.android.com/guide/developing/tools/monkey.html


一个简单的monkey脚本:

# monkey
tap 100 180
type 123
tap 100 280
press DEL
press DEL
press DEL
press DEL
press DEL
press DEL
press DEL
press DEL
type -460.3


调用monkey脚本
$ adb shell am start -n com.example.aatg.tc/.TemperatureConverterActivity
This is informed in the log by this line:
Starting: Intent { cmp=com.example.aatg.tc/.TemperatureConverterActivity }
Once the application has started you can send the events using the script and the
netcat utility:
$ nc localhost 1080 < monkey.txt


一个monkeyRunner的脚本:monkey_playback.py


#! /usr/bin/env monkeyrunner
'''
Created on 2011-03-12
@author: diego
'''
import sys
# Imports the monkeyrunner modules used by this program
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice,
MonkeyImage
# Connects to the current device, returning a MonkeyDevice object
device = MonkeyRunner.waitForConnection()
if not device:
print >> sys.stderr, "Couldn't get connection"
sys.exit(1)
device.startActivity(component='com.example.aatg.tc/.
TemperatureConverterActivity')
MonkeyRunner.sleep(3.0)
device.type("123")
# Takes a screenshot
MonkeyRunner.sleep(3.0)
result = device.takeSnapshot()
# Writes the screenshot to a file
result.writeToFile('/tmp/device.png','png')
device.press('KEYCODE_BACK', 'DOWN_AND_UP')

更详细的文章
http://www.cnblogs.com/yyangblog/archive/2011/03/10/1980086.html
  相关解决方案