用python编写脚本
 
1.导入模块:
MonkeyRunner
MonkeyDevice
MonkeyImage
ps:如果给导入模块起别名,就应该使用别名,而不能使用原名,否则会出现错误。
from com.android.monkeyrunner import MonkeyRunner as mr
from com.android.monkeyrunner import MonkeyDevice  as md

from com.android.monkeyrunner import MonkeyImage as mi

例:
device=mr.waitForConnection()
 
2.MonkeyRunner 模块
 

2.1 com.android.monkeyrunner.MonkeyRunner.waitForConnection

注释:等待连接设备,与模拟器链接,返回monkeydevice对象,代表链接的设备。没有报错的话说明连接成功。

参数:timeout:超时时间,单位秒,浮点数。默认是无限期等待。
          deviceId:指定的设备名称。默认为当前的设备(手机有限,比如手机通过usb线链接到pc、其次为模拟器)。
实例:默认连接:device=MonkeyRunner.waitForConnection()
           参数连接:device=mr.waitForConnection(1.0,'emulator-5554')
 
 

2.2  com.android.monkeyrunner.MonkeyRunner.installPackage

 
注释: #参数是相对或绝对APK路径 路径级别用“/”,不能用“\”
参数:path:被安装到设备上的apk包在电脑上的文件路径
实例:device.installPackage('myproject/bin/MyApplication.apk') 
 
 

2.3 com.android.monkeyrunner.MonkeyRunner.removePackage

 
注释:删除连接设备中的应用包,删除成功返回true
参数:pachage:将被删除的文件的包名
实例:device.removePackage('myproject/bin/MyApplication.apk')
 
 

2.4  com.android.monkeyrunner.MonkeyRunner.startActivity

 
注释:启动任意的Activity,此时可以向模拟器发送如按键、滚动、截图、存储等操作了。 执行一个adb shell命令,并返回结果,如果有的话
device.shell("...")
参数:uri - The URI for the Intent.
           action - The action for the Intent.
           data - The data URI for the Intent
           mimetype - The mime type for the Intent.
           categories - A Python iterable containing the category names for the Intent.
           extras - A dictionary of extras to add to the Intent. Types of these extras are inferred from the python types of the values.
           component - The component of the Intent.
           flags - An iterable of flags for the Intent.All arguments are optional. The default value for each argument is null.
实例:device.startActivity(component="your.www.com/your.www.com.TestActivity") 
           device.startActivity(component="your.www.com/.TestActivity") 
 
 

2.5 com.android.monkeyrunner.MonkeyRunner.sleep

 
注释:暂停目前正在运行的进程相应的时间
参数:second
实例:MonkeyRunner.sleep(秒数,浮点数)
 
 

2.6  com.android.monkeyrunner.MonkeyRunner.takeSnapshot

 
注释:获取设备的屏蔽缓冲区,产生了整个显示器的屏蔽捕获。(截图)
参数:无
实例:result=device.takeSnapshot()
           返回一个MonkeyImage对象(点阵图包装),我们可以用一下命令将图保存到文件
           result.writeToFile('takeSnapshot\\result1.png','png')
 
 

2.7  com.android.monkeyrunner.MonkeyImage.writeToFile

 
注释:将截图保存到文件 写成功返回true,否则返回false
参数:path:输出文件名和路径
          format:目标格式
实例:result.writeToFile('takeSnapshot\\result1.png','png')
 
 

2.8  com.android.monkeyrunner.MonkeyDevice.type

注释:键盘上的类型指定字符串,这相当于要求字符中按(键码,DOWN_AND_UP)字符串发送到键盘
参数:message:要键入的字符串
实例:device.type(‘字符串’)
 

2.9  com.android.monkeyrunner.MonkeyDevice.wake

注释:唤醒设备屏幕(在设备屏幕上唤醒)
参数:无
实例:device.wake()
 

2.10 com.android.monkeyrunner.MonkeyDevice.reboot

注释:重新引导到指定的引导程序指定的设备
参数:into-the bootloader to reboot into :bootloader,recovery,or None
实例:device.reboot()
 
3.Monkeyrunner类的方法介绍
 

3.1 com.android.monkeyrunner.MonkeyRunner.alert

注释:弹出一个对话框直到用户确认为止
参数:message:会话弹出的内容
          title:会话标题,默认alert
          okTitle:会话确认按钮,默认ok
实例:Alert(string message,string title,string okTile)
 

3.2 com.android.monkeyrunner.MonkeyRunner.choice

注释:显示一个对话框,选择你要添加的那个py文件
参数:message:显示在对话框中的提示信息
           choices:一个迭代的包含一系列选择的python类型
           title:对话框的标题,默认input
实例:Choice(string message,iterable choices,string title)
 
 
 

3.3 com.android.monkeyrunner.MonkeyRunner.help

 
注释:Help(string format)monkeyrunner 的一些帮助,这个和api差不多
 
 

3.4com.android.monkeyrunner.MonkeyRunner.input

 
注释:用户可以在一个对话框里面输入内容
参数:message:对话框显示信息
           initialValue:提供给用户的初始化值,默认为空字符串
           title:对话标题,默认为input
           onTitle: the text to use in the  dialog's confirmation button. default is 'OK'.
           canceTitle: the text to use in the  dialog's 'cancel' button. default is 'Cancel'.
           返回:the text entered by the user ,or None if the user canceled the input.
实例:MonkeyRunner.input(string message,initialValue,title,okTitle,cancelTitle)
 
4 MonkeyDevice类的方法介绍
 

4.1  com.android.monkeyrunner.MonkeyDevice.ibroadcastIntent

 
注释:对设备发送一个广播信号
参数:uri - The URI for the Intent.
          action - The action for the Intent.
          data - The data URI for the Intent
           mimetype - The mime type for the Intent.
          categories - An iterable of category names for the Intent.
          extras - A dictionary of extras to add to the Intent. Types of these extras are inferred from the python types of the values.
          component - The component of the Intent.
          flags - An iterable of flags for the Intent.All arguments are optional. The default value for each argument is null.(see         android.content.Context.sendBroadcast(Intent))
实例:BroadcastIntent (string uri,string action,string data, string mimetype,iterable categories dectionnary extras,component component,iterable flages)
 
 

4.2  com.android.monkeyrunner.MonkeyDevice.drag

 
注释:拖动屏幕,也是划屏的一些操作
参数:start:拖曳开始坐标 (a tuple(x,y)in pixels)
           end:拖曳结束坐标点(a tuple(x,y)in pixels)
           duration:持续时间(default 1.0 seconds)
           steps:拖曳步骤(default is 10)
实例:MonkeyRunner.drag(start,end,duration,steps)
 
4.3 

 com.android.monkeyrunner.MonkeyDevice.getProperty(string key)

得到手机上的一些属性
     

 com.android.monkeyrunner.MonkeyDevice.getSystemProperty(string key)

得到一些系统属性
       

com.android.monkeyrunner.MonkeyDevice.installPackage(string path) 

将一个apk安装到手机里面
     

 com.android.monkeyrunner.MonkeyDevice.instrument(string className,dictionary args)

运行测试设备的指定包
       

com.android.monkeyrunner.MonkeyDevice.press(string name,dectionary type)

按键(一些物理按键)
       

com.android.monkeyrunner.MonkeyDevice.reboot(string package)

重启手机
     

 com.android.monkeyrunner.MonkeyDevice.removePackage(string package)

删除一些apk
       

com.android.monkeyrunner.MonkeyDevice.shell(string cmd)执行adb shell

命令并返回结果
     

 com.android.monkeyrunner.MonkeyDevice.takeSnapshot()

截图
     

 com.android.monkeyrunner.MonkeyDevice.touch(integer x,integer y,integer type)

触摸
     

 com.android.monkeyrunner.MonkeyDevice.type(string message)

输入一些字符串
     

 com.android.monkeyrunner.MonkeyDevice.wake()

唤醒手机点亮屏幕
 
 

5.MonkeyImage 类的方法介绍

 
       

 com.android.monkeyrunner.MonkeyImage.convertBytes(string format)

将图片转换为其他特殊的格式,将结果作为字符串返回,用这个方法将像素存取为特殊的格式,输出的字符串是一种更好的表现(format 目标格式 默认值为png)
           
 com.android.monkeyrunner.MonkeyImage.getRawPixel(integer x, integer y)
在x,y位置处获取一个单一的ARGB像素,参数x,y都是基于0坐标,表示一个像素尺寸,x向右增益,y向下增益,得到一个图标的坐标,这个方法返回一个数组
          

com.android.monkeyrunner.MonkeyImage.getSubImage(tuple rect)

复制一个图片的矩形,rect:A tuple(x,y,w,h),x,y,指定矩形区域的左上角,w为矩形宽,h为矩形高
         

 com.android.monkeyrunner.MonkeyImage.sameAs(MonkeyImage other,float percent)

对比两张照片
         

 com.android.monkeyrunner.MonkeyImage.writeToFile(string path,string format)

将得到的图片保存到一个文件夹里面
         

 com.android.monkeyrunner.MonkeyImage.getHierarchyViewer()

获取设备的显示层次
           

com.android.monkeyrunner.MonkeyImage.startActivity()

在设备上开始一个活动

monkeyrunner API接口文档内容的更多相关文章

  1. “小葵日记”API接口文档

    "小葵日记"项目API接口文档 时间:2017/10/31 (1)用户登录[待完成] POST:127.0.0.1/index/user/login data 数据别称 数据名 数 ...

  2. Swagger 生成 PHP API 接口文档

    Swagger 生成 PHP API 接口文档 Lumen微服务生成Swagger文档 1.概况 有同学反馈写几十个接口文档需要两天的工作量, 随着多部门之间的协作越来越频繁, 维护成本越来越高, 文 ...

  3. SpringBoot + Swagger2 自动生成API接口文档

    spring-boot作为当前最为流行的Java web开发脚手架,相信越来越多的开发者会使用其来构建企业级的RESTFul API接口.这些接口不但会服务于传统的web端(b/s),也会服务于移动端 ...

  4. 电商管理后台 API 接口文档

    1. 电商管理后台 API 接口文档 1.1. API V1 接口说明 接口基准地址:http://127.0.0.1:8888/api/private/v1/ 服务端已开启 CORS 跨域支持 AP ...

  5. api(接口)文档管理工具

    api(接口)文档管理工具 欢迎光临:博之阅API管理平台  ,做为一个app开发者,还没有用到api管理工具,你就OUT了 点击进入:程序员精华博客大全  

  6. 智表ZCELL产品V1.4.0开发API接口文档 与 产品功能清单

    为了方便大家使用ZCELL,应网友要求,整理编写了相关文档,现与产品一起同步发布,供大家下载使用,使用过程中如有疑问,请与我QQ联系. 智表(ZCELL)V1.4.0版本  功能清单文档下载地址: 功 ...

  7. Eolinker API 接口文档神器

    Eolinker API 接口文档神器 群里小伙伴推荐的,还没有去研究,先记下来. API文档管理.自动化测试.开发协作利器 正在为数万企业管理超过100万APIs,提高开发效率以及规范开发流程

  8. 构建标准OpenStack API接口文档

    1.构建API接口文档标准参考: http://docs.openstack.org/contributor-guide/api-guides.html 2.构建API接口文档步骤参考下面的Patch ...

  9. 整合swagger2生成Restful Api接口文档

    整合swagger2生成Restful Api接口文档 swagger Restful文档生成工具 2017-9-30 官方地址:https://swagger.io/docs/specificati ...

随机推荐

  1. 转 Android RadioButton设置选中时文字和背景颜色同时改变

    主要应用在购物车,像淘宝的那样,点击以后弹出一个选择种类颜色这样的popuwindow以后,然后这个选择种类的地方要用到类似这个玩意儿. 搜了一下,效果和这个文章一致.转了. 原文地址:http:// ...

  2. Windows Live Writer 2012 on .net 4

    众所周知,强大的live套件不再更新,止步于2012,所以安装的时候需要.net 3.5的运行时,这很讨厌,在新系统里面是.net 4运行时的,.net运行时的设计者脑袋张虫,新的居然不默认支持旧的程 ...

  3. C语言初级进阶2

    运算符 逻辑运算符: && || ! 位运算符:& | ~ ^ 三目运算符: ? : 结构体元素访问: . -> 命令行参数argc与argv C语言中判断式 各种数据类 ...

  4. 软件工程(FZU2015)赛季得分榜,第七回合

    目录 第一回合 第二回合 第三回合 第四回合 第五回合 第6回合 第7回合 第8回合 第9回合 第10回合 第11回合 积分规则 积分制: 作业为10分制,练习为3分制:alpha30分: 团队项目分 ...

  5. 【poj3875】 Lights

    http://poj.org/problem?id=3875 (题目链接) 题意 有M个N位的不同的二进制数,他们异或起来前v位等于1,求这m个数的不同组合方式(同一组数不同顺序不算). Soluti ...

  6. jsp中iframe填充装个页面

    首先要引入这个css,由于我之前没有引入这个,导致iframe的高度一只是默认高度,没有改变 <style type="text/css"> body, html { ...

  7. python标准模块(三)

    本文会涉及到的模块: subprocess logging 1. subprocess 可以执行shell命令的相关模块和函数有: os.system os.spawn os.popen --废弃 p ...

  8. 回归树|GBDT|Gradient Boosting|Gradient Boosting Classifier

    已经好久没写了,正好最近需要做分享所以上来写两篇,这篇是关于决策树的,下一篇是填之前SVM的坑的. 参考文献: http://stats.stackexchange.com/questions/545 ...

  9. sql中的inner join ,left join ,right join

    左连接LEFT JOIN, 也就是说,左外连接的含义是限制连接关键字右端的表中的数据必须满足连接条件,而不关左端的表中的数据是否满足连接条件,均输出左端表中的内容.不满足连接条件的 ,连接字段栏位将对 ...

  10. Pandas-数据选取

    Pandas包对数据的常用数据切片功能 目录 [] where 布尔查找 isin query loc iloc ix map与lambda contains DataFrame的索引选取 [] 只能 ...