Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add more fields from AccessibilityNodeInfo #682

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package io.appium.uiautomator2.model;

import android.os.Build;
import android.text.TextUtils;
mykola-mokhnach marked this conversation as resolved.
Show resolved Hide resolved
import android.util.Pair;
import android.view.accessibility.AccessibilityNodeInfo;
import android.widget.Toast;
Expand Down Expand Up @@ -58,10 +59,15 @@ public class UiElementSnapshot extends UiElement<AccessibilityNodeInfo, UiElemen
Attribute.FOCUSABLE, Attribute.FOCUSED, Attribute.LONG_CLICKABLE,
Attribute.PASSWORD, Attribute.SCROLLABLE, Attribute.SELECTION_START,
Attribute.SELECTION_END, Attribute.SELECTED, Attribute.BOUNDS, Attribute.DISPLAYED,
Attribute.HINT, Attribute.EXTRAS
Attribute.HINT, Attribute.EXTRAS, Attribute.IMPORTANT_FOR_ACCESSIBILITY,
Attribute.SCREEN_READER_FOCUSABLE, Attribute.INPUT_TYPE, Attribute.DRAWING_ORDER,
Attribute.SHOWING_HINT_TEXT, Attribute.TEXT_ENTRY_KEY, Attribute.MULTI_LINE,
Attribute.DISMISSABLE, Attribute.ACCESSIBILITY_FOCUSED, Attribute.HEADING,
Attribute.LIVE_REGION, Attribute.CONTEXT_CLICKABLE, Attribute.MAX_TEXT_LENGTH,
Attribute.CONTENT_INVALID, Attribute.ERROR_TEXT, Attribute.PANE_TITLE, Attribute.ACTIONS
// Skip CONTENT_SIZE as it is quite expensive to compute it for each element
};
private final static Attribute[] TOAST_NODE_ATTRIBUTES = new Attribute[] {
private final static Attribute[] TOAST_NODE_ATTRIBUTES = new Attribute[]{
Attribute.TEXT, Attribute.CLASS, Attribute.PACKAGE, Attribute.DISPLAYED,
Attribute.INDEX
};
Expand Down Expand Up @@ -158,11 +164,49 @@ private static void putAttribute(Map<Attribute, Object> attribs, Attribute key,
case TEXT:
return AxNodeInfoHelper.getText(node, true);
case HINT:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
return node.getHintText();
} else {
return null;
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ? node.getHintText() : null;
case IMPORTANT_FOR_ACCESSIBILITY:
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.N ? node.isImportantForAccessibility() : null;
mykola-mokhnach marked this conversation as resolved.
Show resolved Hide resolved
case SCREEN_READER_FOCUSABLE:
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.P ? node.isScreenReaderFocusable() : null;
case INPUT_TYPE:
return node.getInputType() != 0 ? node.getInputType() : null;
case DRAWING_ORDER:
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.N ? node.getDrawingOrder() : null;
case SHOWING_HINT_TEXT:
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ? node.isShowingHintText() : null;
case ACTIONS:
StringBuilder actionsBuilder = new StringBuilder();
mykola-mokhnach marked this conversation as resolved.
Show resolved Hide resolved
mykola-mokhnach marked this conversation as resolved.
Show resolved Hide resolved
List<AccessibilityNodeInfo.AccessibilityAction> actionList = node.getActionList();
for (AccessibilityNodeInfo.AccessibilityAction action : actionList) {
actionsBuilder.append(action.toString().split(" ")[1]);
mykola-mokhnach marked this conversation as resolved.
Show resolved Hide resolved
actionsBuilder.append(",");
}
if(actionsBuilder.length() > 0)
mykola-mokhnach marked this conversation as resolved.
Show resolved Hide resolved
actionsBuilder.deleteCharAt(actionsBuilder.length()-1);
mykola-mokhnach marked this conversation as resolved.
Show resolved Hide resolved
return actionsBuilder.toString();
case TEXT_ENTRY_KEY:
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q ? node.isTextEntryKey() : null;
case MULTI_LINE:
return node.getMaxTextLength() != -1 ? node.isMultiLine() : null;
case DISMISSABLE:
return node.isDismissable();
case ACCESSIBILITY_FOCUSED:
return node.isAccessibilityFocused();
case HEADING:
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.P ? node.isHeading() : null;
case LIVE_REGION:
return node.getLiveRegion();
case CONTEXT_CLICKABLE:
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? node.isContextClickable() : null;
case MAX_TEXT_LENGTH:
return node.getMaxTextLength() != -1 ? node.getMaxTextLength() : null;
case CONTENT_INVALID:
return node.isContentInvalid();
case ERROR_TEXT:
return charSequenceToNullableString(node.getError());
case PANE_TITLE:
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.P ? charSequenceToNullableString(node.getPaneTitle()) : null;
case EXTRAS:
return BaseElement.getExtrasAsString(node);
case ORIGINAL_TEXT:
Expand Down
21 changes: 20 additions & 1 deletion app/src/main/java/io/appium/uiautomator2/utils/Attribute.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,32 @@ public enum Attribute {
TEXT(new String[]{"text", "name"}),
HINT(new String[]{"hint"}),
EXTRAS(new String[]{"extras"}),

mykola-mokhnach marked this conversation as resolved.
Show resolved Hide resolved
// The main difference of this attribute from the preceding one is that
// it does not replace null values with empty strings
ORIGINAL_TEXT(new String[]{"original-text"}, false, false),
BOUNDS(new String[]{"bounds"}),
INDEX(new String[]{"index"}, false, true),
DISPLAYED(new String[]{"displayed"}),
CONTENT_SIZE(new String[]{"contentSize"}, true, false);
CONTENT_SIZE(new String[]{"contentSize"}, true, false),

IMPORTANT_FOR_ACCESSIBILITY(new String[]{"a11y-important", "importantForAccessibility"}),
SCREEN_READER_FOCUSABLE(new String[]{"screenReaderFocusable"}),
mykola-mokhnach marked this conversation as resolved.
Show resolved Hide resolved
INPUT_TYPE(new String[]{"input-type", "inputType"}),
DRAWING_ORDER(new String[]{"drawing-order", "drawingOrder"}),
SHOWING_HINT_TEXT(new String[]{"showing-hint", "showingHintText"}),
TEXT_ENTRY_KEY(new String[]{"text-entry-key", "textEntryKey"}),
MULTI_LINE(new String[]{"multiline", "multiLine"}),
DISMISSABLE(new String[]{"dismissable"}),
ACCESSIBILITY_FOCUSED(new String[]{"a11y-focused", "accessibilityFocused"}),
HEADING(new String[]{"heading"}),
LIVE_REGION(new String[]{"live-region", "liveRegion"}),
CONTEXT_CLICKABLE(new String[]{"context-clickable", "contextClickable"}),
MAX_TEXT_LENGTH(new String[]{"max-text-length", "maxTextLength"}),
CONTENT_INVALID(new String[]{"content-invalid", "contentInvalid"}),
ERROR_TEXT(new String[]{"error", "errorText"}),
PANE_TITLE(new String[]{"pane-title", "paneTitle"}),
ACTIONS(new String[]{"actions"});
mykola-mokhnach marked this conversation as resolved.
Show resolved Hide resolved

private final String[] aliases;
// Defines if the attribute is visible to the user from getAttribute call
Expand Down
Loading