Android monkey test选择一个特定的活动

ade*_*190 6 android monkey-testing android-activity

我正在使用Android猴子测试来测试我的Android应用程序,它适用于我的应用程序,非常酷.但是我想特定地测试一个应用程序活动,我该怎么做?

今天我正在测试所有应用程序:

$ adb shell monkey -p my.package -c android.intent.category.HOME -c android.intent.category.DEFAULT -v 500 -s "a random number"
Run Code Online (Sandbox Code Playgroud)

ade*_*190 8

使用Android猴子测试我无法测试特定的活动,但使用Android Monkey runner我可以做python脚本来模拟猴子测试,所以我做了一个python脚本打开我的活动并初始化猴子测试:)

#! /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"
Run Code Online (Sandbox Code Playgroud)

保存teste.py并运行

$ monkeyrunner teste.py
Run Code Online (Sandbox Code Playgroud)


Tel*_*ota 6

这对我有用.添加category清单:

<activity android:name="MonkeyActivity">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.MONKEY" />
    </intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud)

哪里MonkeyActivity将执行测试和shell的初始化设置:

adb shell monkey -p my.package -c android.intent.category.MONKEY -v 500
Run Code Online (Sandbox Code Playgroud)