Android的猴子测试选择一个特定的活动猴子、测试、Android

2023-09-12 22:21:26 作者:二踢脚少女

我使用的是 Android的猴子测试测试我的Andr​​oid应用程序,它的作品,我的应用程序,非常酷。但我想,以测试在特定应用程序的活动,我怎么能做到这一点?

今天我测试了所有的应用程序:

  $亚行外壳猴子-p my.package -c android.intent.category.HOME -c android.intent.category.DEFAULT -v 500 -s随机数
 

解决方案

通过 Android的猴子测试我无法测试特定的活动,但与 Android的猴子亚军我能做的Python脚本模拟猴子试验,所以我做了一个python脚本打开我的活动和init猴子测试:)

 #!在/ usr /斌/包膜monkeyrunner

从com.android.monkeyrunner进口MonkeyRunner,MonkeyDevice
从随机导入randint

打印获取设备
设备= MonkeyRunner.waitForConnection()
包='my.packaget
活动='my.package.activity
runComponent =包+'/'+活动
device.startActivity(成分= runComponent)

#使用命令,如device.touch和device.drag模拟导航,打开我的活动

#with你的活动开始打开你的猴子测试
打印开始猴子测试
因为我在范围内(1,1000):
    #here我去效仿只有简单沾上,但我可以模仿刷卡的KeyEvents更多...:D
    device.touch(randint(0,1000),randint(0,800),'DOWN_AND_UP')

打印结束猴子测试
 
十二生肖入诗,快来看看属于你的生肖诗词 属相

保存teste.py和运行

  $ monkeyrunner teste.py
 

I'm using the Android monkey test to test my android apps, it's works for my app, and is very cool. but I'd like to test an application activity in specific, how could i do that?

today I'm testing all app with:

$ adb shell monkey -p my.package -c android.intent.category.HOME -c android.intent.category.DEFAULT -v 500 -s "a random number"

解决方案

With Android monkey test i cannot test a specific activity, but with Android monkey runner i can do python scripts to simulate a monkey test, so i did a python script open the my activity and init the monkey test :)

#! /usr/bin/env monkeyrunner

from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
from random import randint

print "get device"
device = MonkeyRunner.waitForConnection()
package = 'my.packaget'
activity = 'my.package.activity'
runComponent = package + '/' + activity
device.startActivity(component=runComponent)

#use commands like device.touch and device.drag to simulate a navigation and open my activity

#with your activity opened start your monkey test
print "start monkey test"
for i in range(1, 1000):
    #here i go emulate only simple touchs, but i can emulate swiper keyevents and more... :D
    device.touch(randint(0, 1000), randint(0, 800), 'DOWN_AND_UP')

print "end monkey test"

save teste.py and run

$ monkeyrunner teste.py