Culebra:在 Android 应用中从下拉列表中选择内容

Culbera: Selecting things from dropdown list in an Android app

我正在尝试使用 Culbera 测试下拉列表。我的菜单结构如下

Main Page
   -- Program  - Setup - Arm    
                       - Torque 
   -- Test  

现在 Arm 显示(可见)一个显示 ARM 类型列表的下拉列表。

我想从下拉列表中选择一个,然后按 Program Arm Type。由于某种原因,这没有按预期工作。

当我使用

python culebra -Gu -o command_trace.txt --scale=01.0

我得到的痕迹是

vc.findViewWithTextOrRaise(u'Arm').touch()
vc.sleep(_s)
vc.dump(window=-1)
vc.findViewByIdOrRaise("id/no_id/21").setText(u"xxx")
vc.sleep(_s)
vc.dump(window=-1)
vc.findViewWithTextOrRaise(u'OK').touch()
vc.sleep(_s)
vc.dump(window=-1)
vc.findViewWithTextOrRaise(u'Program ArmType').touch()
vc.sleep(_s)
vc.dump(window=-1)

弹出一个文本框。 (我不知道它来自哪里)?有人可以解释如何从 Culbera

的下拉列表中 select 东西吗
import re
import sys
import os
import time


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}

_s = 3
_v = '--verbose' in sys.argv


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('AbcApp.Android.AbcApp.Android-Signed.apk')


# sets a variable with the package's internal name
package = 'AbcApp.Android.AbcApp.Android'

# sets a variable with the name of an Activity in the packag
activity = 'md591ecfcc0189ae8714.MainActivity'

# sets the name of the component to start
runComponent = package + '/' + activity

# Runs the component
device.startActivity(component=runComponent)

vc.sleep(5)

def GoToView(s):
    vc.findViewWithTextOrRaise(unicode(s)).touch()
    vc.sleep(_s)
    vc.dump(window=-1)

vc.dump(window=-1)

GoToView('Program')

GoToView('Setup')
vc.findViewWithTextOrRaise(u'Arm').touch()
vc.sleep(_s)
vc.dump(window=-1)

vc.findViewWithTextOrRaise(u'OK').touch()
vc.sleep(_s)
vc.dump(window=-1)
vc.findViewWithTextOrRaise(u'Program ArmType').touch()
vc.sleep(_s)
vc.dump(window=-1)


GoToView('Main')

选择器

一个Picker是由Button、EditText等其他widget组成的widget

这个简单的例子展示了一个 TimePicker

那么,如果你 运行

dump

这是输出的一部分

  android.widget.TimePicker com.dtmilano.android.demoapplication:id/timePicker 
     android.widget.NumberPicker  
        android.widget.Button  2
        android.widget.EditText android:id/numberpicker_input 3
        android.widget.Button  4
     android.widget.NumberPicker  
        android.widget.Button  33
        android.widget.EditText android:id/numberpicker_input 34
        android.widget.Button  35
     android.widget.NumberPicker  
        android.widget.EditText android:id/numberpicker_input AM
        android.widget.Button  PM

从哪里可以看出我所说的组合

然后,当您单击某些 EditText 时,culebra 明白您的意图是输入一些文本,因此它会显示输入对话框

如果您单击任何 按钮culebra 也会理解您的意图是增加或减少 Picker 值并生成相应的触摸。

我不太确定你提到的下拉菜单是什么。它们是 Spinner 吗? dump 的输出将有助于理解。

旋转器

Spinner 的情况有点不同,因为它由条目和下拉菜单组成。

但是,如果您查看 触摸区域 (CTRL+Z),您会看到条目和下拉箭头属于同一区域

我在这里使用 ApiDemos 所以如果你想测试它或提出新问题我们会有一些东西可以比较。

然后,您单击 微调器 它会打开下拉菜单

您将生成此代码

vc.dump(window=-1)
vc.findViewWithTextOrRaise(u'green', root=vc.findViewByIdOrRaise('id/no_id/4')).touch()
vc.sleep(_s)
vc.dump(window=-1)
vc.findViewWithTextOrRaise(u'violet').touch()

第一个 touch() 可能有点棘手,如果您不知道当前值,那么您可以使用视图 ID 或正则表达式来匹配所有选项。