Android Monkeyrunner Test
# Import the monkey runner modules used by this program
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice, MonkeyImage
# Connects to current device, returning a MonkeyDevice object
device = MonkeyRunner.waitForConnection()
# Installs the Android package
device.installPackage("./MyAndroid.apk")
# Runs the component
device.startActivity(component = 'com.luwenjie.android/.MyAndroidActivity')
#Presses the Menu button
device.press('KEYCODE_MENU','DOWN_AND_UP')
#Takes a screenshot
result = device.takeSnapshot()
# Writes the screenshot to a file
result.writeToFile('./shot1.png','png')
|
#Usage: monkeyrunner recorder.py
#recorder.py http://mirror.yongbok.net/linux/android/repository/platform/sdk/monkeyrunner/scripts/monkey_recorder.py
from com.android.monkeyrunner import MonkeyRunner as mr
from com.android.monkeyrunner.recorder import MonkeyRecorder as recorder
device = mr.waitForConnection()
recorder.start(device)
#END recorder.py
#Press ExportAction to save recorded scrip to a file
#Example of result:
#PRESS|{'name':'MENU','type':'downAndUp',}
#TOUCH|{'x':190,'y':195,'type':'downAndUp',}
#TYPE|{'message':'',}
#Usage: monkeyrunner playback.py "myscript"
#playback.py http://mirror.yongbok.net/linux/android/repository/platform/sdk/monkeyrunner/scripts/monkey_playback.py
import sys
from com.android.monkeyrunner import MonkeyRunner
# The format of the file we are parsing is very carfeully constructed.
# Each line corresponds to a single command. The line is split into 2
# parts with a | character. Text to the left of the pipe denotes
# which command to run. The text to the right of the pipe is a python
# dictionary (it can be evaled into existence) that specifies the
# arguments for the command. In most cases, this directly maps to the
# keyword argument dictionary that could be passed to the underlying
# command.
# Lookup table to map command strings to functions that implement that
# command.
CMD_MAP = {
'TOUCH': lambda dev, arg: dev.touch(**arg),
'DRAG': lambda dev, arg: dev.drag(**arg),
'PRESS': lambda dev, arg: dev.press(**arg),
'TYPE': lambda dev, arg: dev.type(**arg),
'WAIT': lambda dev, arg: MonkeyRunner.sleep(**arg)
}
# Process a single file for the specified device.
def process_file(fp, device):
for line in fp:
(cmd, rest) = line.split('|')
try:
# Parse the pydict
rest = eval(rest)
except:
print 'unable to parse options'
continue
if cmd not in CMD_MAP:
print 'unknown command: ' + cmd
continue
CMD_MAP[cmd](device, rest)
def main():
file = sys.argv[1]
fp = open(file, 'r')
device = MonkeyRunner.waitForConnection()
process_file(fp, device)
fp.close();
if __name__ == '__main__':
main()
|

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
-
上一篇
是时候宣布:Windows Phone死了
四年前,微软开始了Windows Phone业务,并希望其能成为iOS、Android之外的第三大移动生态系统,然而种种迹象表明,现在是时候承认Windows Phone已经失败的事实了。据悉,微软在最近的一个季度内只卖出了450万部Lumia手机,而在前一年同季度,它还有1050万部的销量成绩,这意味着仅过了一年时间,Lumia的季度销量就足足跌了57个百分点。 现在,即便Windows Phone能够得到57%的增长率也没法得到拯救了。 微软和诺基亚总共卖出了1.1亿部Windows Phone,这和同时期的iOS和Andoid一比简直是可望而不可及。IDC最近的一份调查显示,Lumia Windows Phone在最近一季度的市场份额仅有1.1%,而微软也一直没有拿出一款令人信服的Lumia手机,并且最近做足了文章的Lumia 950和Lumia 950 XL也因未完成的Windows 10 Mobile而令人失望。 由于Lumia销量在不断下降,而微软也没有大规模生产的计划,所以显而易见,Windows Phone正在走向尽头。虽然最近有消息传微软正在筹备一款杀手级Surfac...
-
下一篇
苹果将推出网页版地图 欲与谷歌地图竞争?
摘要:苹果现在已经在其地图数据库中发布了可以显示地标和信息点(POI)的公共网页,该网站的链接可以显示地点的一些细节,例如位置、名字、电话号码和评价。值得一提的是,其设计也和 iOS 10 的地图应用一样。 而在苹果平台打开这些链接,会直接开启原生的地图应用,如果使用 Chrome 或其它非苹果设备(例如安卓)查看,会通过网页显示信息。苹果目前打造这些链接的目的尚不清楚,不过有消息指出苹果希望通过提供自家的在线地图服务来和网页版谷歌地图进行竞争。 另外,这些新网页看似是一种分享链接,但目前 iOS 或 macOS 的苹果地图应用并没有提供这些分享。值得一提的是,这些链接目前可以在 Sierra 系统的 Safari 建议中找到,你只需在地址栏内搜索一个 POI,那么系统就会为你显示附近的结果。从结果中选择一个就会再打开一个新的标签页。目前这一功能似乎只能够通过 Safari 的搜索建议访问,并且需要有网络环境。 本文转自d1net(转载)
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
推荐阅读
最新文章
- MySQL8.0.19开启GTID主从同步CentOS8
- CentOS7,8上快速安装Gitea,搭建Git服务器
- Dcoker安装(在线仓库),最新的服务器搭配容器使用
- Docker使用Oracle官方镜像安装(12C,18C,19C)
- CentOS7编译安装Cmake3.16.3,解决mysql等软件编译问题
- CentOS8安装MyCat,轻松搞定数据库的读写分离、垂直分库、水平分库
- Windows10,CentOS7,CentOS8安装MongoDB4.0.16
- CentOS8编译安装MySQL8.0.19
- MySQL数据库在高并发下的优化方案
- Springboot2将连接池hikari替换为druid,体验最强大的数据库连接池