MonkeyRunner—API篇之MonkeyImage&MonkeyRunner

来源:互联网 发布:淘宝网夏季竹凉席坐垫 编辑:程序博客网 时间:2024/06/05 06:15

一、MonkeyImage

1、 string convertToBytes ( string format)
将当前图像转换为一个特定的格式并将其作为字符串返回。
参数
format :传入需要输出的图片格式,默认是png格式

2、tuple getRawPixel (integer x, integer y)
在x,y位置处获取一个单一的ARGB像素,参数x,y都是基于0坐标,表示一个像素尺寸,x向右增益,y向下增益,得到一个图标的坐标,这个方法返回一个数组
参数
x :像素的水平位置
y :像素的垂直位置

3、tuple getRawPixelInt (integer x, integer y)
返回单个像素在图像位置(x,y),作为一个整数。使用这个方法来节约内存。
参数
x :像素的水平位置
y :像素的垂直位置

4、MonkeyImage getSubImage (tuple rect)
复制一个图片的矩形。
参数
rect:矩形元组(x,y,w,h)指定的选择。x和y指定基于像素的左上角的位置选择。w指定区域的宽度,和h指定它的高度,以像素为单位。

5、boolean sameAs ( MonkeyImage otherImage, float percent )
比较两个MonkeyImage对象是否相同
参数
other :另一个MonkeyImage对象
percent :传入的值在0.0-1.0之间,默认值为1.0,表示必须匹配所有的像素

6、 void writeToFile (string filename, string format)
将得到的图片保存到一个文件夹里面
参数
path :文件路径名
format :指定文件的格式类型,默认png

华丽的分割线***************************************************************

二、MonkeyRunner

1、string alert ( string message, string title, string okTitle)
弹出一个对话框直到用户确认为止
参数
message :会话框中的内容
title :会话框的标题. 默认是”Alert”.
okTitle :会话框的按钮文本. 默认是 “OK”.

2、integer choice (string message, iterable choices, string title)
显示一个对话框,选择你要添加的那个py文件
参数
message:会话框中的内容
choices :传入一个python格式的iterable,推荐使用字符串数组
title :对话框的标题,默认是”Input”.

3、 void help (string format)
显示帮助文档
参数
format :指定输入的文本格式

4、string input (string message string initialValue, string title, string okTitle, string cancelTitle)
弹出一个可输入的对话框, 点击确定返回输入的值,点击取消返回空字符串
参数
message :对话框中显示的内容。
initialValue :输入框内显示的初始值,默认显示空字符串
title :对话框显示标题,默认显示”Input”.
okTitle :对话框确认按钮的文本,默认显示 “OK”.
cancelTitle :对话框取消按钮的文本,默认显示”Cancel”.

5、 void sleep ( float seconds )
暂停目前正在运行的进程
参数
seconds :暂停的秒数

6、MonkeyDevice waitForConnection (float timeout, string deviceId)
等待连接设备,与模拟器链接,返回monkeydevice对象,代表链接的设备。没有报错的话说明连接成功。
参数
timeout :等待的秒数连接。默认是永远的等待。
deviceId :一个正则表达式,指定设备的序列号或模拟器。

原创粉丝点击