虽然True python脚本应该循环无限但它只执行一次 - Monkeyrunner

时间:2016-10-27 18:53:11

标签: python monkeyrunner

我创建了简单的python脚本来执行无限循环来测试我的Android应用程序,但它只能成功运行一次并停止。

# Imports the monkeyrunner modules used by this program
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice

# Connects to the current device, returning a MonkeyDevice object
device = MonkeyRunner.waitForConnection('66b6cc0e')

while True:
    device.touch (300, 1750, 'DOWN_AND_UP')
    MonkeyRunner.sleep(3)
    device.touch(742, 1213, 'DOWN_AND_UP')
    MonkeyRunner.sleep(10)
    device.touch(554, 1613, 'DOWN_AND_UP')
    MonkeyRunner.sleep(10)

# Push SEND MESSAGE
device.touch(300, 1750, 'DOWN_AND_UP')
MonkeyRunner.sleep(3)
device.touch(742, 1213, 'DOWN_AND_UP')
MonkeyRunner.sleep(10)
device.touch(554, 1613, 'DOWN_AND_UP')
MonkeyRunner.sleep(10)

2 个答案:

答案 0 :(得分:0)

您应该在tryhttps://docs.python.org/3/tutorial/errors.html)内拥有每个命令。有一个裸的除外(即全部除外)是不可取的,但你可以尝试进行调试。

答案 1 :(得分:0)

你可以使用AndroidViewClient/culebra几乎是monkeyruner的替代品,但它是纯粹的python。

我对您的脚本进行了更改以显示

#! /usr/bin/env python

# Imports the monkeyrunner modules used by this program
#from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice

import re
import sys
import os

from com.dtmilano.android.viewclient import ViewClient


# Connects to the current device, returning a MonkeyDevice object
#device = MonkeyRunner.waitForConnection('66b6cc0e')

kwargs1 = {'ignoreversioncheck': False, 'verbose': False, 'ignoresecuredevice': False}
device, serialno = ViewClient.connectToDeviceOrExit(**kwargs1)


while True:
    print "loop"
    device.touch (300, 1750, 'DOWN_AND_UP')
    ViewClient.sleep(3)
    device.touch(742, 1213, 'DOWN_AND_UP')
    ViewClient.sleep(10)
    device.touch(554, 1613, 'DOWN_AND_UP')
    ViewClient.sleep(10)

# Push SEND MESSAGE
device.touch(300, 1750, 'DOWN_AND_UP')
ViewClient.sleep(3)
device.touch(742, 1213, 'DOWN_AND_UP')
ViewClient.sleep(10)
device.touch(554, 1613, 'DOWN_AND_UP')
ViewClient.sleep(10)

此外,您可以利用Culebra GUI并通过点击UI自动生成此类脚本(甚至是单元测试)。