aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJiangnan Shangguan <jiangnan@google.com>2014-09-18 14:51:22 -0700
committerJiangnan Shangguan <jiangnan@google.com>2014-09-18 14:55:22 -0700
commitecbd0fbd7b3ed1aa31c70b2c0148a8a01ffe8428 (patch)
tree11cf4d7959fb3251593e56c452926714d30591a5 /src
parent397975095c0a03376f2c12f1942546e3360628ac (diff)
downloaddroiddriver-ecbd0fbd7b3ed1aa31c70b2c0148a8a01ffe8428.tar.gz
Add replaceText function in UiElement
This function will delete the current text of the element and then call setText Change-Id: I2f97809a54e60bc4448246b8c050792168358147
Diffstat (limited to 'src')
-rw-r--r--src/com/google/android/droiddriver/UiElement.java7
-rw-r--r--src/com/google/android/droiddriver/base/BaseUiElement.java10
2 files changed, 17 insertions, 0 deletions
diff --git a/src/com/google/android/droiddriver/UiElement.java b/src/com/google/android/droiddriver/UiElement.java
index 71b43ed..72804d8 100644
--- a/src/com/google/android/droiddriver/UiElement.java
+++ b/src/com/google/android/droiddriver/UiElement.java
@@ -152,6 +152,13 @@ public interface UiElement {
void setText(String text);
/**
+ * Replace the text of this element.
+ *
+ * @param text The text that be replaced with
+ */
+ void replaceText(String text);
+
+ /**
* Clicks this element. The click will be at the center of the visible
* element.
*/
diff --git a/src/com/google/android/droiddriver/base/BaseUiElement.java b/src/com/google/android/droiddriver/base/BaseUiElement.java
index 3122ba3..ce3849a 100644
--- a/src/com/google/android/droiddriver/base/BaseUiElement.java
+++ b/src/com/google/android/droiddriver/base/BaseUiElement.java
@@ -21,6 +21,7 @@ import android.graphics.Rect;
import com.google.android.droiddriver.UiElement;
import com.google.android.droiddriver.actions.Action;
import com.google.android.droiddriver.actions.EventUiElementActor;
+import com.google.android.droiddriver.actions.SingleKeyAction;
import com.google.android.droiddriver.actions.UiElementActor;
import com.google.android.droiddriver.exceptions.DroidDriverException;
import com.google.android.droiddriver.finders.Attribute;
@@ -211,6 +212,15 @@ public abstract class BaseUiElement<R, E extends BaseUiElement<R, E>> implements
}
@Override
+ public void replaceText(String text) {
+ int len = this.getText().length();
+ for (int i = 0; i < len; i++) {
+ this.perform(SingleKeyAction.DELETE);
+ }
+ this.setText(text);
+ }
+
+ @Override
public void click() {
uiElementActor.click(this);
}