目前公司主要开发安卓平台的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. 背后的故事之 - 快乐的Lambda表达式(一)

    快乐的Lambda表达式(二) 自从Lambda随.NET Framework3.5出现在.NET开发者眼前以来,它已经给我们带来了太多的欣喜.它优雅,对开发者更友好,能提高开发效率,天啊!它还有可能 ...

  3. 解决 Springboot Unable to build Hibernate SessionFactory @Column命名不起作用

    问题: Springboot启动报错: Caused by: org.springframework.beans.factory.BeanCreationException: Error creati ...

  4. java EE设计模式简介

    1.何为设计模式 设计模式提供了对常见应用设计问题的解决方案.在面向对象的编程中,设计模式通常在解决与对象创建和交互相关的问题,而非整体软件架构所面对的大规模问题,它们以样板代码的形式提供了通用的解决 ...

  5. HttpUrlConnection 基础使用

    From https://developer.android.com/reference/java/net/HttpURLConnection.html HttpUrlConnection: A UR ...

  6. 前端常用的WindowsCMD命令

    前面的话   在网上找了一些关于命令提示符CMD的资料,但是很多资料都是把所有的功能罗列出来,大部分都不会用到.所以,自己把常用的CMD命令总结如下,方便查阅 操作类 help 列出所有支持的指令及说 ...

  7. 前端学Markdown

    前面的话   我个人理解,Markdown就是一个富文本编辑器语言,类似于sass对于css的功能,Markdown也可以叫做HTML预处理器,只不过它是一门轻量级的标记语言,可以更简单的实现HTML ...

  8. 设计模式C#合集--抽象工厂模式

    抽象工厂,名字就告诉你是抽象的了.上代码. public interface BMW { public void Drive(); } public class BMW730 : BMW { publ ...

  9. QT内省机制、自定义Model、数据库

    本文将介绍自定义Model过程中数据库数据源的获取方法,我使用过以下三种方式获取数据库数据源: 创建 存储对应数据库所有字段的 结构体,将结构体置于容器中返回,然后根据索引值(QModelIndex) ...

  10. HTML简单入门内容

    常用属性: Width=宽度 Height=高度 Size=大小 Color=颜色 Align=布局方向,值包括(top,bottom,left,right,center)上,下,左,右,中. Bor ...