leipfise 发表于 2016-11-24 15:14:38

Monkeyrunner 循环出错 求指点

# coding:utf-8
from com.android.monkeyrunner import MonkeyRunner,MonkeyDevice
device=MonkeyRunner.waitForConnection(6,'emulator-5554')
for i in range(1,10):
device.startActivity(component="com.xs.cn/.activitys.LoadingActivity")
MonkeyRunner.sleep(2)
device.touch(280,470,"DOWN_AND_UP")
MonkeyRunner.sleep(1)
device.press('KEYCODE_BACK','DOWN_AND_UP')
MonkeyRunner.sleep(1)
device.touch(485,1072,"DOWN_AND_UP")
print i
else:
print('end')
在CMD执行后出现一大串,是哪里不对呢

sqqdvfhpn 发表于 2016-11-24 15:14:39

# Imports the monkeyrunner modules used by this program
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice, MonkeyImage
# Connects to the current device, returning a MonkeyDevice object
device = MonkeyRunner.waitForConnection()
# Installs the Android package. Notice that this method returns a boolean, so you can test
i=2
while i>0:
device.touch(119,568,"DOWN_AND_UP")
device.shell("input text goup01")
MonkeyRunner.sleep(8)
i=i-1
print(i)

print("wancheng")


这样你试下,应该是可以的,I是你循环的次数

梦想家 发表于 2016-11-25 11:08:51

for i in range(次数):
循环脚本
------------------------------------
报错了一定是你脚本写错了

Bugkiller 发表于 2016-11-25 11:26:21

沙发

fhhh_eyou 发表于 2016-11-25 18:06:14

com.android.monkeyrunner import MonkeyRunner.MonkeyRunnerOptions IS yntaxError:("mismatchedinput 'device'" expecting

INDENT",........   )

从开始定义时,函数错误。

leipfise 发表于 2016-11-26 17:36:43

fhhh_eyou 发表于 2016-11-25 18:06
com.android.monkeyrunner import MonkeyRunner.MonkeyRunnerOptions IS yntaxError"mismatchedinput ' ...

我去掉循环后,脚本是能够执行的,加上之后就不行了

leipfise 发表于 2016-11-26 17:40:52

梦想家 发表于 2016-11-25 11:08
for i in range(次数):
循环脚本
------------------------------------


具体是哪里出错了呢

xiaoaiwhc 发表于 2016-12-4 23:08:22

注意对齐, 缩进, 都用空格, 别TAB. 提示是语法错误了.
页: [1]
查看完整版本: Monkeyrunner 循环出错 求指点