aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKevin Jin <kjin@google.com>2014-04-04 11:55:58 -0700
committerKevin Jin <kjin@google.com>2014-04-04 11:55:58 -0700
commit5c9d7f7e2db9c7dd52543e455abff0449e21a90b (patch)
tree903e4f2e0ab038298770f0582af8223395d8ee61 /src
parentb91b93ad4787c19d769d0e8f3c1660231d6e0687 (diff)
downloaddroiddriver-5c9d7f7e2db9c7dd52543e455abff0449e21a90b.tar.gz
add selection-[start|end} attributes for TextView
Change-Id: I0fb7214437c450ffcccc7fb2ce94e32d7ec759dc
Diffstat (limited to 'src')
-rw-r--r--src/com/google/android/droiddriver/base/BaseUiElement.java18
-rw-r--r--src/com/google/android/droiddriver/finders/Attribute.java2
-rw-r--r--src/com/google/android/droiddriver/finders/ByXPath.java8
-rw-r--r--src/com/google/android/droiddriver/instrumentation/ViewElement.java7
-rw-r--r--src/com/google/android/droiddriver/uiautomation/UiAutomationElement.java5
5 files changed, 39 insertions, 1 deletions
diff --git a/src/com/google/android/droiddriver/base/BaseUiElement.java b/src/com/google/android/droiddriver/base/BaseUiElement.java
index c82c2f0..0db6c6a 100644
--- a/src/com/google/android/droiddriver/base/BaseUiElement.java
+++ b/src/com/google/android/droiddriver/base/BaseUiElement.java
@@ -134,6 +134,24 @@ public abstract class BaseUiElement implements UiElement {
return get(Attribute.BOUNDS);
}
+ // TODO: expose these 3 methods in UiElement?
+ public int getSelectionStart() {
+ Integer value = get(Attribute.SELECTION_START);
+ return value == null ? 0 : value;
+ }
+
+ public int getSelectionEnd() {
+ Integer value = get(Attribute.SELECTION_END);
+ return value == null ? 0 : value;
+ }
+
+ public boolean hasSelection() {
+ final int selectionStart = getSelectionStart();
+ final int selectionEnd = getSelectionEnd();
+
+ return selectionStart >= 0 && selectionStart != selectionEnd;
+ }
+
@Override
public boolean perform(Action action) {
Logs.call(this, "perform", action);
diff --git a/src/com/google/android/droiddriver/finders/Attribute.java b/src/com/google/android/droiddriver/finders/Attribute.java
index 1aeb86c..9799117 100644
--- a/src/com/google/android/droiddriver/finders/Attribute.java
+++ b/src/com/google/android/droiddriver/finders/Attribute.java
@@ -30,6 +30,8 @@ public enum Attribute {
PASSWORD("password"),
RESOURCE_ID("resource-id"),
SCROLLABLE("scrollable"),
+ SELECTION_START("selection-start"),
+ SELECTION_END("selection-end"),
SELECTED("selected"),
TEXT("text"),
BOUNDS("bounds");
diff --git a/src/com/google/android/droiddriver/finders/ByXPath.java b/src/com/google/android/droiddriver/finders/ByXPath.java
index 10e639c..fce8f0d 100644
--- a/src/com/google/android/droiddriver/finders/ByXPath.java
+++ b/src/com/google/android/droiddriver/finders/ByXPath.java
@@ -152,6 +152,12 @@ public class ByXPath implements Finder {
setAttribute(element, Attribute.SCROLLABLE, uiElement.isScrollable());
setAttribute(element, Attribute.LONG_CLICKABLE, uiElement.isLongClickable());
setAttribute(element, Attribute.PASSWORD, uiElement.isPassword());
+ if (uiElement.hasSelection()) {
+ element.setAttribute(Attribute.SELECTION_START.getName(),
+ Integer.toString(uiElement.getSelectionStart()));
+ element.setAttribute(Attribute.SELECTION_END.getName(),
+ Integer.toString(uiElement.getSelectionEnd()));
+ }
setAttribute(element, Attribute.SELECTED, uiElement.isSelected());
element.setAttribute(Attribute.BOUNDS.getName(), uiElement.getBounds().toShortString());
@@ -159,7 +165,7 @@ public class ByXPath implements Finder {
if (!UiElement.VISIBLE.equals(predicate)) {
if (!uiElement.isVisible()) {
element.setAttribute(BaseUiElement.ATTRIB_NOT_VISIBLE, "");
- } else if (!uiElement.getVisibleBounds().equals(uiElement.getBounds())){
+ } else if (!uiElement.getVisibleBounds().equals(uiElement.getBounds())) {
element.setAttribute(BaseUiElement.ATTRIB_VISIBLE_BOUNDS, uiElement.getVisibleBounds()
.toShortString());
}
diff --git a/src/com/google/android/droiddriver/instrumentation/ViewElement.java b/src/com/google/android/droiddriver/instrumentation/ViewElement.java
index 5c39dc4..0b1f360 100644
--- a/src/com/google/android/droiddriver/instrumentation/ViewElement.java
+++ b/src/com/google/android/droiddriver/instrumentation/ViewElement.java
@@ -74,6 +74,13 @@ public class ViewElement extends BaseUiElement {
put(Attribute.LONG_CLICKABLE, view.isLongClickable());
put(Attribute.PASSWORD, isPassword());
put(Attribute.SCROLLABLE, isScrollable());
+ if (view instanceof TextView) {
+ TextView textView = (TextView) view;
+ if (textView.hasSelection()) {
+ attribs.put(Attribute.SELECTION_START, textView.getSelectionStart());
+ attribs.put(Attribute.SELECTION_END, textView.getSelectionEnd());
+ }
+ }
put(Attribute.SELECTED, view.isSelected());
put(Attribute.BOUNDS, getBounds());
diff --git a/src/com/google/android/droiddriver/uiautomation/UiAutomationElement.java b/src/com/google/android/droiddriver/uiautomation/UiAutomationElement.java
index 8b81485..5e55148 100644
--- a/src/com/google/android/droiddriver/uiautomation/UiAutomationElement.java
+++ b/src/com/google/android/droiddriver/uiautomation/UiAutomationElement.java
@@ -85,6 +85,11 @@ public class UiAutomationElement extends BaseUiElement {
put(attribs, Attribute.LONG_CLICKABLE, node.isLongClickable());
put(attribs, Attribute.PASSWORD, node.isPassword());
put(attribs, Attribute.SCROLLABLE, node.isScrollable());
+ if (node.getTextSelectionStart() >= 0
+ && node.getTextSelectionStart() != node.getTextSelectionEnd()) {
+ attribs.put(Attribute.SELECTION_START, node.getTextSelectionStart());
+ attribs.put(Attribute.SELECTION_END, node.getTextSelectionEnd());
+ }
put(attribs, Attribute.SELECTED, node.isSelected());
put(attribs, Attribute.BOUNDS, getBounds(node));
attributes = ImmutableMap.copyOf(attribs);