Android Monkeyrunner Test

发表于:2013-12-30 11:27

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:luckyapplelwj    来源:51Testing软件测试网采编

  关于Android自动化测试,研究了Monkey,Robotium 这次来看下 Monkeyrunner.
  具体实践最靠谱的当然还是官网资料了。
  http://developer.android.com/tools/help/monkeyrunner_concepts.html
  这里简单记录下实践过程,Monkeyrunner 需要用Python来编写,对于曾未学过Python的童鞋来说也没关系,因为Python属于比较好学的一门脚本语言.笔者也未曾学过Python,但有其他编程基础如:PHP,Java,Peal,还是能够很好理解Python的。
  一、monkeyrunner 介绍
  monkeyrunner 提供了一个API,使用此API写出的程序可以在Android代码之外控制Android设备和模拟器.
  二、monkeyrunner 测试类型
  多设备控制、功能测试、回归测试
  三、实例(测试MyAndroid.apk)
  1. 新建一个 monkeyrunnerTest.py
# 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')
  2. 运行在 %Android_HOME%\tools 目录下运行一下命令
  monkeyrunner  monkeyrunnerTest.py
  四、API参考
  MonkeyRunner:http://developer.android.com/tools/help/MonkeyRunner.html
  MonkeyDevice:http://developer.android.com/tools/help/MonkeyDevice.html
  MonkeyImage:http://developer.android.com/tools/help/MonkeyImage.html
21/212>
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号