Skip to content

Commit

Permalink
#573 - Method $.shouldHave(exactValue(" foo ")) does NOT trim leadi…
Browse files Browse the repository at this point in the history
…ng/trailing spaces anymore
  • Loading branch information
asolntsev committed Aug 7, 2017
1 parent 22aaecb commit 5b8a60e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Expand Up @@ -4,6 +4,7 @@
* #529 Cannot find capabilities with browserName=ie when grid hub url specified in -Dremote -- thanks to @BorisOsipov
* #551 Method `$.setValue()` should not fail if it could not trigger change event (for whatever reason).
* #528 - Wrong ElementNotFound exception message -- thanks to @BorisOsipov
* #573 - Method `$.shouldHave(exactValue(" foo "))` does NOT trim leading/trailing spaces anymore - thanks to @mseele for this PR

=== 4.5.1 (released 27.06.2017)
* #484 added method $.getSearchCriteria()
Expand Down
14 changes: 5 additions & 9 deletions src/main/java/com/codeborne/selenide/Condition.java
Expand Up @@ -150,14 +150,10 @@ public String toString() {
* @param expectedAttributeValue expected value of attribute
*/
public static Condition attribute(final String attributeName, final String expectedAttributeValue) {
return attribute(attributeName, expectedAttributeValue, true);
}

private static Condition attribute(final String attributeName, final String expectedAttributeValue, final boolean trim) {
return new Condition("attribute") {
@Override
public boolean apply(WebElement element) {
return expectedAttributeValue.equals(getAttributeValue(element, attributeName, trim));
return expectedAttributeValue.equals(getAttributeValue(element, attributeName));
}
@Override
public String toString() {
Expand All @@ -166,9 +162,9 @@ public String toString() {
};
}

private static String getAttributeValue(WebElement element, String attributeName, boolean trim) {
private static String getAttributeValue(WebElement element, String attributeName) {
String attr = element.getAttribute(attributeName);
return attr == null ? "" : (trim ? attr.trim() : attr);
return attr == null ? "" : attr;
}

/**
Expand All @@ -183,7 +179,7 @@ public static Condition value(final String expectedValue) {
return new Condition("value") {
@Override
public boolean apply(WebElement element) {
return Html.text.contains(getAttributeValue(element, "value", true), expectedValue);
return Html.text.contains(getAttributeValue(element, "value"), expectedValue);
}
@Override
public String toString() {
Expand All @@ -197,7 +193,7 @@ public String toString() {
* @param value expected value of input field
*/
public static Condition exactValue(String value) {
return attribute("value", value, false);
return attribute("value", value);
}

/**
Expand Down

0 comments on commit 5b8a60e

Please sign in to comment.