目前公司主要开发安卓平台的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. JS核心系列:浅谈 call apply 与 bind

    在JavaScript 中,call.apply 和 bind 是 Function 对象自带的三个方法,这三个方法的主要作用是改变函数中的 this 指向,从而可以达到`接花移木`的效果.本文将对这 ...

  2. ASP.NET路由模型解析

    大家好,我又来吹牛逼了 ~-_-~ 转载请注明出处:来自吹牛逼之<ASP.NET路由模型解析> 背景:很多人知道Asp.Net中路由怎么用的,却不知道路由模型内部的运行原理,今天我就给大家 ...

  3. HashMap与TreeMap源码分析

    1. 引言     在红黑树--算法导论(15)中学习了红黑树的原理.本来打算自己来试着实现一下,然而在看了JDK(1.8.0)TreeMap的源码后恍然发现原来它就是利用红黑树实现的(很惭愧学了Ja ...

  4. python程序生成平均脸

    简介 项目代码https://github.com/LiuRoy/pokerface 原文链接http://www.cnblogs.com/lrysjtu/p/5492547.html 写这个项目的本 ...

  5. EntityFramework之DetectChanges's Secrets(三)(我为EF正名)

    前言 对于应用程序开发者来说,通常不需要考虑太多对于Entity Framework中的变更追踪(change tracking),但是变更追踪和DetectChanges方法是栈的一部分,在这其中, ...

  6. QT5利用chromium内核与HTML页面交互

    在QT5.4之前,做QT开发浏览器只能选择QWebkit,但是有过使用的都会发现,这个webkit不是出奇的慢,简直是慢的令人发指,Release模式下还行,debug下你就无语了,但是webkit毕 ...

  7. 一起学 Java(二)面向对象

    一.方法函数 函数也称为方法,就是定义在类中的具有特定功能的一段独立代码.用于定义功能,提高代码的复用性. 函数的特点1> 定义函数可以将功能代码进行封装,便于对该功能进行复用:2> 函数 ...

  8. Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory

    学习架构探险,从零开始写Java Web框架时,在学习到springAOP时遇到一个异常: "C:\Program Files\Java\jdk1.7.0_40\bin\java" ...

  9. 分布式学习系列【dubbo入门实践】

    分布式学习系列[dubbo入门实践] dubbo架构 组成部分:provider,consumer,registry,monitor: provider,consumer注册,订阅类似于消息队列的注册 ...

  10. [Android]使用Dagger 2来构建UserScope(翻译)

    以下内容为原创,欢迎转载,转载请注明 来自天天博客:http://www.cnblogs.com/tiantianbyconan/p/6237731.html 使用Dagger 2来构建UserSco ...