#-*- coding: UTF-8 -*-

#上面第一行是设置文件编码,windows下第一行必须是这个
#文件名 MonkeyRunner.py
#功能: 使用monkey runner测试app,此案例是测试搜索功能(输入关键字,然后点击搜索按钮)
#参考: http://blog.csdn.net/mad1989/article/details/38087737
# http://blog.csdn.net/zm2714/article/details/7980634

#可以使用 Android/sdk/tools/uiautomatorviewer.bat 获取坐标点

#执行方式 Android/sdk/tools 添加到环境变量,运行"monkeyrunner c:/MonkeyRunner.py"(不包括引号,后面文件要用全路径)
#-f后面为脚本文件的路径,最后一个数字表示脚本执行的次数

#导入我们需要用到的包和类并且起别名
import sys
from com.android.monkeyrunner import MonkeyRunner as mr
from com.android.monkeyrunner import MonkeyDevice as md
from com.android.monkeyrunner import MonkeyImage as mi

#connect device 连接设备
#第一个参数为等待连接设备时间
#第二个参数为具体连接的设备,可以是ip:port,通过adb devices 可以获取到
device = mr.waitForConnection(1.0,'71985152')
if not device:
print >> sys.stderr,"fail"
sys.exit(1)
#定义要启动的Activity
componentName='com.iotlife.action/com.iotlife.action.activity.SearchDetailActivity'
#启动特定的Activity
device.startActivity(component=componentName)
mr.sleep(0.2)

#点击搜索框
device.touch(400,100,'DOWN_AND_UP')
mr.sleep(0.2)

#输入 test
device.type('test')
#输入回车
device.press('KEYCODE_ENTER')
#return keyboard
#device.press('KEYCODE_BACK')

#点击搜索按钮
device.touch(1000,100,'DOWN_AND_UP')
mr.sleep(0.2)

#takeSnapshot截图
mr.sleep(3.0)
result = device.takeSnapshot()

#save to file 保存到文件(pc 上 ,不是手机上)
#result.writeToFile('./shot1.png','png'); #相对路径是monkeyrunner的路径
result.writeToFile('c:/tmp/shot1.png','png');

最新文章

  1. codeforces 754D. Fedor and coupons
  2. 移动端自动化环境搭建-wxpython的安装
  3. 2.springMVC+spring+Mybatis整合
  4. Rational.Rose.Enterprise.v7.0 (2007)安装分享
  5. 【BZOJ-2768】冠军调查 最小割
  6. 112、两个Activity切换黑屏问题
  7. linux硬链接与软链接
  8. JS 点击按钮后弹出遮罩层,有关闭按钮
  9. Delphi XE5教程7:单元引用和uses 子句
  10. cocos2dx系列笔记(2)- windows环境配置后续之 Android环境配置
  11. VBA开发经验总结之一:利用Range对象设计用户界面
  12. python换行写入文件
  13. Linux centos7环境下安装JDK的步骤详解
  14. [转载] Linux内存管理之mmap详解
  15. java独立小程序实现AES加密和解密
  16. PostgreSQL 自定义自动类型转换(CAST)
  17. windows10 VM12 安装Mac OS X 10.11
  18. PAT 1013 数素数
  19. EasyUI datagrid 查询、设置、提交 三
  20. [Windows Azure] Guidelines for Connecting to Windows Azure SQL Database

热门文章

  1. Docs-.NET-C#-指南-语言参考-预处理器指令:#define(C# 参考)
  2. Angular中的routerLink 跳转页面和默认路由
  3. websphere 英文版部署(更新)项目【我】
  4. Ubuntu 16.04 haproxy 简单配置应用
  5. 简介Python设计模式中的代理模式与模板方法模式编程
  6. LeetCode_172. Factorial Trailing Zeroes
  7. Laravel 别名Redis 与 Redis 扩展冲突
  8. [多转合成] 使用pycaffe保存各个层的特征图
  9. vue报错:Component template should contain exactly one root element. If you are using v-if on multiple elements, use v-else-if to chain them instead.
  10. 学习笔记:(转)Centos7.6安装Oracle11gR2