From 6d87ed8de001ee9a1e68d7d149e530c22a7f1978 Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Tue, 14 Nov 2017 19:17:02 +0100 Subject: [PATCH] Add 'password' attribute to attributes list (#51) * Add 'password attribute to attributes list' * Tune formatting --- .gitignore | 1 + .../android/bootstrap/AndroidElement.java | 57 ++++++++++--------- 2 files changed, 32 insertions(+), 26 deletions(-) diff --git a/.gitignore b/.gitignore index 7cf6d1e..d91bebd 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ bootstrap/.classpath bootstrap/target/ node_modules *.log +*.iml diff --git a/bootstrap/src/io/appium/android/bootstrap/AndroidElement.java b/bootstrap/src/io/appium/android/bootstrap/AndroidElement.java index fd6f4c2..30d6094 100644 --- a/bootstrap/src/io/appium/android/bootstrap/AndroidElement.java +++ b/bootstrap/src/io/appium/android/bootstrap/AndroidElement.java @@ -93,31 +93,35 @@ public Point getAbsolutePosition(final Point point) public boolean getBoolAttribute(final String attr) throws UiObjectNotFoundException, NoAttributeFoundException { - boolean res; - if (attr.equals("enabled")) { - res = el.isEnabled(); - } else if (attr.equals("checkable")) { - res = el.isCheckable(); - } else if (attr.equals("checked")) { - res = el.isChecked(); - } else if (attr.equals("clickable")) { - res = el.isClickable(); - } else if (attr.equals("focusable")) { - res = el.isFocusable(); - } else if (attr.equals("focused")) { - res = el.isFocused(); - } else if (attr.equals("longClickable")) { - res = el.isLongClickable(); - } else if (attr.equals("scrollable")) { - res = el.isScrollable(); - } else if (attr.equals("selected")) { - res = el.isSelected(); - } else if (attr.equals("displayed")) { - res = el.exists(); - } else { - throw new NoAttributeFoundException(attr); + switch (attr) { + case "enabled": + return el.isEnabled(); + case "checkable": + return el.isCheckable(); + case "checked": + return el.isChecked(); + case "clickable": + return el.isClickable(); + case "focusable": + return el.isFocusable(); + case "focused": + return el.isFocused(); + case "longClickable": + return el.isLongClickable(); + case "scrollable": + return el.isScrollable(); + case "selected": + return el.isSelected(); + case "displayed": + return el.exists(); + case "password": + AccessibilityNodeInfo node = (AccessibilityNodeInfo) invoke( + method(el.getClass(), "findAccessibilityNodeInfo", long.class), + el, Configurator.getInstance().getWaitForSelectorTimeout()); + return node.isPassword(); + default: + throw new NoAttributeFoundException(attr); } - return res; } public Rect getBounds() throws UiObjectNotFoundException { @@ -151,12 +155,13 @@ public String getResourceId() throws UiObjectNotFoundException { * Unfortunately UiObject does not implement a getResourceId method. * There is currently no way to determine the resource-id of a given * element represented by UiObject. Until this support is added to - * UiAutomater, we try to match the implementation pattern that is + * UiAutomator, we try to match the implementation pattern that is * already used by UiObject for getting attributes using reflection. * The returned string matches exactly what is displayed in the * UiAutomater inspector. */ - AccessibilityNodeInfo node = (AccessibilityNodeInfo) invoke( method(el.getClass(), "findAccessibilityNodeInfo", long.class), + AccessibilityNodeInfo node = (AccessibilityNodeInfo) invoke( + method(el.getClass(), "findAccessibilityNodeInfo", long.class), el, Configurator.getInstance().getWaitForSelectorTimeout()); if (node == null) {