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

chore: Be smarter about setting the text #329

Merged
merged 1 commit into from
Jan 30, 2020
Merged
Changes from all 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 @@ -71,31 +71,29 @@ protected AppiumResponse safeHandle(IHttpRequest request) throws JSONException,
Logger.debug("Will press Enter after setting text");
}

String currentText = element.getText();
if (!StringUtils.isEmpty(currentText)) {
element.clear();
}
if (!StringUtils.isEmpty(element.getText())) {
// clear could have failed, or we could have a hint in the field
// we'll assume it is the latter
Logger.debug("Could not clear the text. Assuming the remainder is a hint text.");
currentText = "";
}
if (!replace && currentText != null) {
text = currentText + text;
if (!replace) {
String currentText = element.getText();
if (!StringUtils.isEmpty(currentText)) {
element.clear();
if (!StringUtils.isEmpty(element.getText())) {
// clear could have failed, or we could have a hint in the field
// we'll assume it is the latter
Logger.debug("Could not clear the text. Assuming the remainder is a hint text.");
currentText = "";
}
text = currentText + text;
}
}
if (!element.setText(text)) {
throw new InvalidElementStateException(String.format("Cannot set the element to '%s'. " +
"Did you interact with the correct element?", text));
}

String actionMsg = "";
if (pressEnter) {
actionMsg = getUiDevice().pressEnter()
Logger.debug(getUiDevice().pressEnter()
? "Sent Enter key to the device"
: "Could not send Enter key to the device";
: "Could not send Enter key to the device");
}
Logger.debug(actionMsg);
return new AppiumResponse(getSessionId(request));
}
}
Expand Down