目前公司主要开发安卓平台的APP,平时测试经常需要使用monkey测试,所以尝试了下用python调用monkey,代码如下:

 import os
apk = {'j': 'com.***.test1',
'h': 'com.***.test2'}
print 'enter \'j\' to test test1'
print 'enter \'h\' to test test2'
#choose apk
while True: test_apk = raw_input('which apk do you want to test?\n(\'h\' or \'j\'):')
try:
apk_name = apk[test_apk]
except KeyError:
print 'Please enter \'j\' or \'h\'! - -#'
else:
break
#check the input value
while True:
event_num = raw_input('How many pseudo random events(-v) do you want?\nenter int num(>0):')
if event_num.isdigit() and int(event_num) > 0:
print 'OK, your events are ' + event_num
break
else:
print 'Please enter a number and the number > 0'
#check the input value
while True:
for_time = raw_input('How many times monkey test do you want?\ntimes(>1):')
if for_time.isdigit() and int(for_time) > 1:
print 'OK, you want to loop ' + for_time + 'times monkey test'
break
else:
print 'Please enter a number and the number > 1'
#the log path
log_path = 'D:\\'
#the log name
log_name = 'monkeytestlog.txt'
#monkey shell script
monkey_shell = 'adb shell monkey -v -v -v -p '+ apk_name+ ' -v ' + event_num + ' >'+log_path def monkeytest():
print 'now let\'s check your phone'
phonedevice = os.popen('adb devices').read()
if phonedevice.strip().endswith('device'):
print 'OK, your phone get ready,let\'s start moneky test!'
for i in range(1, int(for_time)+1):
print 'The', i, 'monkey test starting...'
os.system(monkey_shell+str(i)+log_name)
print i, 'complete!'
print 'OK, moneky test all complete! The log is in D:\\'
else:
print 'please check your phone has linked your computer well' #find 'adb' command at your os
sysPath = os.environ.get('PATH')
if not sysPath.find('platform-tools'):
print '''please install the android-sdk and put the 'platform-tools' dir in your system PATH'''
else: #kill the 'tadb.exe'
tadb = os.popen('tasklist').read()
if tadb.find('tadb.exe') != -1:
print 'Find \'tadb.exe\', it must be killed!!!!!!'
os.system('taskkill /im tadb.exe /F')
print 'OK,the \'tadb.exe\' has been killed, let\'s go on'
monkeytest()
else:
print 'not find \'tadb.exe\',great! go on!'
monkeytest()

感觉还能继续优化,做个记录。

【初学python】使用python调用monkey测试的更多相关文章

  1. python实现建立soap通信(调用及测试webservice接口)

    实现代码如下: #调用及测试webservice接口 import requests class SoapConnect: def get_soap(self,url,data): r = reque ...

  2. Python 3.X 调用多线程C模块,并在C模块中回调python函数的示例

    由于最近在做一个C++面向Python的API封装项目,因此需要用到C扩展Python的相关知识.在此进行简要的总结. 此篇示例分为三部分.第一部分展示了如何用C在Windows中进行多线程编程:第二 ...

  3. 『Python CoolBook』C扩展库_其五_C语言层面Python库之间调用API

    点击进入项目 一.C层面模块添加API 我们仍然操作如下结构体, #include <math.h> typedef struct Point { double x,y; } Point; ...

  4. Python 中如何实现参数化测试?

    Python 中如何实现参数化测试? 之前,我曾转过一个单元测试框架系列的文章,里面介绍了 unittest.nose/nose2 与 pytest 这三个最受人欢迎的 Python 测试框架. 本文 ...

  5. Python包模块化调用方式详解

    Python包模块化调用方式详解 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一般来说,编程语言中,库.包.模块是同一种概念,是代码组织方式. Python中只有一种模块对象类型 ...

  6. 详细介绍windows下使用python pylot进行网站压力测试

    windows下使用python进行网站压力测试,有两个必不可少的程序需要安装,一个是python,另一个是pylot.python是一个安装软件,用来运行python程序,而pylot则是pytho ...

  7. Python Web 性能和压力测试 multi-mechanize

    http://www.aikaiyuan.com/5318.html 对Web服务做Performance & Load测试,最常见的工具有Apache Benchmark俗称ab和商用工具L ...

  8. python笔记之调用系统命令

    python笔记之调用系统命令 目前我使用到的python中执行cmd的方式有三种 使用os.system("cmd") 该方法在调用完shell脚本后,返回一个16位的二进制数, ...

  9. python可变参数调用函数的问题

    已使用python实现的一些想法,近期使用python这种出现的要求,它定义了一个函数,第一种是一般的参数,第二个参数是默认,并有可变参数.在第一项研究中python时间,不知道keyword可变参数 ...

随机推荐

  1. Swift与C#的基础语法比较

    背景: 这两天不小心看了一下Swift的基础语法,感觉既然看了,还是写一下笔记,留个痕迹~ 总体而言,感觉Swift是一种前后端多种语言混合的产物~~~ 做为一名.NET阵营人士,少少多多总喜欢通过对 ...

  2. 史上最详细git教程

    题外话 虽然这个标题很惊悚,不过还是把你骗进来了,哈哈-各位看官不要着急,耐心往下看 Git是什么 Git是目前世界上最先进的分布式版本控制系统. SVN与Git的最主要的区别 SVN是集中式版本控制 ...

  3. NET Core-学习笔记(三)

    这里将要和大家分享的是学习总结第三篇:首先感慨一下这周跟随netcore官网学习是遇到的一些问题: a.官网的英文版教程使用的部分nuget包和我当时安装的最新包版本不一致,所以没法按照教材上给出的列 ...

  4. [C#] 了解过入口函数 Main() 吗?带你用批处理玩转 Main 函数

    了解过入口函数 Main() 吗?带你用批处理玩转 Main 函数 目录 简介 特点 方法的参数 方法的返回值 与批处理交互的一个示例 简介 我们知道,新建一个控制台应用程序的时候,IDE 会同时创建 ...

  5. mybatis_基础篇

    一.认识mybatis: MyBatis 本是apache的一个开源项目iBatis, 2010年这个项目由apache software foundation 迁移到了google code,并且改 ...

  6. 《LoadRunner12七天速成宝典》来了

    看到自己的新书又要发行了,算算从09年第一本书开始,不知不觉已经是第四本书了(帮朋友合写的书不算),每次写完之后都会说太累了,不想再写了,但是却又次次反悔,吞下食言的苦果.如果非要说第四本书的感受,那 ...

  7. 【SAP业务模式】之ICS(五):定价配置

    本篇博文讲述ICS业务中的定价配置. 1.定义销售订单类型 目录:SPRO-销售与分销-销售-销售凭证-销售凭证抬头-定义销售凭证类型 事务代码:VOV8 2.定义销售订单类型 目录:SPRO-销售与 ...

  8. 基于SOA架构的TDD测试驱动开发模式

    以需求用例为基,Case&Coding两条线并行,服务(M)&消费(VC)分离,单元.接口.功能.集成四层质量管理,自动化集成.测试.交付全程支持. 3个大阶段(需求分析阶段.研发准备 ...

  9. linux之查看系统命令

    cpu信息 1.查看逻辑cpu核数 # cat /proc/cpuinfo| grep "processor"| wc -l 2.查看物理cpu个数 # cat /proc/cpu ...

  10. NYOJ 954

    首先观察: 2! = 2×1                 = (2)10     = (10)2,        则第一个1是第2位,2!有1个质因数23! = 3×2×1             ...