androidpythondrop-down-menumonkeyrunnerandroidviewclient

Culbera: Selecting things from dropdown list in an Android app


I am trying to test a drop down list with Culbera. My menu structure is as follows

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

Now Arm displays (makes visible) a drop down list that shows the list of ARM types.

I want to pick one from the dropdown list and then press Program Arm Type. For some reason this is not working as expected.

When I used

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

the trace I got is

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)

It popped up a text box. (I have no idea where it is coming from)? Can someone explain how to select things from a dropdown list in Culbera

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')

Solution

  • Picker

    A Picker is a widget composed of other widgets such as Button and EditText.

    This simple example shows a TimePicker

    enter image description here

    then, if you run

    dump
    

    this is part of the output

      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
    

    where you can see what I mean by composed.

    Then, when you click on some of the EditTexts, culebra understands that your intention is to enter some text and thus it shows the entry dialog

    enter image description here

    If you click on any of the Buttons, culebra will also understand your intention is to increase or decrease the Picker value and generates the corresponding touches.

    I'm not really sure what are the drop downs you mentioned. Are they Spinners? The output of dump will help understand.

    Spinner

    The case for the Spinner is a bit different as it's composed of the entry and the drop down menu.

    However, if you take a look at touch zones (CTRL+Z) you will see the entry and the drop down arrow are part of the same zone

    enter image description here

    I'm using ApiDemos here so if you want to test it or ask new questions we will have something to compare.

    Then, you click on the Spinner it opens the drop down

    enter image description here

    and you will get this code generated

    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()
    

    The first touch() might be a little trickier if you don't know the current value then you can use either the View Id or a regular expression to match all the options.