diff options
author | Adam Momtaz <amomtaz@google.com> | 2012-06-28 13:33:11 -0700 |
---|---|---|
committer | Adam Momtaz <amomtaz@google.com> | 2012-06-29 14:12:56 -0700 |
commit | 4ab790eccf6d5c27f542056b87d26d38f7caeeb3 (patch) | |
tree | 70070b768335fbed8140e7f0df40cb2dcfe615cb | |
parent | aecdc4a41f1f2f3e76e05d6549df75359f8397c3 (diff) | |
download | testing-4ab790eccf6d5c27f542056b87d26d38f7caeeb3.tar.gz |
Allow selectors to be created with new operator
- Also renamed the By selector to Selector and updated all tests.
- Fixed the Selector clone method
- Renamed touch to click and updated comments
Change-Id: If338525e2759c1211497300bac20a6ceea8f926f
-rw-r--r-- | uiautomator/library/src/com/android/uiautomator/core/InteractionController.java | 4 | ||||
-rw-r--r-- | uiautomator/library/src/com/android/uiautomator/core/QueryController.java | 65 | ||||
-rw-r--r-- | uiautomator/library/src/com/android/uiautomator/core/UiCollection.java | 42 | ||||
-rw-r--r-- | uiautomator/library/src/com/android/uiautomator/core/UiDevice.java | 8 | ||||
-rw-r--r-- | uiautomator/library/src/com/android/uiautomator/core/UiObject.java | 135 | ||||
-rw-r--r-- | uiautomator/library/src/com/android/uiautomator/core/UiObjectNotFoundException.java | 2 | ||||
-rw-r--r-- | uiautomator/library/src/com/android/uiautomator/core/UiScrollable.java | 64 | ||||
-rw-r--r-- | uiautomator/library/src/com/android/uiautomator/core/UiSelector.java (renamed from uiautomator/library/src/com/android/uiautomator/core/By.java) | 201 |
8 files changed, 234 insertions, 287 deletions
diff --git a/uiautomator/library/src/com/android/uiautomator/core/InteractionController.java b/uiautomator/library/src/com/android/uiautomator/core/InteractionController.java index 2d9301f..dfd46bb 100644 --- a/uiautomator/library/src/com/android/uiautomator/core/InteractionController.java +++ b/uiautomator/library/src/com/android/uiautomator/core/InteractionController.java @@ -132,7 +132,7 @@ class InteractionController { return longPressTimeout; } - public boolean tap(int x, int y) { + public boolean click(int x, int y) { if (DEBUG) { Log.d(LOG_TAG, "tap (" + x + ", " + y + ")"); } @@ -146,7 +146,7 @@ class InteractionController { return false; } - public boolean tapAndWaitForNewWindow(final int x, final int y, long timeout) { + public boolean clickAndWaitForNewWindow(final int x, final int y, long timeout) { if (DEBUG) { Log.d(LOG_TAG, "tap (" + x + ", " + y + ")"); } diff --git a/uiautomator/library/src/com/android/uiautomator/core/QueryController.java b/uiautomator/library/src/com/android/uiautomator/core/QueryController.java index 3e2d81f..d4c9a49 100644 --- a/uiautomator/library/src/com/android/uiautomator/core/QueryController.java +++ b/uiautomator/library/src/com/android/uiautomator/core/QueryController.java @@ -23,7 +23,7 @@ import android.view.accessibility.AccessibilityNodeInfo; import com.android.uiautomator.core.UiAutomatorBridge.AccessibilityEventListener; /** - * The QuertController main purpose is to translate a {@link By} selectors to + * The QuertController main purpose is to translate a {@link UiSelector} selectors to * {@link AccessibilityNodeInfo}. This is all this controller does. It is typically * created in conjunction with a {@link InteractionController} by {@link UiAutomationContext} * which owns both. {@link UiAutomationContext} is used by {@link UiBase} classes. @@ -126,7 +126,7 @@ class QueryController { * @param selector * @return number of pattern matches. Returns 0 for all other cases. */ - public int getPatternCount(By selector) { + public int getPatternCount(UiSelector selector) { findAccessibilityNodeInfo(selector, true /*counting*/); return mPatternCounter; } @@ -136,11 +136,12 @@ class QueryController { * @param selector * @return */ - public AccessibilityNodeInfo findAccessibilityNodeInfo(By selector) { + public AccessibilityNodeInfo findAccessibilityNodeInfo(UiSelector selector) { return findAccessibilityNodeInfo(selector, false); } - protected AccessibilityNodeInfo findAccessibilityNodeInfo(By selector, boolean isCounting) { + protected AccessibilityNodeInfo findAccessibilityNodeInfo(UiSelector selector, + boolean isCounting) { mUiAutomatorBridge.waitForIdle(); initializeNewSearch(); @@ -155,8 +156,8 @@ class QueryController { } // Copy so that we don't modify the original's sub selectors - By bySelector = By.selector(selector); - return translateCompoundSelector(bySelector, rootNode, isCounting); + UiSelector uiSelector = new UiSelector(selector); + return translateCompoundSelector(uiSelector, rootNode, isCounting); } } @@ -208,47 +209,47 @@ class QueryController { * directly treated as regular_selector. So the presence of a CONTAINER and PATTERN within * a selector simply dictates that the selector matching will be constraint to the sub tree * node where the CONTAINER and its child PATTERN have identified. - * @param bySelector + * @param selector * @param fromNode * @param isCounting * @return */ - private AccessibilityNodeInfo translateCompoundSelector(By bySelector, + private AccessibilityNodeInfo translateCompoundSelector(UiSelector selector, AccessibilityNodeInfo fromNode, boolean isCounting) { // Start translating compound selectors by translating the regular_selector first // The regular_selector is then used as a container for any optional pattern_selectors // that may or may not be specified. - if(bySelector.hasContainerSelector()) + if(selector.hasContainerSelector()) // nested pattern selectors - if(bySelector.getContainerSelector().hasContainerSelector()) { + if(selector.getContainerSelector().hasContainerSelector()) { fromNode = translateCompoundSelector( - bySelector.getContainerSelector(), fromNode, false); + selector.getContainerSelector(), fromNode, false); initializeNewSearch(); } else - fromNode = translateReqularSelector(bySelector.getContainerSelector(), fromNode); + fromNode = translateReqularSelector(selector.getContainerSelector(), fromNode); else - fromNode = translateReqularSelector(bySelector, fromNode); + fromNode = translateReqularSelector(selector, fromNode); if(fromNode == null) { if(DEBUG) - Log.i(LOG_TAG, "Container selector not found: " + bySelector.dumpToString(false)); + Log.i(LOG_TAG, "Container selector not found: " + selector.dumpToString(false)); return null; } - if(bySelector.hasPatternSelector()) { - fromNode = translatePatternSelector(bySelector.getPatternSelector(), + if(selector.hasPatternSelector()) { + fromNode = translatePatternSelector(selector.getPatternSelector(), fromNode, isCounting); if (isCounting) { Log.i(LOG_TAG, String.format( - "Counted %d instances of: %s", mPatternCounter, bySelector)); + "Counted %d instances of: %s", mPatternCounter, selector)); return null; } else { if(fromNode == null) { if(DEBUG) Log.i(LOG_TAG, "Pattern selector not found: " + - bySelector.dumpToString(false)); + selector.dumpToString(false)); return null; } } @@ -256,22 +257,22 @@ class QueryController { // translate any additions to the selector that may have been added by tests // with getChild(By selector) after a container and pattern selectors - if(bySelector.hasContainerSelector() || bySelector.hasPatternSelector()) { - if(bySelector.hasChildSelector() || bySelector.hasParentSelector()) - fromNode = translateReqularSelector(bySelector, fromNode); + if(selector.hasContainerSelector() || selector.hasPatternSelector()) { + if(selector.hasChildSelector() || selector.hasParentSelector()) + fromNode = translateReqularSelector(selector, fromNode); } if(fromNode == null) { if(DEBUG) - Log.i(LOG_TAG, "Object Not Found for selector " + bySelector); + Log.i(LOG_TAG, "Object Not Found for selector " + selector); return null; } - Log.i(LOG_TAG, String.format("Matched selector: %s <<==>> [%s]", bySelector, fromNode)); + Log.i(LOG_TAG, String.format("Matched selector: %s <<==>> [%s]", selector, fromNode)); return fromNode; } /** - * Used by the {@link #translateCompoundSelector(By, AccessibilityNodeInfo, boolean)} + * Used by the {@link #translateCompoundSelector(UiSelector, AccessibilityNodeInfo, boolean)} * to translate the regular_selector portion. It has the following format: * <p/> * regular_selector = By[attributes... CHILD=By[attributes... CHILD=By[....]]]<br/> @@ -284,13 +285,13 @@ class QueryController { * @param index * @return AccessibilityNodeInfo if found else null */ - private AccessibilityNodeInfo translateReqularSelector(By selector, + private AccessibilityNodeInfo translateReqularSelector(UiSelector selector, AccessibilityNodeInfo fromNode) { return findNodeRegularRecursive(selector, fromNode, 0); } - private AccessibilityNodeInfo findNodeRegularRecursive(By subSelector, + private AccessibilityNodeInfo findNodeRegularRecursive(UiSelector subSelector, AccessibilityNodeInfo fromNode, int index) { if (subSelector.isMatchFor(fromNode, index)) { @@ -350,7 +351,7 @@ class QueryController { } /** - * Used by the {@link #translateCompoundSelector(By, AccessibilityNodeInfo, boolean)} + * Used by the {@link #translateCompoundSelector(UiSelector, AccessibilityNodeInfo, boolean)} * to translate the pattern_selector portion. It has the following format: * <p/> * pattern_selector = ... PATTERN=By[instance=x PATTERN=[regular_selector]]<br/> @@ -368,9 +369,9 @@ class QueryController { * @param fromNode * @param originalPattern * @return null of node is not found or if counting mode is true. - * See {@link #translateCompoundSelector(By, AccessibilityNodeInfo, boolean)} + * See {@link #translateCompoundSelector(UiSelector, AccessibilityNodeInfo, boolean)} */ - private AccessibilityNodeInfo translatePatternSelector(By subSelector, + private AccessibilityNodeInfo translatePatternSelector(UiSelector subSelector, AccessibilityNodeInfo fromNode, boolean isCounting) { if(subSelector.hasPatternSelector()) { @@ -401,7 +402,8 @@ class QueryController { } private AccessibilityNodeInfo findNodePatternRecursive( - By subSelector, AccessibilityNodeInfo fromNode, int index, By originalPattern) { + UiSelector subSelector, AccessibilityNodeInfo fromNode, int index, + UiSelector originalPattern) { if (subSelector.isMatchFor(fromNode, index)) { if(subSelector.isLeaf()) { @@ -466,7 +468,8 @@ class QueryController { } if (!childNode.isVisibleToUser()) { // TODO: need to remove this or move it under if (DEBUG) - Log.d(LOG_TAG, String.format("Skipping invisible child: %s", childNode.toString())); + Log.d(LOG_TAG, + String.format("Skipping invisible child: %s", childNode.toString())); continue; } AccessibilityNodeInfo retNode = findNodePatternRecursive( diff --git a/uiautomator/library/src/com/android/uiautomator/core/UiCollection.java b/uiautomator/library/src/com/android/uiautomator/core/UiCollection.java index 8b7c3b3..db0007e 100644 --- a/uiautomator/library/src/com/android/uiautomator/core/UiCollection.java +++ b/uiautomator/library/src/com/android/uiautomator/core/UiCollection.java @@ -21,29 +21,29 @@ package com.android.uiautomator.core; * if a list view contained many list items each in its own LinearLayout, and * the test desired to locate an On/Off switch next to text Wi-Fi so not to be * confused with a switch near text Bluetooth, the test use a UiCollection pointing - * at the list view of the items then use {@link #getChildByText(By, String)} for + * at the list view of the items then use {@link #getChildByText(UiSelector, String)} for * locating the LinearLayout element containing the text Wi-Fi. The returned UiObject * can further be used to retrieve a child by selector targeting the desired switch and * not other switches that may also be in the list. */ public class UiCollection extends UiObject { - public UiCollection(By selector) { + public UiCollection(UiSelector selector) { super(selector); } /** - * Searches for child UI element within the constraints of this UiCollection {@link By} + * Searches for child UI element within the constraints of this UiCollection {@link UiSelector} * selector. It looks for any child matching the <code>childPattern</code> argument that has * a child UI element anywhere within its sub hierarchy that has content-description text. * The returned UiObject will point at the <code>childPattern</code> instance that matched the * search and not at the identifying child element that matched the content description.</p> - * @param childPattern {@link By} selector of the child pattern to match and return + * @param childPattern {@link UiSelector} selector of the child pattern to match and return * @param text String of the identifying child contents of of the <code>childPattern</code> * @return {@link UiObject} pointing at and instance of <code>childPattern</code> * @throws UiObjectNotFoundException */ - public UiObject getChildByDescription(By childPattern, String text) + public UiObject getChildByDescription(UiSelector childPattern, String text) throws UiObjectNotFoundException { if (text != null) { int count = getChildCount(childPattern); @@ -53,7 +53,7 @@ public class UiCollection extends UiObject { if(nodeDesc != null && nodeDesc.contains(text)) { return row; } - UiObject item = row.getChild(By.selector().descriptionContains(text)); + UiObject item = row.getChild(new UiSelector().descriptionContains(text)); if (item.exists()) { return row; } @@ -63,35 +63,35 @@ public class UiCollection extends UiObject { } /** - * Searches for child UI element within the constraints of this UiCollection {@link By} + * Searches for child UI element within the constraints of this UiCollection {@link UiSelector} * selector. It looks for any child matching the <code>childPattern</code> argument that has * a child UI element anywhere within its sub hierarchy that is at the <code>instance</code> * specified. The operation is performed only on the visible items and no scrolling is performed * in this case. - * @param childPattern {@link By} selector of the child pattern to match and return + * @param childPattern {@link UiSelector} selector of the child pattern to match and return * @param instance int the desired matched instance of this <code>childPattern</code> * @return {@link UiObject} pointing at and instance of <code>childPattern</code> */ - public UiObject getChildByInstance(By childPattern, int instance) + public UiObject getChildByInstance(UiSelector childPattern, int instance) throws UiObjectNotFoundException { - By patternSelector = By.patternBuilder(getSelector(), - By.patternBuilder(childPattern).instance(instance)); + UiSelector patternSelector = UiSelector.patternBuilder(getSelector(), + UiSelector.patternBuilder(childPattern).instance(instance)); return new UiObject(patternSelector); } /** - * Searches for child UI element within the constraints of this UiCollection {@link By} + * Searches for child UI element within the constraints of this UiCollection {@link UiSelector} * selector. It looks for any child matching the <code>childPattern</code> argument that has * a child UI element anywhere within its sub hierarchy that has text attribute = * <code>text</code>. The returned UiObject will point at the <code>childPattern</code> * instance that matched the search and not at the identifying child element that matched the * text attribute.</p> - * @param childPattern {@link By} selector of the child pattern to match and return + * @param childPattern {@link UiSelector} selector of the child pattern to match and return * @param text String of the identifying child contents of of the <code>childPattern</code> * @return {@link UiObject} pointing at and instance of <code>childPattern</code> * @throws UiObjectNotFoundException */ - public UiObject getChildByText(By childPattern, String text) + public UiObject getChildByText(UiSelector childPattern, String text) throws UiObjectNotFoundException { if (text != null) { @@ -102,7 +102,7 @@ public class UiCollection extends UiObject { if(text.equals(nodeText)) { return row; } - UiObject item = row.getChild(By.selector().text(text)); + UiObject item = row.getChild(new UiSelector().text(text)); if (item.exists()) { return row; } @@ -114,13 +114,15 @@ public class UiCollection extends UiObject { /** * Count child UI element instances matching the <code>childPattern</code> * argument. The number of elements match returned represent those elements that are - * currently visible on the display within the sub hierarchy of this UiCollection {@link By} - * selector. Take note that more elements may be present but invisible and are not counted. - * @param childPattern is a {@link By} selector that is a pattern to count + * currently visible on the display within the sub hierarchy of this UiCollection + * {@link UiSelector} selector. Take note that more elements may be present but + * invisible and are not counted. + * @param childPattern is a {@link UiSelector} selector that is a pattern to count * @return the number of matched childPattern under the current {@link UiCollection} */ - public int getChildCount(By childPattern) { - By patternSelector = By.patternBuilder(getSelector(), By.patternBuilder(childPattern)); + public int getChildCount(UiSelector childPattern) { + UiSelector patternSelector = + UiSelector.patternBuilder(getSelector(), UiSelector.patternBuilder(childPattern)); return getQueryController().getPatternCount(patternSelector); } } diff --git a/uiautomator/library/src/com/android/uiautomator/core/UiDevice.java b/uiautomator/library/src/com/android/uiautomator/core/UiDevice.java index c1a867c..8f929c4 100644 --- a/uiautomator/library/src/com/android/uiautomator/core/UiDevice.java +++ b/uiautomator/library/src/com/android/uiautomator/core/UiDevice.java @@ -330,16 +330,16 @@ public class UiDevice { } /** - * Perform a touch at arbitrary coordinates specified by the user + * Perform a click at arbitrary coordinates specified by the user * @param x coordinate * @param y coordinate - * @return true if the touch succeeded else false + * @return true if the click succeeded else false */ - public boolean touch(int x, int y) { + public boolean click(int x, int y) { if (x >= getDisplayWidth() || y >= getDisplayHeight()) { return (false); } - return getAutomatorBridge().getInteractionController().tap(x, y); + return getAutomatorBridge().getInteractionController().click(x, y); } /** diff --git a/uiautomator/library/src/com/android/uiautomator/core/UiObject.java b/uiautomator/library/src/com/android/uiautomator/core/UiObject.java index 9d09332..4c49ae7 100644 --- a/uiautomator/library/src/com/android/uiautomator/core/UiObject.java +++ b/uiautomator/library/src/com/android/uiautomator/core/UiObject.java @@ -37,24 +37,24 @@ public class UiObject { protected static final long WAIT_FOR_WINDOW_TMEOUT = 5500; protected static final int SWIPE_MARGIN_LIMIT = 5; - protected By mSelector; + protected UiSelector mSelector; protected final UiDevice mDevice; protected final UiAutomatorBridge mUiAutomationBridge; /** * Constructs a UiObject that references any UI element that may match the specified - * {@link By} selector. UiObject can be pre-constructed and reused across an application - * where applicable. A good example is a tool bar and its buttons. A tool bar may remain - * visible on the various views the application is displaying but may have different - * contextual buttons displayed for each. The same UiObject that describes the tool bar - * can be reused.<p/> + * {@link UiSelector} selector. UiObject can be pre-constructed and reused across an + * application where applicable. A good example is a tool bar and its buttons. + * A toolbar may remain visible on the various views the application is displaying but + * may have different contextual buttons displayed for each. The same UiObject that + * describes the toolbar can be reused.<p/> * It is a good idea in certain cases before using any operations of this UiObject is to * call {@link #exists()} to verify if the UI element matching this object is actually * visible on the screen. This way the test can gracefully handle this situation else * a {@link UiObjectNotFoundException} will be thrown when using this object. * @param selector */ - public UiObject(By selector) { + public UiObject(UiSelector selector) { mUiAutomationBridge = UiDevice.getInstance().getAutomatorBridge(); mDevice = UiDevice.getInstance(); mSelector = selector; @@ -63,15 +63,15 @@ public class UiObject { /** * Helper for debugging. During testing a test can dump the selector of the object into * its logs of needed. <code>getSelector().toString();</code> - * @return {@link By} + * @return {@link UiSelector} */ - public final By getSelector() { - return By.selector(mSelector); + public final UiSelector getSelector() { + return new UiSelector(mSelector); } /** * Used in test operations to retrieve the {@link QueryController} to translate - * a {@link By} selector into an {@link AccessibilityNodeInfo}. + * a {@link UiSelector} selector into an {@link AccessibilityNodeInfo}. * @return {@link QueryController} */ protected QueryController getQueryController() { @@ -94,8 +94,8 @@ public class UiObject { * @param selector * @return a new UiObject with a new selector. It doesn't test if the object exists. */ - public UiObject getChild(By selector) throws UiObjectNotFoundException { - return new UiObject(By.selector(getSelector().childSelector(selector))); + public UiObject getChild(UiSelector selector) throws UiObjectNotFoundException { + return new UiObject(getSelector().childSelector(selector)); } /** @@ -106,8 +106,8 @@ public class UiObject { * @return * @throws UiObjectNotFoundException */ - public UiObject getFromParent(By selector) throws UiObjectNotFoundException { - return new UiObject(By.selector(getSelector().fromParent(selector))); + public UiObject getFromParent(UiSelector selector) throws UiObjectNotFoundException { + return new UiObject(getSelector().fromParent(selector)); } /** @@ -127,7 +127,7 @@ public class UiObject { /** * Helper method to allow for a specific content to become present on the * screen before moving on to do other operations. - * @param selector {@link By} + * @param selector {@link UiSelector} * @param timeout in milliseconds * @return AccessibilityNodeInfo if found else null */ @@ -288,7 +288,7 @@ public class UiObject { } /** - * Performs a tap over the UI element this object represents. </p> + * Performs a click over the UI element this object represents. </p> * Take note that the UI element directly represented by this UiObject may not have * its attribute <code>clickable</code> set to <code>true</code> and yet still perform * the click successfully. This is because all clicks are performed in the center of the @@ -304,12 +304,13 @@ public class UiObject { throw new UiObjectNotFoundException(getSelector().toString()); } Rect rect = getVisibleBounds(node); - return getInteractionController().tap(rect.centerX(), rect.centerY()); + return getInteractionController().click(rect.centerX(), rect.centerY()); } /** * - * Performs a tap over the represented UI element, and expect window transition as a result.</p> + * Performs a click over the represented UI element, and expect window transition as + * a result.</p> * * This method is similar to the plain {@link UiObject#click()}, with an important difference * that the method goes further to expect a window transition as a result of the tap. Some @@ -329,7 +330,8 @@ public class UiObject { /** * - * Performs a tap over the represented UI element, and expect window transition as a result.</p> + * Performs a click over the represented UI element, and expect window transition as + * a result.</p> * * This method is similar to the plain {@link UiObject#click()}, with an important difference * that the method goes further to expect a window transition as a result of the tap. Some @@ -350,12 +352,12 @@ public class UiObject { throw new UiObjectNotFoundException(getSelector().toString()); } Rect rect = getVisibleBounds(node); - return getInteractionController().tapAndWaitForNewWindow( + return getInteractionController().clickAndWaitForNewWindow( rect.centerX(), rect.centerY(), timeout); } /** - * Click the top and left corner of the UI element. + * Clicks the top and left corner of the UI element. * @return true on success * @throws Exception */ @@ -365,11 +367,11 @@ public class UiObject { throw new UiObjectNotFoundException(getSelector().toString()); } Rect rect = getVisibleBounds(node); - return getInteractionController().tap(rect.left + 5, rect.top + 5); + return getInteractionController().click(rect.left + 5, rect.top + 5); } /** - * Long clicks a UI element pointed to by the {@link By} selector of this object at the + * Long clicks a UI element pointed to by the {@link UiSelector} selector of this object at the * bottom right corner. The duration of what will be considered as a long click is dynamically * retrieved from the system and used in the operation. * @return true if operation was successful @@ -385,7 +387,7 @@ public class UiObject { } /** - * Click the bottom and right corner of the UI element. + * Clicks the bottom and right corner of the UI element. * @return true on success * @throws Exception */ @@ -395,11 +397,11 @@ public class UiObject { throw new UiObjectNotFoundException(getSelector().toString()); } Rect rect = getVisibleBounds(node); - return getInteractionController().tap(rect.right - 5, rect.bottom - 5); + return getInteractionController().click(rect.right - 5, rect.bottom - 5); } /** - * Long clicks a UI element pointed to by the {@link By} selector of this object. The + * Long clicks a UI element pointed to by the {@link UiSelector} selector of this object. The * duration of what will be considered as a long click is dynamically retrieved from the * system and used in the operation. * @return true if operation was successful @@ -415,7 +417,7 @@ public class UiObject { } /** - * Long clicks a UI element pointed to by the {@link By} selector of this object at the + * Long clicks a UI element pointed to by the {@link UiSelector} selector of this object at the * top left corner. The duration of what will be considered as a long click is dynamically * retrieved from the system and used in the operation. * @return true if operation was successful @@ -467,8 +469,8 @@ public class UiObject { /** * First this function clears the existing text from the field. If this is not the intended * behavior, do a {@link #getText()} first, modify the text and then use this function. - * The {@link By} selector of this object MUST be pointing directly at a UI element that - * can accept edits. The way this method works is by first performing a {@link #click()} + * The {@link UiSelector} selector of this object MUST be pointing directly at a UI element + * that can accept edits. The way this method works is by first performing a {@link #click()} * on the edit field to set focus then it begins injecting the content of the text param * into the system. Since the targeted field is in focus, the text contents should be * inserted into the field.<p/> @@ -499,7 +501,7 @@ public class UiObject { Rect rect = getVisibleBounds(node); getInteractionController().longTap(rect.left + 20, rect.centerY()); // check if the edit menu is open - UiObject selectAll = new UiObject(By.selector().descriptionContains("Select all")); + UiObject selectAll = new UiObject(new UiSelector().descriptionContains("Select all")); if(selectAll.waitForExists(50)) selectAll.click(); // wait for the selection @@ -510,11 +512,8 @@ public class UiObject { /** * Check if item pointed to by this object's selector is currently checked. <p/> - * Take note that the {@link By} selector specified for this UiObjecy must be pointing - * directly at the element you wish to query for this attribute as this UiObject may be - * using {@link By} selectors that may be pointing at a parent element of the element - * you're querying while still providing the desired functionality in terms of coordinates - * for taps and swipes. + * Take note that the {@link UiSelector} specified for this UiObjecy must be pointing + * directly at the element you wish to query for this attribute. * @return true if it is else false */ public boolean isChecked() throws UiObjectNotFoundException { @@ -527,11 +526,8 @@ public class UiObject { /** * Check if item pointed to by this object's selector is currently selected.<p/> - * Take note that the {@link By} selector specified for this UiObjecy must be pointing - * directly at the element you wish to query for this attribute as this UiObject may be - * using {@link By} selectors that may be pointing at a parent element of the element - * you're querying while still providing the desired functionality in terms of coordinates - * for taps and swipes. + * Take note that the {@link UiSelector} specified for this UiObjecy must be pointing + * directly at the element you wish to query for this attribute. * @return true if it is else false * @throws UiObjectNotFoundException */ @@ -545,11 +541,8 @@ public class UiObject { /** * Check if item pointed to by this object's selector can be checked and unchecked. <p/> - * Take note that the {@link By} selector specified for this UiObjecy must be pointing - * directly at the element you wish to query for this attribute as this UiObject may be - * using {@link By} selectors that may be pointing at a parent element of the element - * you're querying while still providing the desired functionality in terms of coordinates - * for taps and swipes. + * Take note that the {@link UiSelector} specified for this UiObjecy must be pointing + * directly at the element you wish to query for this attribute. * @return true if it is else false * @throws UiObjectNotFoundException */ @@ -562,13 +555,9 @@ public class UiObject { } /** - * Check if item pointed to by this object's selector with text is currently - * not grayed out. <p/> - * Take note that the {@link By} selector specified for this UiObjecy must be pointing - * directly at the element you wish to query for this attribute as this UiObject may be - * using {@link By} selectors that may be pointing at a parent element of the element - * you're querying while still providing the desired functionality in terms of coordinates - * for taps and swipes. + * Check if item pointed to by this object's selector is currently not grayed out. <p/> + * Take note that the {@link UiSelector} specified for this UiObjecy must be pointing + * directly at the element you wish to query for this attribute. * @return true if it is else false * @throws UiObjectNotFoundException */ @@ -581,13 +570,9 @@ public class UiObject { } /** - * Check if item pointed to by this object's selector with text responds to - * clicks <p/> - * Take note that the {@link By} selector specified for this UiObjecy must be pointing - * directly at the element you wish to query for this attribute as this UiObject may be - * using {@link By} selectors that may be pointing at a parent element of the element - * you're querying while still providing the desired functionality in terms of coordinates - * for taps and swipes. + * Check if item pointed to by this object's selector responds to clicks <p/> + * Take note that the {@link UiSelector} specified for this UiObjecy must be pointing + * directly at the element you wish to query for this attribute. * @return true if it is else false * @throws UiObjectNotFoundException */ @@ -600,8 +585,8 @@ public class UiObject { } /** - * Check if item pointed to by this object's selector with text is currently - * focused. Focused objects will receive key stroke events when key events + * Check if item pointed to by this object's selector is currently focused. + * Objects with focus will receive key stroke events when key events * are fired * @return true if it is else false * @throws UiObjectNotFoundException @@ -615,13 +600,9 @@ public class UiObject { } /** - * Check if item pointed to by this object's selector with text is capable of receiving - * focus. <p/> - * Take note that the {@link By} selector specified for this UiObjecy must be pointing - * directly at the element you wish to query for this attribute as this UiObject may be - * using {@link By} selectors that may be pointing at a parent element of the element - * you're querying while still providing the desired functionality in terms of coordinates - * for taps and swipes. + * Check if item pointed to by this object's selector is capable of receiving focus. <p/> + * Take note that the {@link UiSelector} selector specified for this UiObjecy must be pointing + * directly at the element you wish to query for this attribute. * @return true if it is else false * @throws UiObjectNotFoundException */ @@ -634,12 +615,9 @@ public class UiObject { } /** - * Check if item pointed to by this object's selector with text can be scrolled.<p/> - * Take note that the {@link By} selector specified for this UiObjecy must be pointing - * directly at the element you wish to query for this attribute as this UiObject may be - * using {@link By} selectors that may be pointing at a parent element of the element - * you're querying while still providing the desired functionality in terms of coordinates - * for taps and swipes. + * Check if item pointed to by this object's selector can be scrolled.<p/> + * Take note that the {@link UiSelector} selector specified for this UiObjecy must be pointing + * directly at the element you wish to query for this attribute. * @return true if it is else false * @throws UiObjectNotFoundException */ @@ -653,11 +631,8 @@ public class UiObject { /** * Check if item pointed to by this object's selector responds to long clicks.<p/> - * Take note that the {@link By} selector specified for this UiObjecy must be pointing - * directly at the element you wish to query for this attribute as this UiObject may be - * using {@link By} selectors that may be pointing at a parent element of the element - * you're querying while still providing the desired functionality in terms of coordinates - * for taps and swipes. + * Take note that the {@link UiSelector} selector specified for this UiObjecy must be pointing + * directly at the element you wish to query for this attribute. * @return true if it is else false * @throws UiObjectNotFoundException */ diff --git a/uiautomator/library/src/com/android/uiautomator/core/UiObjectNotFoundException.java b/uiautomator/library/src/com/android/uiautomator/core/UiObjectNotFoundException.java index 4610160..63ba549 100644 --- a/uiautomator/library/src/com/android/uiautomator/core/UiObjectNotFoundException.java +++ b/uiautomator/library/src/com/android/uiautomator/core/UiObjectNotFoundException.java @@ -17,7 +17,7 @@ package com.android.uiautomator.core; /** - * Generated in test runs when a {@link By} selector could not be matched + * Generated in test runs when a {@link UiSelector} selector could not be matched * to any UI element displayed. */ public class UiObjectNotFoundException extends Exception { diff --git a/uiautomator/library/src/com/android/uiautomator/core/UiScrollable.java b/uiautomator/library/src/com/android/uiautomator/core/UiScrollable.java index 7df4195..4022c5a 100644 --- a/uiautomator/library/src/com/android/uiautomator/core/UiScrollable.java +++ b/uiautomator/library/src/com/android/uiautomator/core/UiScrollable.java @@ -46,13 +46,13 @@ public class UiScrollable extends UiCollection { private double mSwipeDeadZonePercentage = DEFAULT_SWIPE_DEADZONE_PCT; /** - * UiScrollable is a {@link UiCollection} and as such requires a {@link By} selector to identify + * UiScrollable is a {@link UiCollection} and as such requires a {@link UiSelector} to identify * the UI element it represents. In the case of UiScrollable, the selector specified is * considered a container where further calls to enumerate or find children will be performed * in. - * @param container a {@link By} selector + * @param container a {@link UiSelector} selector */ - public UiScrollable(By container) { + public UiScrollable(UiSelector container) { // wrap the container selector with container so that QueryController can handle // this type of enumeration search accordingly super(container); @@ -78,7 +78,7 @@ public class UiScrollable extends UiCollection { * @param selector * @return true if found else false */ - protected boolean exists(By selector) { + protected boolean exists(UiSelector selector) { if(getQueryController().findAccessibilityNodeInfo(selector) != null) { return true; } @@ -86,42 +86,42 @@ public class UiScrollable extends UiCollection { } /** - * Searches for child UI element within the constraints of this UiScrollable {@link By} + * Searches for child UI element within the constraints of this UiScrollable {@link UiSelector} * selector. It looks for any child matching the <code>childPattern</code> argument that has * a child UI element anywhere within its sub hierarchy that has content-description text. * The returned UiObject will point at the <code>childPattern</code> instance that matched the * search and not at the identifying child element that matched the content description.</p> * By default this operation will perform scroll search while attempting to find the * UI element. - * See {@link #getChildByDescription(By, String, boolean)} - * @param childPattern {@link By} selector of the child pattern to match and return + * See {@link #getChildByDescription(UiSelector, String, boolean)} + * @param childPattern {@link UiSelector} selector of the child pattern to match and return * @param text String of the identifying child contents of of the <code>childPattern</code> * @return {@link UiObject} pointing at and instance of <code>childPattern</code> * @throws UiObjectNotFoundException */ @Override - public UiObject getChildByDescription(By childPattern, String text) + public UiObject getChildByDescription(UiSelector childPattern, String text) throws UiObjectNotFoundException { return getChildByDescription(childPattern, text, true); } /** - * Searches for child UI element within the constraints of this UiScrollable {@link By} + * Searches for child UI element within the constraints of this UiScrollable {@link UiSelector} * selector. It looks for any child matching the <code>childPattern</code> argument that has * a child UI element anywhere within its sub hierarchy that has content-description text. * The returned UiObject will point at the <code>childPattern</code> instance that matched the * search and not at the identifying child element that matched the content description. - * @param childPattern {@link By} selector of the child pattern to match and return + * @param childPattern {@link UiSelector} selector of the child pattern to match and return * @param text String may be a partial match for the content-description of a child element. * @param allowScrollSearch set to true if scrolling is allowed * @return {@link UiObject} pointing at and instance of <code>childPattern</code> * @throws UiObjectNotFoundException */ - public UiObject getChildByDescription(By childPattern, String text, boolean allowScrollSearch) - throws UiObjectNotFoundException { + public UiObject getChildByDescription(UiSelector childPattern, String text, + boolean allowScrollSearch) throws UiObjectNotFoundException { if (text != null) { if (allowScrollSearch) { - scrollIntoView(By.selector().descriptionContains(text)); + scrollIntoView(new UiSelector().descriptionContains(text)); } return super.getChildByDescription(childPattern, text); } @@ -129,24 +129,24 @@ public class UiScrollable extends UiCollection { } /** - * Searches for child UI element within the constraints of this UiScrollable {@link By} + * Searches for child UI element within the constraints of this UiScrollable {@link UiSelector} * selector. It looks for any child matching the <code>childPattern</code> argument and * return the <code>instance</code> specified. The operation is performed only on the visible * items and no scrolling is performed in this case. - * @param childPattern {@link By} selector of the child pattern to match and return + * @param childPattern {@link UiSelector} selector of the child pattern to match and return * @param instance int the desired matched instance of this <code>childPattern</code> * @return {@link UiObject} pointing at and instance of <code>childPattern</code> */ @Override - public UiObject getChildByInstance(By childPattern, int instance) + public UiObject getChildByInstance(UiSelector childPattern, int instance) throws UiObjectNotFoundException { - By patternSelector = By.patternBuilder(getSelector(), - By.patternBuilder(childPattern).instance(instance)); + UiSelector patternSelector = UiSelector.patternBuilder(getSelector(), + UiSelector.patternBuilder(childPattern).instance(instance)); return new UiObject(patternSelector); } /** - * Searches for child UI element within the constraints of this UiScrollable {@link By} + * Searches for child UI element within the constraints of this UiScrollable {@link UiSelector} * selector. It looks for any child matching the <code>childPattern</code> argument that has * a child UI element anywhere within its sub hierarchy that has text attribute = * <code>text</code>. The returned UiObject will point at the <code>childPattern</code> @@ -154,37 +154,37 @@ public class UiScrollable extends UiCollection { * text attribute.</p> * By default this operation will perform scroll search while attempting to find the UI * element. - * See {@link #getChildByText(By, String, boolean)} - * @param childPattern {@link By} selector of the child pattern to match and return + * See {@link #getChildByText(UiSelector, String, boolean)} + * @param childPattern {@link UiSelector} selector of the child pattern to match and return * @param text String of the identifying child contents of of the <code>childPattern</code> * @return {@link UiObject} pointing at and instance of <code>childPattern</code> * @throws UiObjectNotFoundException */ @Override - public UiObject getChildByText(By childPattern, String text) + public UiObject getChildByText(UiSelector childPattern, String text) throws UiObjectNotFoundException { return getChildByText(childPattern, text, true); } /** - * Searches for child UI element within the constraints of this UiScrollable {@link By} + * Searches for child UI element within the constraints of this UiScrollable {@link UiSelector} * selector. It looks for any child matching the <code>childPattern</code> argument that has * a child UI element anywhere within its sub hierarchy that has the text attribute = * <code>text</code>. * The returned UiObject will point at the <code>childPattern</code> instance that matched the * search and not at the identifying child element that matched the text attribute. - * @param childPattern {@link By} selector of the child pattern to match and return + * @param childPattern {@link UiSelector} selector of the child pattern to match and return * @param text String of the identifying child contents of of the <code>childPattern</code> * @param allowScrollSearch set to true if scrolling is allowed * @return {@link UiObject} pointing at and instance of <code>childPattern</code> * @throws UiObjectNotFoundException */ - public UiObject getChildByText(By childPattern, String text, boolean allowScrollSearch) + public UiObject getChildByText(UiSelector childPattern, String text, boolean allowScrollSearch) throws UiObjectNotFoundException { if (text != null) { if (allowScrollSearch) { - scrollIntoView(By.selector().text(text)); + scrollIntoView(new UiSelector().text(text)); } return super.getChildByText(childPattern, text); } @@ -198,16 +198,16 @@ public class UiScrollable extends UiCollection { * @return true if item us found else false */ public boolean scrollDescriptionIntoView(String text) { - return scrollIntoView(By.selector().description(text)); + return scrollIntoView(new UiSelector().description(text)); } /** - * Perform a scroll search for a UI element matching the {@link By} selector argument. Also - * see {@link #scrollDescriptionIntoView(String)} and {@link #scrollTextIntoView(String)}. - * @param selector {@link By} selector + * Perform a scroll search for a UI element matching the {@link UiSelector} selector argument. + * Also see {@link #scrollDescriptionIntoView(String)} and {@link #scrollTextIntoView(String)}. + * @param selector {@link UiSelector} selector * @return true if the item was found and now is in view else false */ - public boolean scrollIntoView(By selector) { + public boolean scrollIntoView(UiSelector selector) { // if we happen to be on top of the text we want then return here if (exists(getSelector().childSelector(selector))) { return (true); @@ -237,7 +237,7 @@ public class UiScrollable extends UiCollection { * @return true if item us found else false */ public boolean scrollTextIntoView(String text) { - return scrollIntoView(By.selector().text(text)); + return scrollIntoView(new UiSelector().text(text)); } /** diff --git a/uiautomator/library/src/com/android/uiautomator/core/By.java b/uiautomator/library/src/com/android/uiautomator/core/UiSelector.java index 51a8936..28df320 100644 --- a/uiautomator/library/src/com/android/uiautomator/core/By.java +++ b/uiautomator/library/src/com/android/uiautomator/core/UiSelector.java @@ -25,12 +25,10 @@ import android.view.accessibility.AccessibilityNodeInfo; * text values, a content-description field, class name and multiple state * information like isSelected, isEnabled or isChecked. Additionally a UI element * may also be associated with a specific layout hierarchy that the test wishes - * to use to unambiguously target one UI element separated from other similar ones. - * <p/> This class will allow tests to create the instructions necessary for the - * the {@link UiObject} and {@link UiScrollable} classes to uses to target the UI - * element for the purposes of verifications, interactions or enumerations. + * to use to unambiguously target one UI element distinguishing it from other + * similar elements. */ -public class By { +public class UiSelector { static final int SELECTOR_NIL = 0; static final int SELECTOR_TEXT = 1; static final int SELECTOR_START_TEXT = 2; @@ -59,144 +57,112 @@ public class By { private SparseArray<Object> mSelectorAttributes = new SparseArray<Object>(); public static final String LOG_TAG = "ByClass"; - private By() { + public UiSelector() { } - private By(By by) { + protected UiSelector(UiSelector by) { mSelectorAttributes = by.cloneSelectors().mSelectorAttributes; } - protected By cloneSelectors() { - By ret = By.selector(); - - // shallow copy the attributes + protected UiSelector cloneSelectors() { + UiSelector ret = new UiSelector(); ret.mSelectorAttributes = mSelectorAttributes.clone(); - - // deep copy attributes that contain sub selectors - By by = getChildSelector(); - if(by != null) { - mSelectorAttributes.put(By.SELECTOR_CHILD, by.cloneSelectors()); - } - - by = getContainerSelector(); - if(by != null) { - mSelectorAttributes.put(By.SELECTOR_CONTAINER, by.cloneSelectors()); - } - - by = getPatternSelector(); - if(by != null) { - mSelectorAttributes.put(By.SELECTOR_PATTERN, by.cloneSelectors()); - } - - by = getParentSelector(); - if(by != null) { - mSelectorAttributes.put(By.SELECTOR_PARENT, by.cloneSelectors()); - } - return ret; } - public static By selector() { - return new By(); - } - - static By selector(By selector) { - return new By(selector); - } - - static By patternBuilder(By selector) { + static UiSelector patternBuilder(UiSelector selector) { if(!selector.hasPatternSelector()) { - return By.selector().patternSelector(selector); + return new UiSelector().patternSelector(selector); } return selector; } - static By patternBuilder(By container, By pattern) { - return By.selector(By.selector().containerSelector(container).patternSelector(pattern)); + static UiSelector patternBuilder(UiSelector container, UiSelector pattern) { + return new UiSelector( + new UiSelector().containerSelector(container).patternSelector(pattern)); } - - public By text(String text) { + public UiSelector text(String text) { return buildSelector(SELECTOR_TEXT, text); } - public By textStartsWith(String text) { + public UiSelector textStartsWith(String text) { return buildSelector(SELECTOR_START_TEXT, text); } - public By textContains(String text) { + public UiSelector textContains(String text) { return buildSelector(SELECTOR_CONTAINS_TEXT, text); } - public By className(String className) { + public UiSelector className(String className) { return buildSelector(SELECTOR_CLASS, className); } - public By description(String desc) { + public UiSelector description(String desc) { return buildSelector(SELECTOR_DESCRIPTION, desc); } - public By descriptionStartsWith(String desc) { + public UiSelector descriptionStartsWith(String desc) { return buildSelector(SELECTOR_START_DESCRIPTION, desc); } - public By descriptionContains(String desc) { + public UiSelector descriptionContains(String desc) { return buildSelector(SELECTOR_CONTAINS_DESCRIPTION, desc); } - public By index(final int index) { + public UiSelector index(final int index) { return buildSelector(SELECTOR_INDEX, index); } - public By instance(final int instance) { + public UiSelector instance(final int instance) { return buildSelector(SELECTOR_INSTANCE, instance); } - public By enabled(boolean val) { + public UiSelector enabled(boolean val) { return buildSelector(SELECTOR_ENABLED, val); } - public By focused(boolean val) { + public UiSelector focused(boolean val) { return buildSelector(SELECTOR_FOCUSED, val); } - public By focusable(boolean val) { + public UiSelector focusable(boolean val) { return buildSelector(SELECTOR_FOCUSABLE, val); } - public By scrollable(boolean val) { + public UiSelector scrollable(boolean val) { return buildSelector(SELECTOR_SCROLLABLE, val); } - public By selected(boolean val) { + public UiSelector selected(boolean val) { return buildSelector(SELECTOR_SELECTED, val); } - public By checked(boolean val) { + public UiSelector checked(boolean val) { return buildSelector(SELECTOR_CHECKED, val); } - public By clickable(boolean val) { + public UiSelector clickable(boolean val) { return buildSelector(SELECTOR_CLICKABLE, val); } - public By childSelector(By by) { + public UiSelector childSelector(UiSelector by) { return buildSelector(SELECTOR_CHILD, by); } - private By patternSelector(By by) { + private UiSelector patternSelector(UiSelector by) { return buildSelector(SELECTOR_PATTERN, by); } - private By containerSelector(By by) { + private UiSelector containerSelector(UiSelector by) { return buildSelector(SELECTOR_CONTAINER, by); } - public By fromParent(By by) { + public UiSelector fromParent(UiSelector by) { return buildSelector(SELECTOR_PARENT, by); } - public By packageName(String name) { + public UiSelector packageName(String name) { return buildSelector(SELECTOR_PACKAGE_NAME, name); } @@ -208,8 +174,8 @@ public class By { * state of SB which is expected to be something else. For this we will return a new * By selector every time. */ - private By buildSelector(int selectorId, Object selectorValue) { - By by = By.selector(this); + private UiSelector buildSelector(int selectorId, Object selectorValue) { + UiSelector by = new UiSelector(this); if(selectorId == SELECTOR_CHILD || selectorId == SELECTOR_PARENT) by.getLastSubSelector().mSelectorAttributes.put(selectorId, selectorValue); else @@ -226,36 +192,36 @@ public class By { * reference child node. */ - By getChildSelector() { - By by = (By)mSelectorAttributes.get(By.SELECTOR_CHILD, null); + UiSelector getChildSelector() { + UiSelector by = (UiSelector)mSelectorAttributes.get(UiSelector.SELECTOR_CHILD, null); if(by != null) - return By.selector(by); + return new UiSelector(by); return null; } - By getPatternSelector() { - By by = (By)mSelectorAttributes.get(By.SELECTOR_PATTERN, null); + UiSelector getPatternSelector() { + UiSelector by = (UiSelector)mSelectorAttributes.get(UiSelector.SELECTOR_PATTERN, null); if(by != null) - return By.selector(by); + return new UiSelector(by); return null; } - By getContainerSelector() { - By by = (By)mSelectorAttributes.get(By.SELECTOR_CONTAINER, null); + UiSelector getContainerSelector() { + UiSelector by = (UiSelector)mSelectorAttributes.get(UiSelector.SELECTOR_CONTAINER, null); if(by != null) - return By.selector(by); + return new UiSelector(by); return null; } - By getParentSelector() { - By by = (By) mSelectorAttributes.get(By.SELECTOR_PARENT, null); + UiSelector getParentSelector() { + UiSelector by = (UiSelector) mSelectorAttributes.get(UiSelector.SELECTOR_PARENT, null); if(by != null) - return By.selector(by); + return new UiSelector(by); return null; } int getInstance() { - return getInt(By.SELECTOR_INSTANCE); + return getInt(UiSelector.SELECTOR_INSTANCE); } String getString(int criterion) { @@ -276,95 +242,95 @@ public class By { CharSequence s = null; int criterion = mSelectorAttributes.keyAt(x); switch(criterion) { - case By.SELECTOR_INDEX: + case UiSelector.SELECTOR_INDEX: if(index != this.getInt(criterion)) return false; break; - case By.SELECTOR_CHECKED: + case UiSelector.SELECTOR_CHECKED: if (node.isChecked() != getBoolean(criterion)) { return false; } break; - case By.SELECTOR_CLASS: + case UiSelector.SELECTOR_CLASS: s = node.getClassName(); if (s == null || !s.toString().contentEquals(getString(criterion))) { return false; } break; - case By.SELECTOR_CLICKABLE: + case UiSelector.SELECTOR_CLICKABLE: if (node.isClickable() != getBoolean(criterion)) { return false; } break; - case By.SELECTOR_CONTAINS_DESCRIPTION: + case UiSelector.SELECTOR_CONTAINS_DESCRIPTION: s = node.getContentDescription(); if(s == null || !s.toString().toLowerCase() .contains(getString(criterion).toLowerCase())) { return false; } break; - case By.SELECTOR_START_DESCRIPTION: + case UiSelector.SELECTOR_START_DESCRIPTION: s = node.getContentDescription(); if(s == null || !s.toString().toLowerCase() .startsWith(getString(criterion).toLowerCase())) { return false; } break; - case By.SELECTOR_DESCRIPTION: + case UiSelector.SELECTOR_DESCRIPTION: s = node.getContentDescription(); if(s == null || !s.toString().contentEquals(getString(criterion))) { return false; } break; - case By.SELECTOR_CONTAINS_TEXT: + case UiSelector.SELECTOR_CONTAINS_TEXT: s = node.getText(); if(s == null || !s.toString().toLowerCase() .contains(getString(criterion).toLowerCase())) { return false; } break; - case By.SELECTOR_START_TEXT: + case UiSelector.SELECTOR_START_TEXT: s = node.getText(); if(s == null || !s.toString().toLowerCase() .startsWith(getString(criterion).toLowerCase())) { return false; } break; - case By.SELECTOR_TEXT: + case UiSelector.SELECTOR_TEXT: s = node.getText(); if(s == null || !s.toString().contentEquals(getString(criterion))) { return false; } break; - case By.SELECTOR_ENABLED: + case UiSelector.SELECTOR_ENABLED: if(node.isEnabled() != getBoolean(criterion)) { return false; } break; - case By.SELECTOR_FOCUSABLE: + case UiSelector.SELECTOR_FOCUSABLE: if(node.isFocusable() != getBoolean(criterion)) { return false; } break; - case By.SELECTOR_FOCUSED: + case UiSelector.SELECTOR_FOCUSED: if(node.isFocused() != getBoolean(criterion)) { return false; } break; - case By.SELECTOR_ID: + case UiSelector.SELECTOR_ID: break; //TODO: do we need this for AccessibilityNodeInfo.id? - case By.SELECTOR_PACKAGE_NAME: + case UiSelector.SELECTOR_PACKAGE_NAME: s = node.getPackageName(); if(s == null || !s.toString().contentEquals(getString(criterion))) { return false; } break; - case By.SELECTOR_SCROLLABLE: + case UiSelector.SELECTOR_SCROLLABLE: if(node.isScrollable() != getBoolean(criterion)) { return false; } break; - case By.SELECTOR_SELECTED: + case UiSelector.SELECTOR_SELECTED: if(node.isSelected() != getBoolean(criterion)) { return false; } @@ -379,13 +345,14 @@ public class By { int currentSelectorInstance = 0; // matched attributes - now check for matching instance number - if(mSelectorAttributes.indexOfKey(By.SELECTOR_INSTANCE) > 0) { - currentSelectorInstance = (Integer)mSelectorAttributes.get(By.SELECTOR_INSTANCE); + if(mSelectorAttributes.indexOfKey(UiSelector.SELECTOR_INSTANCE) > 0) { + currentSelectorInstance = + (Integer)mSelectorAttributes.get(UiSelector.SELECTOR_INSTANCE); } // instance is required. Add count if not already counting - if(mSelectorAttributes.indexOfKey(By.SELECTOR_COUNT) > 0) { - currentSelectorCounter = (Integer)mSelectorAttributes.get(By.SELECTOR_COUNT); + if(mSelectorAttributes.indexOfKey(UiSelector.SELECTOR_COUNT) > 0) { + currentSelectorCounter = (Integer)mSelectorAttributes.get(UiSelector.SELECTOR_COUNT); } // Verify @@ -394,7 +361,7 @@ public class By { } // Update count if (currentSelectorInstance > currentSelectorCounter) { - mSelectorAttributes.put(By.SELECTOR_COUNT, ++currentSelectorCounter); + mSelectorAttributes.put(UiSelector.SELECTOR_COUNT, ++currentSelectorCounter); } return false; } @@ -405,36 +372,36 @@ public class By { * @return true if is leaf. */ boolean isLeaf() { - if(mSelectorAttributes.indexOfKey(By.SELECTOR_CHILD) < 0 && - mSelectorAttributes.indexOfKey(By.SELECTOR_PARENT) < 0) { + if(mSelectorAttributes.indexOfKey(UiSelector.SELECTOR_CHILD) < 0 && + mSelectorAttributes.indexOfKey(UiSelector.SELECTOR_PARENT) < 0) { return true; } return false; } boolean hasChildSelector() { - if(mSelectorAttributes.indexOfKey(By.SELECTOR_CHILD) < 0) { + if(mSelectorAttributes.indexOfKey(UiSelector.SELECTOR_CHILD) < 0) { return false; } return true; } boolean hasPatternSelector() { - if(mSelectorAttributes.indexOfKey(By.SELECTOR_PATTERN) < 0) { + if(mSelectorAttributes.indexOfKey(UiSelector.SELECTOR_PATTERN) < 0) { return false; } return true; } boolean hasContainerSelector() { - if(mSelectorAttributes.indexOfKey(By.SELECTOR_CONTAINER) < 0) { + if(mSelectorAttributes.indexOfKey(UiSelector.SELECTOR_CONTAINER) < 0) { return false; } return true; } boolean hasParentSelector() { - if(mSelectorAttributes.indexOfKey(By.SELECTOR_PARENT) < 0) { + if(mSelectorAttributes.indexOfKey(UiSelector.SELECTOR_PARENT) < 0) { return false; } return true; @@ -442,20 +409,20 @@ public class By { /** * Returns the deepest selector in the chain of possible sub selectors. - * A chain of selector is created when either of {@link By#childSelector(By)} - * or {@link By#fromParent(By)} are used once or more in the construction of + * A chain of selector is created when either of {@link UiSelector#childSelector(UiSelector)} + * or {@link UiSelector#fromParent(UiSelector)} are used once or more in the construction of * a selector. * @return last By selector in chain */ - private By getLastSubSelector() { - if(mSelectorAttributes.indexOfKey(By.SELECTOR_CHILD) >= 0) { - By child = (By)mSelectorAttributes.get(By.SELECTOR_CHILD); + private UiSelector getLastSubSelector() { + if(mSelectorAttributes.indexOfKey(UiSelector.SELECTOR_CHILD) >= 0) { + UiSelector child = (UiSelector)mSelectorAttributes.get(UiSelector.SELECTOR_CHILD); if(child.getLastSubSelector() == null) { return child; } return child.getLastSubSelector(); - } else if(mSelectorAttributes.indexOfKey(By.SELECTOR_PARENT) >= 0) { - By parent = (By)mSelectorAttributes.get(By.SELECTOR_PARENT); + } else if(mSelectorAttributes.indexOfKey(UiSelector.SELECTOR_PARENT) >= 0) { + UiSelector parent = (UiSelector)mSelectorAttributes.get(UiSelector.SELECTOR_PARENT); if(parent.getLastSubSelector() == null) { return parent; } |