-
-
Notifications
You must be signed in to change notification settings - Fork 237
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
Return empty string if null #212
Conversation
This was actually a deliberate change in #208 to distinguish cases where text attribute is not present and where it equals to an empty string. This result should be consistent in all places: xml tree, xpath search, getAttribute output |
I guess that's why the tests just started failing. |
@imurchie does the standard define some rules on the |
appium-uiautomator2-server/app/src/main/java/io/appium/uiautomator2/utils/ElementHelpers.java Line 225 in cc9b767
appium-uiautomator2-server/app/src/main/java/io/appium/uiautomator2/utils/ElementHelpers.java Line 238 in cc9b767
These are the places to patch in order to make getText output consistent |
@@ -45,7 +45,8 @@ public SendKeysToElement(String mappedUri) { | |||
} | |||
|
|||
private static boolean isTextFieldClear(AndroidElement element) throws UiObjectNotFoundException { | |||
return element.getText() == null || element.getText().isEmpty(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually the previous one was also fine ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, just two calls to element.getText()
.
Unfortunately, this breaks finding element by androidUiAutomator. Alas. |
@imurchie I don't see any connection between this change and lookup by androidUiAutomator %/ |
We could patch getAttribute calls for UiObject2Element/UiObjectElement plus replace |
Me neither. :( But as far as I can tell right now, the right object is found, but reports as non-existent at https://github.com/appium/appium-uiautomator2-server/blob/master/app/src/main/java/io/appium/uiautomator2/model/internal/CustomUiDevice.java#L124 |
@imurchie I believe it was something else that caused this test to fail, because I observe the same error in https://travis-ci.org/appium/appium-uiautomator2-server/builds/448241629?utm_source=github_status&utm_medium=notification, however it does not contain this fix. How about merging this PR as is and then we try to address the uia location issue in the other one? |
@imurchie I assume this PR should be fine if you rebase it with master |
c1f93dd
to
720d0a4
Compare
@@ -44,7 +44,9 @@ public UiSelector getUiSelector(AccessibilityNodeInfo node) { | |||
} | |||
put(Attribute.PACKAGE, charSequenceToString(uiAutomationElement.getPackageName())); | |||
put(Attribute.CLASS, charSequenceToString(uiAutomationElement.getClassName())); | |||
put(Attribute.TEXT, charSequenceToString(uiAutomationElement.getText())); | |||
// the element will give empty strings as "" but for searching we need null | |||
String text = charSequenceToString(uiAutomationElement.getText()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is too hacky and not very reliable as for my taste. Can we then patch the stuff in GetAttribute and GetText instead and leave getText
inside ElementHelpers in their previous state (return null)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or probably have a separate getText endpoint for uiAutomationElement, which does not replace null and call it here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
like getNullableText and a "normal" getText
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure.
@Nullable | ||
public String getNullableText() { | ||
String text = getText(); | ||
return (text != null && text.isEmpty()) ? null : text; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better, but still not ideal. I would prefer to have a special argument for ElementHelper methods, which defines whether null should be replaced or not, so we don't need to perform "double transformation"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel free to open a PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure will do. Thanks for the hint
Superseeded by #218 |
In certain circumstances (such as Java 1.7, Android-21 in our
appium-uiautomator2-driver
Travis build (see https://travis-ci.org/appium/appium-uiautomator2-driver/jobs/447774226#L3630-L3637)) the framework returnsnull
, and we pass that back, leading to failures where""
is expected.