Android自动化测试, Feature phone自动化测试, Robotium, Monkey Runner, Android Robot

Android自动化测试 - MonkeyRunner(一)

上一篇 / 下一篇  2012-03-07 14:21:23

Android自动化测试如今有很多,有收费的也有免费的,包括Google也有很多开源的好的工具可以利用。
Monkeyrunner就是其中之一:下面是一些简单的代码

MonkeyRunner所在的位置是在android sdk\tools下面,支持的是Python脚本。
MonkeyRunner支持用户的2个基础类是:MonkeyRunner,MonkeyDevice
就是说用户只要在python脚本里面import这2个类便可以调用Monkeyrunner提供的所有API了。
下面是个简单的例子,来至于Google:

fromcom.android.monkeyrunnerimportMonkeyRunner,MonkeyDevice
device=MonkeyRunner.waitForConnection()
device
.installPackage('myproject/bin/MyApplication.apk')

package
='com.example.android.myapplication'
activity
='com.example.android.myapplication.MainActivity'
runComponent
=package+'/'+activity
# Runs the component

device
.startActivity(component=runComponent)

# Presses the Menu button

device
.press('KEYCODE_MENU',MonkeyDevice.DOWN_AND_UP)

# Takes a screenshot

result
=device.takeSnapshot()

# Writes the screenshot to a file

result
.writeToFile('myproject/shot1.png','png')

大家可以把改文本copy到自己的test.py文件里面运行monkeyrunner test.py看看效果。



TAG:

引用 删除 hhjk9901   /   2012-03-08 10:10:15
3
 

评分:0

我来说两句

Open Toolbar