Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Culebra在Android应用程序上按“文本”按钮_Android_Python_Monkeyrunner_Androidviewclient - Fatal编程技术网

使用Culebra在Android应用程序上按“文本”按钮

使用Culebra在Android应用程序上按“文本”按钮,android,python,monkeyrunner,androidviewclient,Android,Python,Monkeyrunner,Androidviewclient,我有一个Android应用程序,我正在尝试使用库莱布拉进行测试。代码如下所示 '''reated on 2017-02-08 by Culebra v12.5.3 __ __ __ __ / \ / \ / \ / \ ____________________/ __\/ __\/ __\/ __\_____________________________ ______

我有一个Android应用程序,我正在尝试使用库莱布拉进行测试。代码如下所示

'''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')
它正在安装和加载应用程序。但是,它无法找到文本为PRO',FIE',DIA'等的按钮

我做错了什么

运行

culebra -Gu -o myscript.py --scale=0.5
您将看到一个表示设备的窗口,很像

然后点击我在这里运行ApiDemos的按钮,culebra生成

vc.dump(window=-1)
vc.findViewWithTextOrRaise(u'NORMAL').touch()
vc.sleep(_s)
vc.dump(window=-1)
vc.findViewWithTextOrRaise(u'SMALL').touch()
vc.sleep(_s)
vc.dump(window=-1)
vc.findViewWithTextOrRaise(u'OFF').touch()
vc.sleep(_s)
vc.dump(window=-1)
然后您可以手动将其转换为

for t in ['NORMAL', 'SMALL', 'OFF']:
    b = vc.findViewWithTextOrRaise(t)
    print >> sys.stderr, "clicking", b,  "@", b.getXY()
    b.touch()
甚至

for t in ['NORMAL', 'SMALL', 'OFF']:
    vc.findViewWithTextOrRaise(t).touch()
这是假设当您单击按钮时屏幕不会改变,如果确实如此,您需要再次调用vc.dump


然后可以复制并粘贴到原始脚本。

看来b.getXY没有返回视图的坐标。检查b是否包含您期望的内容。此外,使用culebra或culebra-G为一个案例生成触摸,然后您可以将其变成一个循环。这样您就有了正确的语法。@DiegoTorresMilano-如何在python脚本中使用culbera-G?抱歉,不够清楚。我不是说你可以在脚本中使用culebra-G,但是你可以运行它,然后剪切粘贴新生成的代码
for t in ['NORMAL', 'SMALL', 'OFF']:
    vc.findViewWithTextOrRaise(t).touch()