【发布时间】:2017-02-11 04:17:15
【问题描述】:
我有一个 Android 应用程序,我正在尝试使用 culebra 进行测试。代码如下所示。
'''reated on 2017-02-08 by Culebra v12.5.3
__ __ __ __
/ \ / \ / \ / \
____________________/ __\/ __\/ __\/ __\_____________________________
___________________/ /__/ /__/ /__/ /________________________________
| / \ / \ / \ / \ \___
|/ \_/ \_/ \_/ \ o \
\_____/--<
@author: Diego Torres Milano
@author: Jennifer E. Swofford (ascii art snake)
'''
import re
import sys
import os
from com.dtmilano.android.viewclient import ViewClient
from com.dtmilano.android.adb.adbclient import DOWN_AND_UP
kwargs1 = {'ignoreversioncheck': False, 'verbose': False, 'ignoresecuredevice': False}
device, serialno = ViewClient.connectToDeviceOrExit(**kwargs1)
kwargs2 = {'forceviewserveruse': False, 'useuiautomatorhelper': False, 'ignoreuiautomatorkilled': True, 'autodump': False, 'startviewserver': True, 'compresseddump': True}
vc = ViewClient(device, serialno, **kwargs2)
# Installs the Android package. Notice that this method returns a boolean, so you can test
# to see if the installation worked.
vc.installPackage('Abc App.Android.Abc App.Android-Signed.apk')
# sets a variable with the package's internal name
package = 'Abc App.Android.Abc App.Android'
# sets a variable with the name of an Activity in the packag
activity = 'md591ecfcc00ede54e89ae8714.MainActivity'
# sets the name of the component to start
runComponent = package + '/' + activity
# Runs the component
device.startActivity(component=runComponent)
vc.sleep(5)
#vc = ViewClient(device)
vc.dump()
for bt in [ 'PRO', 'FIE', 'DIA']:
b = vc.findViewWithAttribute('text:mText', bt)
if b:
(x, y) = b.getXY()
print >>sys.stderr, "clicking b%s @ (%d,%d) ..." % (bt, x, y)
b.touch()
time.sleep(7)
# Presses the Menu button
# device.press('KEYCODE_MENU', DOWN_AND_UP)
# Writes the screenshot to a file (you can use a plain filename or use these placeholders)
vc.writeImageToFile('/tmp/${serialno}-${focusedwindowname}-${timestamp}.png', 'PNG')
当我以
身份运行上述脚本时$ python test_culebra.py
我收到以下错误。
[100%] /data/local/tmp/AbcApp.Android.AbcApp.Android-Signed.apk
pkg: /data/local/tmp/AbcApp.Android.AbcApp.Android-Signed.apk
Success
Traceback (most recent call last):
File "monkey_runner_culebra.py", line 53, in <module>
print >>sys.stderr, "clicking b%s @ (%d,%d) ..." % (bt, x, y)
NameError: name 'x' is not defined
它正在安装和加载应用程序。但是它找不到带有文本PRO',FIE,DIA`等的按钮。
我在这里做错了什么。
【问题讨论】:
-
看来
b.getXY()没有返回视图的坐标。检查b是否包含您期望的内容。 -
另外,使用
culebra或culebra -G为一种情况生成触摸,然后您可以将其变成循环。这样你就会有正确的语法。 -
@DiegoTorresMilano - 如何在 python 脚本中使用 culbera -G?
-
抱歉,不够清楚。我不是说你可以在你的脚本中使用
culebra -Ginside,但你可以运行它,然后剪切并粘贴新生成的代码。
标签: android python monkeyrunner androidviewclient