|
自己写的一个monkey runner的py文件,实现camera的简单压力
monkey runner这几天研究了一下,由于网络上教程稀少,学得很纠结
现在大概明白什么意思了,
为了避免初入的同学走我一样的弯路,分享出我自己写的一个脚本;
语言很简单,没什么技术含量哦,但初学者还是能看看的,我试验了 是可以运行的,如果你的运行报错了
估计是空格的原因,注意函数,循环的缩进对齐
还有,如果有什么问题,我懂的,我会回答的,刚发现51test这个论坛还不错的,希望大家一起学习研究~
import random
from com.android.monkeyrunner import MonkeyRunner,MonkeyDevice,MonkeyImage
#connect phone device
print("start to connect to the phone")
MonkeyRunner.sleep(1)
device = MonkeyRunner.waitForConnection()
print("connect sucessed!")
#start a Activity,we must get the name of the pakage and acitivity
#you can use "adb logcat ActivityManager:I MyApp *:S"
def startActivity():
#which activity you will run("pakage name/activity name")
print("start an Activity")
connectcomponent="com.android.camera/.Camera"
device.startActivity(component = connectcomponent)
#exit current Activity
def exitActivity():
print("exit an Activity")
device.press("KEYCODE_HOME",'DOWN_AND_UP')
#snap a shot
def snap():
result = device.takeSnapshot()
result.writeToFile("E:\sdk\monkeysnap\shot.png",'png')
print("picture has saved!")
#touch the LCD in random
#circulate times;
def randomtouchLCD(Times):
print("start to touch LCD in random")
LCDWidth=480
LCDHeigth=800
for k in range(0,Times):
i=random.randint(1, Times)
j=random.randint(1, Times)
device.touch(int(LCDWidth*i/Times),int(LCDHeigth*j/Times),"DOWN_AND_UP")
print("touch ",int(LCDWidth*i/Times),int(LCDHeigth*j/Times))
MonkeyRunner.sleep(0.5)
#desgin Testing,you can also add a circulate for better stress testing
def test():
print("testing start!")
startActivity()
randomtouchLCD(10)
exitActivity()
print("testing end!")
test() |
|