Monkey Runner常用语句

Monkey Runner常用语句

#Imports the monkeyrunner modules used by this program
from com.android.monkeyrunner import MonkeyRunner,MonkeyDevice,MonkeyImage

#Connects to the current device,retuning a MonkeyDevice object
device=MonkeyRunner.waitForConnection()

#Install the Android package.Notice that this method returns a boolean,so you #can test to see if the installation worked.
device.installPackage('./ApiDemos.apk')

#Remove the Android package.
device.removePackage('com.example.android.apis')

#Runs the component
device.startActivity(component='com.example.android.apis/.ApiDemos')

#Presses the Menu button
device.press('KEYCODE_MENU','DOWN_AND_UP')

#Takes a screenshot
result=device.takeSnapshot()

#Writes the screenshot to a file
result.writeToFile('./shot1.png','png')

#Delay(second)
MonkeyRunner.sleep(3)

#Slides touch screen
for i in range(1,70):
    device.drag((250,850),(250,110),0.1,10) //Start,End,duration,steps

for i in range(1,70):
    device.drag((250,110),(250,850),0.1,10)
MonkeyRunner.sleep(1)

#Touch screen
device.touch(507,72,"DOWN_AND_UP")

#exc adb shell
device.shell("input text group01")

#Presses keys
device.press('KEYCODE_HOME','DOWN_AND_UP')

#menu:        KEYCODE_MENU
#home:        KEYCODE_HOME
#back:        KEYCODE_BACK
#search:    KEYCODE_SEARCH
#call:        KEYCODE_CALL
#end:        KEYCODE_ENDCALL
#NAV up:    KEYCODE_DPAD_UP
#NAV down:    KEYCODE_DPAD_DOWN
#NAV left:    KEYCODE_DPAD_LEFT
#NAV right:    KEYCODE_DPAD_RIGHT
#OK:        KEYCODE_DPAD_CENTER
#volume up:    KEYCODE_VOLUME_UP
#volume down:    KEYCODE_VOLUME_DOWN
#power:        KEYCODE_POWER
#power:        KEYCODE_CAMERA

#Input asd
device.type('asd')

#Input enter
device.press('KEYCODE_ENTER')

#Recode
monkeyrunner monkey_recorder.py
save as:monkey_test.mr

#play back
monkeyrunner monkey_playback.py monkey_test.mr

#help and save
monkeyrunner help.py <format> <outfile> //format:text or html,outfile:directory+filename


#Reboot
device.reboot()

#Get the Phone model
print str(device.getProperty('build.model'))
print str(device.getProperty('build.board'))
print str(device.getProperty('build.device'))
print str(device.getProperty('build.fingerprint'))
print str(device.getProperty('build.brand'))


1.  adb命令的执行:os.system()
例如 adb root, adb push, adb pull, 可以用 os.system()来实现,例如os.system("adb push e:\\tmp\\email_eception.log /sdcard/")

2.目录操作: os.chdir(),os.getcwd()
os.chdir('e:\\tmp')      
os.getcwd()

3. 创建以时间命名的文件夹
首先获取时间:time.ctime(), 获得的时间格式如"Mon Oct 31 15:48:30 2011",因为window不支持文件夹名包括“:”,并且带有空格也会带来兼容性的问题,可以用字符串处理函数str.replace来将空格用“_”替换,将“:”删除,st2.replace(" ","_").replace(":","")

4. 判断文件是否存在
os.path.exists(), 返回True 或 False
os.path.exists("D:\\shellwork\\devtool\\setup\\music\\setup.bat")

 
5. 连接之前要确保是以root身份连接的(adb root)
os.system('adb root')
os.system('adb wait-for-device')

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值