【问题标题】:Couldn't distinguish NumberPicker views by AndroidViewClient无法通过 AndroidViewClient 区分 NumberPicker 视图
【发布时间】:2014-06-24 13:44:24
【问题描述】:

在我尝试使用 AndroidViewClient 自动化的应用程序中,有一些使用 NumberPicker 实现的小部件。使用 AndroidViewClient / culebra 我无法区分这些 NumberPickers 上显示的值/文本。

【问题讨论】:

  • 您能否包含全部或部分dump 输出?
  • # 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")
  • # 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")
  • 这是culebra创建的所有mump文件。使用的应用程序是包含在github.com/SimonVT/android-numberpicker zip 文件中的最简单示例
  • 这是我们应用程序中真实 NumberPicker 小部件的图像filedropper.com/im

标签: android automation androidviewclient


【解决方案1】:

由于NumberPicker 的实现方式,它不会出现在显示其值的转储中。 可能还有其他解决方案,但我首先想到的是创建一个包装器并将内容描述设置为值(这也由其他一些视图完成)。

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);
    }

}

记得在你的布局中使用这个新类

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

然后,在您的 culebra 脚本中,您可以获得获取内容描述的值

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

【讨论】:

  • 我正在构建需要进行自动化测试的应用程序,上面的人正在处理,我不能使用这个 NumberPickerHolder,因为我的应用程序中有 4 个不同的数字选择器,所有这些选择器共享 1 个常见的 onValueChanged 侦听器,因此我需要将每个 NumberPickerHolder 设置为该侦听器,我该怎么做?
  • onValueChange 的第一个参数是选择器,因此相同的侦听器可以用于不同的侦听器。
猜你喜欢
  • 2016-10-24
  • 2014-06-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-01-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多