Skip to content
This repository was archived by the owner on Feb 2, 2025. It is now read-only.

Commit 9844ad4

Browse files
authored
Merge pull request #91 from YauheniPo/feature/waitAttributeContainsValue
Feature/wait attribute contains value
2 parents fed6f0e + 87477a2 commit 9844ad4

File tree

5 files changed

+42
-14
lines changed

5 files changed

+42
-14
lines changed

src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/Element.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,17 @@ public String getElementAttribute(String locator) {
426426
return getElementAttribute(parts[0], parts[1]);
427427
}
428428

429+
@RobotKeyword("Get the value of a given CSS property.")
430+
@ArgumentNames({ "attribute", "locator" })
431+
public String getCssValue(final String attribute, final String locator) {
432+
List<WebElement> elements = elementFind(locator, true, false);
433+
434+
if (elements.size() == 0) {
435+
throw new SeleniumLibraryNonFatalException(String.format("Element '%s' not found.", locator));
436+
}
437+
return elements.get(0).getCssValue(attribute);
438+
}
439+
429440
@RobotKeyword("Returns value of attribute from element locator.\r\n" +
430441
"\r\n" +
431442
"See the `Locating elements` section for details about the locator syntax.\r\n" +
@@ -988,11 +999,7 @@ protected boolean isEnabled(String locator) {
988999
return false;
9891000
}
9901001
String readonly = element.getAttribute("readonly");
991-
if (readonly != null && (readonly.equals("readonly") || readonly.equals("true"))) {
992-
return false;
993-
}
994-
995-
return true;
1002+
return readonly == null || (!readonly.equals("readonly") && !readonly.equals("true"));
9961003
}
9971004

9981005
protected boolean isFocused(String locator) {
@@ -1113,6 +1120,7 @@ protected CharSequence mapAsciiKeyCodeToKey(int keyCode) {
11131120
case 127:
11141121
return Keys.DELETE;
11151122
default:
1123+
//noinspection NewStringBufferWithCharArgument
11161124
return new StringBuffer((char) keyCode);
11171125
}
11181126
}

src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/Waiting.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,26 @@ public void waitUntilTitleContains(final String title, String...params) {
303303
});
304304
}
305305

306+
@RobotKeyword("Waits until the current WebElement attribute or CSS property will be containing value.")
307+
@ArgumentNames({ "value", "attribute", "locator", "timeout=NONE", "message=NONE" })
308+
public void waitUntilElementAttributeValueContains(final String value, final String attribute, final String locator, String...params) {
309+
String timeout = robot.getParamsValue(params, 0, null);
310+
String message = robot.getParamsValue(params, 1, null);
311+
if (message == null) {
312+
message = String.format("Attribute value '%s' did not contain in attribute '%s' in <TIMEOUT>", value, attribute);
313+
}
314+
waitUntil(
315+
timeout,
316+
message,
317+
() -> {
318+
String currentValue = element.getElementAttribute(locator, attribute);
319+
if (currentValue == null || currentValue.isEmpty()) {
320+
currentValue = element.getCssValue(attribute, locator);
321+
}
322+
return value.equals(currentValue);
323+
});
324+
}
325+
306326
@RobotKeyword("Waits until the current page title does not contain ``title``.\r\n" +
307327
"\r\n" +
308328
"Fails, if the timeout expires, before the page title does not contain the given title. \r\n" +

src/main/java/com/github/markusbernhardt/seleniumlibrary/locators/TableElementFinder.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,11 @@ protected static List<String> parseTableLocator(String tableLocator, String loca
9494

9595
List<String> locatorSuffixes = locatorSuffixesMap.get(tableLocatorType + locationMethod);
9696

97-
List<String> parsedTabeLocators = new ArrayList<>();
97+
List<String> parsedTableLocators = new ArrayList<>();
9898
for (String locatorSuffix : locatorSuffixes) {
99-
parsedTabeLocators.add(tableLocator + locatorSuffix);
99+
parsedTableLocators.add(tableLocator + locatorSuffix);
100100
}
101-
return parsedTabeLocators;
101+
return parsedTableLocators;
102102
}
103103

104104
protected static WebElement searchInLocators(WebDriver webDriver, List<String> locators, String content) {

src/main/java/com/github/markusbernhardt/seleniumlibrary/utils/Robotframework.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public static String commonPath(String p1, String p2) {
9696
}
9797

9898
public static String secsToTimestr(double double_secs) {
99-
TimestrHelper secsToTimestrHelper = new TimestrHelper(double_secs);
99+
TimeStringHelper secsToTimestrHelper = new TimeStringHelper(double_secs);
100100
return secsToTimestrHelper.getValue();
101101
}
102102

@@ -117,7 +117,7 @@ public static double timestrToSecs(String timestr) {
117117
int mins = 0;
118118
int hours = 0;
119119
int days = 0;
120-
int sign = 0;
120+
int sign;
121121
if (timestr.charAt(0) == '-') {
122122
sign = -1;
123123
timestr = timestr.substring(1);

src/main/java/com/github/markusbernhardt/seleniumlibrary/utils/TimestrHelper.java renamed to src/main/java/com/github/markusbernhardt/seleniumlibrary/utils/TimeStringHelper.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@
33
import java.util.ArrayList;
44
import java.util.List;
55

6-
public class TimestrHelper {
6+
public class TimeStringHelper {
77

88
protected boolean compact;
9-
protected List<String> ret = new ArrayList<String>();
9+
protected List<String> ret = new ArrayList<>();
1010
protected String sign;
1111
protected int millis;
1212
protected int secs;
1313
protected int mins;
1414
protected int hours;
1515
protected int days;
1616

17-
public TimestrHelper(double double_secs) {
17+
public TimeStringHelper(double double_secs) {
1818
this(double_secs, false);
1919
}
2020

21-
public TimestrHelper(double double_secs, boolean compact) {
21+
public TimeStringHelper(double double_secs, boolean compact) {
2222
this.compact = compact;
2323
secsToComponents(double_secs);
2424
addItem(days, "d", "day");

0 commit comments

Comments
 (0)