[android]android自动化测试四之Monkey与MonkeyRunner
程序员文章站
2022-03-02 16:59:01
...
请大家用下面的范例来做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
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
上一篇: [android]android自动化测试七之动态AVD硬件参数
下一篇: 浅述PHP设计模式(6)
推荐阅读
-
android monkey自动化测试改为java调用monkeyrunner Api
-
Android开发之图形图像与动画(四)AnimationListener简介
-
android monkey自动化测试改为java调用monkeyrunner Api
-
Android开发之图形图像与动画(四)AnimationListener简介
-
实现android自动化测试部署与运行Shell脚本分享
-
AS+Appium+Java+Win自动化测试之Appium的Java测试脚本封装(Android测试)
-
Android自动化测试工具——Monkey
-
android自动化测试之元素抓取
-
关于Android自动化测试Monkey和MonkeyRunner不能正常运行的说明
-
[Android自动化测试(四)] robot framework+appium元素定位