Android的猴子测试选择一个特定的活动 [英] Android monkey test choose a specific activity

查看:128
本文介绍了Android的猴子测试选择一个特定的活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 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

这篇关于Android的猴子测试选择一个特定的活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆