求教 :monkeyrunner 测试工具的简单使用

L17265431970 2015-07-13 04:09:55
from com.android.monkeyrunner import MonkeyRunner,MonkeyDevice,MonkeyImage
device=MonkeyRunner.waitForConnection(1.0,'5069b007')
device.startActivity(component='com.android.contacts/com.android.contacts.DialtactsContactsEntryActivity')
MonkeyRunner.sleep(3)
for i in range(1,999999):
MonkeyRunner.sleep(4)
device.touch(23,36,MonkeyDevice.downAndUp)
MonkeyRunner.sleep(4)
device.touch(241,,906,MonkeyDevice.downAndUp)
MonkeyRunner.sleep(4)
print i
else:
print('end')


小弟是初学者,以上代码,就是实现一个简单的连续点击2个屏幕坐标的操作,但运行报错。

C:\Users\Administrator>monkeyrunner 234.py
150713 16:09:03.648:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions] Scri
pt terminated due to an exception
150713 16:09:03.648:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]Synta
xError: ("mismatched input '' expecting DEDENT", ('D:\\adt-bundle-windows\\sdk\\
tools\\234.py', 7, 1, '\tdevice.touch(23,36,MonkeyDevice.downAndUp)\n'))

150713 16:09:03.648:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at org.python.core.ParserFacade.fixParseError(ParserFacade.java:92)
150713 16:09:03.648:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at org.python.core.ParserFacade.parse(ParserFacade.java:184)
150713 16:09:03.648:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at org.python.core.Py.compile_flags(Py.java:1731)
150713 16:09:03.648:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at org.python.core.__builtin__.execfile_flags(__builtin__.java:514)
150713 16:09:03.648:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at org.python.util.PythonInterpreter.execfile(PythonInterpreter.java:225)
150713 16:09:03.648:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at com.android.monkeyrunner.ScriptRunner.run(ScriptRunner.java:116)
150713 16:09:03.648:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at com.android.monkeyrunner.MonkeyRunnerStarter.run(MonkeyRunnerStarter.java:77)

150713 16:09:03.648:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at com.android.monkeyrunner.MonkeyRunnerStarter.main(MonkeyRunnerStarter.java:18
9)
...全文
216 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
baiduchazhao 2016-08-30
  • 打赏
  • 举报
回复
您好!有没有自动化的测试工具!monkeyrunner!求教程!
L17265431970 2015-07-14
  • 打赏
  • 举报
回复
from com.android.monkeyrunner import MonkeyRunner,MonkeyDevice,MonkeyImage
print('import success')
device=MonkeyRunner.waitForConnection(1.0,'5069b007')
if device: 
	 print("Connect device successful!") 
else:
     print("Connect device failed!")
for i in range(1,99):
	 device=MonkeyRunner.waitForConnection(1.0,'5069b007')
	 if device: 
		 print('Connect device successful!') 
	 else:
		 print('Connect device failed!')     	
	 device.touch(243,348,MonkeyDevice.DOWN_AND_UP)
	 print('please upload sfz a')
     MonkeyRunner.sleep(1)
     device.touch(224,378,MonkeyDevice.DOWN_AND_UP)
     print('use the photo a')
     MonkeyRunner.sleep(1)
     device.touch(210,222,MonkeyDevice.DOWN_AND_UP)
     print('click photo group')
     MonkeyRunner.sleep(1)
     device.touch(460,150,MonkeyDevice.DOWN_AND_UP)
     print('selcet sfz a')
     MonkeyRunner.sleep(1)
     device.touch(264,574,MonkeyDevice.DOWN_AND_UP)
     print('please upload sfz b')
     MonkeyRunner.sleep(1)
     device.touch(271,476,MonkeyDevice.DOWN_AND_UP)
     print('use the photo b')
     MonkeyRunner.sleep(1)
     device.touch(204,202,MonkeyDevice.DOWN_AND_UP)
     print('select sfz b')
     MonkeyRunner.sleep(1)
     device.touch(271,160,MonkeyDevice.DOWN_AND_UP)
     print('click ready read')
     MonkeyRunner.sleep(1)
     device.touch(45,830,MonkeyDevice.DOWN_AND_UP)
     print('next1')
     MonkeyRunner.sleep(1)
     device.touch(114,910,MonkeyDevice.DOWN_AND_UP)
     print('next2')
     MonkeyRunner.sleep(1)
     device.touch(138,874,MonkeyDevice.DOWN_AND_UP)
     print('next3')
     MonkeyRunner.sleep(1)
     device.touch(23,36,MonkeyDevice.DOWN_AND_UP)
     print('retern1')
     MonkeyRunner.sleep(1)
     device.touch(23,36,MonkeyDevice.DOWN_AND_UP)
     print('retern2')
     MonkeyRunner.sleep(1)
     print('truned') ,i
else:
    print('end')

运行错误 150714 20:40:47.769:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]Inden tationError: ('unindent does not match any outer indentation level', ('D:\\adt-b undle-windows\\sdk\\tools\\3456.py', 16, 5, ' MonkeyRunner.sleep(1)\n'))
L17265431970 2015-07-13
  • 打赏
  • 举报
回复
for i in range(1,999999): 改为 for i in range(1,99): 就没问题
qq_21995109 2015-07-13
  • 打赏
  • 举报
回复
好非常的好,楼主是个好人 楼主是还哦人
L17265431970 2015-07-13
  • 打赏
  • 举报
回复
找到一个问题 DOWN_AND_UP 应该是大写

80,351

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧