MonkeyRunner_monkeyrunner的iQuery插件使用说明

刚刚上传了monkeyrunner的iQuery插件,完整下载和示例代码请在此下载:

https://github.com/downloads/vowei/iQuery/iquery%20monkeyrunner%20plugin%20sample.zip

示例代码是随便找的针对大众点评写的,因此请确保手机上已经安装了大众点评的应用。示例代码下载后,请设置一个变量:“ANDROID_HOME”,例如:

$ export ANDROID_HOME=~/android-sdks

接着运行

$ ./run.sh

该插件的原理是解析Android手机上的View Server输出的应用控件树结构,找到要操控的控件的坐标,然后执行操作,当前只支持点击操作,后续会添加新的API。

下面是示例代码的说明:

   1:  # encoding: utf-8
   2:  import time, httplib, string, ast
   3:  # Imports the monkeyrunner modules used by this program
   4:  from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
   5:  from cc.iqa.iquery.mr import QueryableDevice, By
   6:   
   7:  ACTIVITY_LAUNCH_TIME = 10
   8:  THINK_TIME = 3
   9:   
  10:  runComponent = "com.dianping.v1/com.dianping.ui.activity.MainActivity"
  11:   
  12:  # Connects to the current device, returning a MonkeyDevice object
  13:  device = MonkeyRunner.waitForConnection()
  14:   
  15:  # Installs the Android package. Notice that this method returns a boolean, so you can test
  16:  # to see if the installation worked.
  17:  device.startActivity(component=runComponent)
  18:  time.sleep(ACTIVITY_LAUNCH_TIME)
  19:   
  20:  # 从device变量里初始化支持iQuery查询的device对象,其源码位置是:
  21:  # https://github.com/vowei/iQuery/blob/master/java/iquery/iquery-mr/src/main/java/cc/iqa/iquery/mr/QueryableDevice.java
  22:  qdevice = QueryableDevice(device)
  23:   
  24:  # 启动并链接到安卓设备上的View Server,“127.0.0.1”这个ip是针对模拟器的,
  25:  # 需要自己查询真机设备的ip
  26:  qdevice.connectViewServer("127.0.0.1", 4939)
  27:   
  28:  # 获取待测应用的控件树结构,得到一个ControlHierarchy对象,其源码位置是:
  29:  # https://github.com/vowei/iQuery/blob/master/java/iquery/iquery-mr/src/main/java/cc/iqa/iquery/mr/ControlHierarchy.java
  30:   
  31:  ch = qdevice.getLayout(qdevice.getActivityId(runComponent))
  32:  # mText是按钮、文本框等控件的文本属性,与android sdk里各控件里的变量一致。
  33:  # 下面touch函数里,第一个参数就是由By类创建的iquery查询,
  34:  # 第二个参数就是待测应用的控件树结构,可以调用 ch.getViewServerOutput() 函数来获取一个字符串数组形式的待测应用控件树结构。
  35:  # 第三个参数就是点击操作的具体行为。
  36:  qdevice.touch(By.iquery(u":first >> [mText='团购']"), ch, MonkeyDevice.DOWN_AND_UP)
  37:  time.sleep(THINK_TIME)
  38:   
  39:  qdevice.touch(By.iquery(u":first >> [mText='签到']"), ch, MonkeyDevice.DOWN_AND_UP)
  40:  time.sleep(THINK_TIME)
  41:   
  42:  qdevice.touch(By.iquery(u":first >> [mText='我的']"), ch, MonkeyDevice.DOWN_AND_UP)
  43:  time.sleep(THINK_TIME)

最后,如果你希望修改代码需要编译的话,请在此同步代码:

https://github.com/vowei/iQuery/

编译之前,因为iquery monkeyrunner插件使用了很多android sdk里面的jar文件,因此也要先设置ANDROID_HOME环境变量才能编译,如下:

   1:  $ export ANDROID_HOME=~/android-sdK
   2:  $ mvn package
 
 
转载自:http://www.cnblogs.com/vowei/archive/2012/11/10/2764426.html
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
所有效果说明:基本的鼠标互动:拖拽(drag and dropping)、排序(sorting)、选择(selecting)、缩放(resizing) 各种互动效果:手风琴式的折叠菜单(accordions)、日历(date pickers)、对话框(dialogs)、滑动条 (sliders)、表格排序(table sorters)、页签(tabs) 放大镜效果(magnifier)、阴影效果(shadow) 第一部分:鼠标交互 1.1 Draggables:拖拽所需文件: ui.mouse.js ui.draggable.js ui.draggable.ext.js 用法:文件载入后,可以拖拽class = "block"的层 $(document).ready(function(){ $(".block").draggable(); }); draggable(options)可以跟很多选项选项说明:http://docs.jquery.com/UI/Draggables/draggable#options 选项实例:http://dev.jquery.com/view/trunk/plugins/ui/tests/draggable.html 1.2 Droppables 所需要文件,drag drop ui.mouse.js ui.draggable.js ui.draggable.ext.js ui.droppable.js ui.droppable.ext.js 用法: $(document).ready(function(){ $(".block").draggable({helper: 'clone'}); $(".drop").droppable({ accept: ".block", activeClass: 'droppable-active', hoverClass: 'droppable-hover', drop: function(ev, ui) { $(this).append("<br>Dropped!"); } }); }); 选项说明:http://docs.jquery.com/UI/Droppables/droppable#options 选项实例:http://dev.jquery.com/view/trunk/plugins/ui/tests/droppable.html 1.3 Sortables 排序所需要的文件 jquery.dimensions.js ui.mouse.js ui.draggable.js ui.droppable.js ui.sortable.js 用法: $(document).ready(function(){ $("#myList").sortable({}); }); dimensions文档http://jquery.com/plugins/project/dimensions 选项说明:http://docs.jquery.com/UI/Sortables/sortable#options 选项实例:http://dev.jquery.com/view/trunk/plugins/ui/demos/ui.sortable.html 1.4 Selectables 选择所需要的文件 jquery.dimensions.js ui.mouse.js ui.draggable.js ui.droppable.js ui.selectable.js 用法: $(document).ready(function(){ $("#myList").selectable(); }); 选项说明:http://docs.jquery.com/UI/Selectables/selectable#options 选项实例:http://dev.jquery.com/view/trunk/plugins/ui/tests/selectable.html 1.5 Resizables改变大小所需要的文件 ,此例子需要几个css文件 jquery.dimensions.js ui.mouse.js ui.resizable.js 用法: $(document).ready(function(){ $("#example").resizable(); }); CSS文件:http://dev.jquery.com/view/trunk/themes/flora/flora.all.css 选项说明:http://docs.jquery.com/UI/Resizables/resizable#options 选项实例:http://dev.jquery.com/view/trunk/plugins/ui/demos/ui.resizable.html 第二部分:互动效果 2.1 Accordion 折叠菜单所需要的文件: ui.accordion.js jquery.dimensions.js 用法: $(document).ready(function(){ $("#example").accordion(); }); CSS文件:http://dev.jquery.com/view/trunk/themes/flora/flora.all.css 选项说明:http://docs.jquery.com/UI/Accordion/accordion#options 选项实例:http://dev.jquery.com/view/trunk/plugins/accordion/?p=1.1.1 2.2 dialogs 对话框所需要的文件: jquery.dimensions.js ui.dialog.js ui.resizable.js ui.mouse.js ui.draggable.js 用法: $(document).ready(function(){ $("#example").dialog(); }); CSS文件:http://dev.jquery.com/view/trunk/themes/flora/flora.all.css 选项说明:http://docs.jquery.com/UI/Dialog/dialog#options 选项实例:http://dev.jquery.com/view/trunk/plugins/ui/tests/dialog.html 2.3 sliders 滑动条所需要的文件 jquery.dimensions.js ui.mouse.js ui.slider.js 用法: $(document).ready(function(){ $("#example").slider(); }); CSS文件:http://dev.jquery.com/view/trunk/themes/flora/flora.all.css 选项说明:http://docs.jquery.com/UI/Slider/slider#options 选项实例:http://dev.jquery.com/view/trunk/plugins/ui/demos/ui.slider.html 2.4 Tablesorter表格排序所需要的文件 ui.tablesorter.js 用法: $(document).ready(function(){ $("#example").tablesorter({sortList:[[0,0],[2,1]], widgets: ['zebra']}); }); CSS文件:http://dev.jquery.com/view/trunk/themes/flora/flora.all.css 选项说明:http://docs.jquery.com/Plugins/Tablesorter/tablesorter#options 选项实例:http://tablesorter.com/docs/#Demo 2.5 tabs页签(对IE支持不是很好) 所需要的文件 ui.tabs.js 用法: $(document).ready(function(){ $("#example > ul").tabs(); }); CSS文件:http://dev.jquery.com/view/trunk/themes/flora/flora.all.css 选项说明:http://docs.jquery.com/UI/Tabs/tabs#initialoptions 选项实例:http://dev.jquery.com/view/trunk/plugins/ui/tests/tabs.html tabs ext http://stilbuero.de/jquery/tabs_3/rotate.html 第三部分:效果 3.1 Shadow 阴影实例http://dev.jquery.com/view/trunk/plugins/ui/demos/ui.shadow.html 3.2 Magnifier 放大实例http://dev.jquery.com/view/trunk/plugins/ui/demos/ui.magnifier.html
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值