monkeyrunner python脚本在循环内仅执行一次

时间:2018-11-06 12:21:12

标签: android for-loop testing monkeyrunner

我正在尝试针对我在本文中发现的monkeyrunner运行此脚本:

MonkeyRunner script

#! /usr/bin/env monkeyrunner

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

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

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

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

print "end monkey test"

它可以运行,但似乎for循环内的行仅执行一次。

device.touch(randint(0, 1000), randint(0, 800), 'DOWN_AND_UP')

有什么想法吗?我还想执行不同类型的点击和操作,例如命令行执行adb shell monkey -p my.package.name -v 500

我创建脚本是因为我需要确保已测试某些Activities。现在,如果我运行上面发布的命令,则monkey测试将进入一个活动,并且永远不会返回。

0 个答案:

没有答案