【发布时间】: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