0

In the application I'm trying to automate with AndroidViewClient there are widgets implemented with NumberPicker. Using AndroidViewClient / culebra I can't distinguish the values / texts presented on those NumberPickers.

Prophet
  • 32,350
  • 22
  • 54
  • 79
  • Can you include all or part of the `dump` output? – Diego Torres Milano May 07 '14 at 14:29
  • # class=android.widget.FrameLayout no_id1 = vc.findViewByIdOrRaise("id/no_id/1") # class=android.view.View android___id_action_bar_overlay_layout = vc.findViewByIdOrRaise("android:id/action_bar_overlay_layout") # class=android.widget.FrameLayout android___id_action_bar_container = vc.findViewByIdOrRaise("android:id/action_bar_container") # class=android.view.View android___id_action_bar = vc.findViewByIdOrRaise("android:id/action_bar") # class=android.widget.LinearLayout no_id5 = vc.findViewByIdOrRaise("id/no_id/5") – Prophet May 07 '14 at 14:36
  • # class=android.widget.FrameLayout no_id6 = vc.findViewByIdOrRaise("id/no_id/6") # class=android.widget.ImageView android___id_home = vc.findViewByIdOrRaise("android:id/home") # class=android.widget.LinearLayout no_id8 = vc.findViewByIdOrRaise("id/no_id/8") # class=android.widget.TextView text=u'NumberPickerSamples' android___id_action_bar_title = vc.findViewByIdOrRaise("android:id/action_bar_title") # class=android.widget.FrameLayout android___id_content = vc.findViewByIdOrRaise("android:id/content") # class=android.widget.LinearLayout no_id11 = vc.findViewByIdOrRaise("id/no_id/11") – Prophet May 07 '14 at 14:37
  • This is all the mump file created by culebra. The application used is simplest example included in https://github.com/SimonVT/android-numberpicker zip file – Prophet May 07 '14 at 14:39
  • This is an image of real NumberPicker widget in our application http://www.filedropper.com/im – Prophet May 07 '14 at 14:51
  • And this is a file created by culebra dumping the image above http://www.filedropper.com/my2 – Prophet May 07 '14 at 14:53

1 Answers1

1

Due to how NumberPicker is implemented it does not appear in the dump showing its values. There may be other solutions but the one that comes first to my mind is to create a wrapper and set the content description as the value (this is done by some other Views too).

package net.simonvt.numberpicker.samples;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.widget.FrameLayout;

import net.simonvt.numberpicker.NumberPicker;
import net.simonvt.numberpicker.NumberPicker.OnValueChangeListener;

/**
 * @author diego
 */
public class NumberPickerHolder extends FrameLayout {

    protected static final String TAG = "NumberPickerHolder";

    private NumberPicker mNumberPicker;

    final OnValueChangeListener mOnValueChangedListener = new OnValueChangeListener() {

        @Override
        public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
            final String cd = Integer.toString(newVal);
            Log.d(TAG, "picker=" + picker + " content description set to " + cd);
            setContentDescription(cd);
        }
    };

    /**
     * @param context
     */
    public NumberPickerHolder(Context context) {
        super(context);
        init(context);
    }

    /**
     * @param context
     * @param attrs
     */
    public NumberPickerHolder(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    /**
     * @param context
     * @param attrs
     * @param defStyle
     */
    public NumberPickerHolder(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init(context);
    }

    private void init(Context context) {
        mNumberPicker = new NumberPicker(context);
        mNumberPicker.setOnValueChangedListener(mOnValueChangedListener);
        android.view.ViewGroup.LayoutParams lp = getLayoutParams();
        if (lp == null) {
            lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
        }
        addView(mNumberPicker, lp);
    }

    public void setMaxValue(int i) {
        mNumberPicker.setMaxValue(i);
    }

    public void setMinValue(int i) {
        mNumberPicker.setMinValue(i);
    }

}

Remember to use this new class in your layouts

    <!--   <net.simonvt.numberpicker.NumberPicker -->
    <net.simonvt.numberpicker.samples.NumberPickerHolder
        android:id="@+id/numberPicker"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

Then, in your culebra script you can get the value obtaining the content description

# class=android.widget.FrameLayout
net_simonvt_numberpicker_samples___id_numberPicker = vc.findViewByIdOrRaise("net.simonvt.numberpicker.samples:id/numberPicker")
print net_simonvt_numberpicker_samples___id_numberPicker.getContentDescription()
Diego Torres Milano
  • 65,697
  • 9
  • 111
  • 134
  • 1
    I'm building the application that need to have the automation test that the guy above is working on and I can't use this NumberPickerHolder since I have 4 different number pickers in my application and all of them share 1 common onValueChanged listener so I need to set each NumberPickerHolder to that listener, how can I do that? – user1582281 May 08 '14 at 16:00
  • 1
    the first argument of the `onValueChange` is the picker so the same listener could be used for different ones. – Diego Torres Milano May 08 '14 at 19:02