MR_在eclipse下执行monkey runner脚本

 说实在话,本人有点懒,不想每次都在cmd下切换到android sdk的tools目录下执行monkey runner脚本,也比较讨厌在tools 目录下创建monkey runner脚步,我想的还是能不能在eclipse下执行monkey runner脚本呢?
    一个偶然的机会我发现python 的os 跟subprocess模块下可以执行一些shell命令,那能不能实现打开cmd然后切换到android sdk的tools目录下执行monkey runner脚本呢?
带着这个想法我进行了一次次的尝试,终于能实现了;
执行monkey runner脚本的脚本为:
import subprocess
import os
def command_line(): 
    #连续执行两个命令,切换目录到android sdk 的tools目录下,然后用monkey runner执行测试脚本
    cmd_path=' cd /d "E:\\xxxx\\Android\\androidSDKwindows\\tools" &  monkeyrunner  F:\\xxxx\\AndroidAutoTest\\notepad\\notepad_test.py'
    os.system(cmd_path)
command_line()

notedpad_test.py脚本仅实现安装与卸载应用的功能
import sys
# import the MonkeyRunners modules used by this program
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice, MonkeyImage
def installApp(device):
    device.installPackage('F:/xxxx/AndroidAutoTest/apps/NotesList.apk')   
def call(d):
    d.startActivity(component="com.example.android.notepad/.NotesList")
    print "Start Activity"
    MonkeyRunner.sleep(1.0)   
def removeApp(device):
    device.removePackage ('com.example.android.notepad')
    print "remove success!!!"   
def main():
    print "Start"
    # Connect to the current device returning the MonkeyDevice object
    device = MonkeyRunner.waitForConnection()
    #MonkeyRunner.alert("Starting Activity", "monkeyrunner", "OK")
    if not device:
        print "Couldn't get connection"
        sys.exit()
    print "Found device"
    installApp(device)
    call(device)
    MonkeyRunner.sleep(10.0)
    removeApp(device)    
if __name__ == '__main__':
    main()
    
   文章写于2014-10-18 21:30

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值