【问题标题】:Appium Test on Edit Text Clear Button On right SideAppium 测试右侧的编辑文本清除按钮
【发布时间】:2016-05-08 03:14:03
【问题描述】:

我正在使用 Appium 测试我的 Android 应用程序。我在文本右侧创建了一个带有 X(清除图标)的编辑文本,当用户单击此图标时,编辑文本变为空。问题是如何在 Appium 测试中测试此单击。

这是我的 xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="10dp">

<EditText
    android:id="@+id/password"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="Edit Text"
    android:padding="12dp"
    android:drawableRight="@android:drawable/ic_delete"// X icon at right side of edit text
    >
    <requestFocus />
</EditText>

这是代码

 passwordEditText.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            final int DRAWABLE_LEFT = 0;
            final int DRAWABLE_TOP = 1;
            final int DRAWABLE_RIGHT = 2;
            final int DRAWABLE_BOTTOM = 3;

            if (event.getAction() == MotionEvent.ACTION_UP) {

                if (event.getRawX() >= (passwordEditText.getRight() - passwordEditText.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width())) {
                    passwordEditText.setText(null);

                    return true;
                }
            }
            return false;
        }
    });

【问题讨论】:

  • 我没有在 appium 上看到任何尝试,希望您通过文档 @www.appium.io
  • android:drawableRight="@android:drawable/ic_delete"// X icon at right side of edit text 似乎没有附加到X 图标的 id 属性,除了它是一个可绘制的图标形式。
  • 是的,这就是问题所在,我正在使用此图标通过设置触摸侦听器来清除文本,如代码所示,但我该如何自动化这就是问题
  • 1.你总是可以使用 XPATH,我相信你在其中一个 cmets 中提供的 UI automator 的链接描述了一个 Viewassigned 甚至这个 drawable。 2.您可以尝试寻找它并为该特定选择附加一个 UI automator 视图
  • 很抱歉,实际上视图是发送按钮上方 1 dp 的分隔线,它与 X 图像无关

标签: android android-edittext automated-tests appium android-drawable


【解决方案1】:

使用发送键方法向您的编辑文本发送一些文本。然后单击您的 x 按钮并从编辑文本中获取文本并验证输入的文本是否已清除。这是您想要验证的内容吗?

【讨论】:

  • 我想自动点击 x 按钮我可以这样做吗?
  • 是的!你可以这样做!
  • 我该怎么做?因为 x 按钮没有单独的 id
  • 您可以使用 xpath 或 name 属性,按类名等。如果您可以发布您的按钮的 uiautomator 视图,这对我提出建议会有所帮助
  • scontent-sit4-1.xx.fbcdn.net/hphotos-xaf1/v/t35.0-12/… 按钮的 UI automator 视图链接
猜你喜欢
  • 2011-12-07
  • 2012-02-04
  • 2015-07-16
  • 1970-01-01
  • 1970-01-01
  • 2016-04-27
  • 1970-01-01
  • 2020-10-06
  • 1970-01-01
相关资源
最近更新 更多