Monkeyrunner 写脚本的技巧

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")


[python]  view plain copy
  1. from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice, MonkeyImage  
  2. device = MonkeyRunner.waitForConnection()  
  3. #device.removePackage ('ApiDemos.apk')  
  4. device.removePackage ('com.example.android.notepad')  
  5. print ('卸载成功')  
  6. MonkeyRunner.sleep(15)  
  7. device.installPackage('ApiDemos.apk')  
  8. print ('安装成功')  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值