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

Feature/wait attribute contains value #91

Merged
Merged
Show file tree
Hide file tree
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 @@ -437,6 +437,17 @@ public String getElementAttribute(String attributeLocator) {
return getElementAttribute(parts[0], parts[1]);
}

@RobotKeyword("Get the value of a given CSS property.")
@ArgumentNames({ "attribute", "locator" })
public String getCssValue(final String attribute, final String locator) {
List<WebElement> elements = elementFind(locator, true, false);

if (elements.size() == 0) {
throw new SeleniumLibraryNonFatalException(String.format("Element '%s' not found.", locator));
}
return elements.get(0).getCssValue(attribute);
}

@RobotKeyword("Returns value of attribute from element locator.\r\n" +
"\r\n" +
"See the `Locating elements` section for details about the locator syntax.\r\n" +
Expand Down Expand Up @@ -998,11 +1009,7 @@ protected boolean isEnabled(String locator) {
return false;
}
String readonly = element.getAttribute("readonly");
if (readonly != null && (readonly.equals("readonly") || readonly.equals("true"))) {
return false;
}

return true;
return readonly == null || (!readonly.equals("readonly") && !readonly.equals("true"));
}

protected boolean isFocused(String locator) {
Expand Down Expand Up @@ -1123,6 +1130,7 @@ protected CharSequence mapAsciiKeyCodeToKey(int keyCode) {
case 127:
return Keys.DELETE;
default:
//noinspection NewStringBufferWithCharArgument
return new StringBuffer((char) keyCode);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,26 @@ public void waitUntilTitleContains(final String title, String...params) {
});
}

@RobotKeyword("Waits until the current WebElement attribute or CSS property will be containing value.")
@ArgumentNames({ "value", "attribute", "locator", "timeout=NONE", "message=NONE" })
public void waitUntilElementAttributeValueContains(final String value, final String attribute, final String locator, String...params) {
String timeout = robot.getParamsValue(params, 0, null);
String message = robot.getParamsValue(params, 1, null);
if (message == null) {
message = String.format("Attribute value '%s' did not contain in attribute '%s' in <TIMEOUT>", value, attribute);
}
waitUntil(
timeout,
message,
() -> {
String currentValue = element.getElementAttribute(locator, attribute);
if (currentValue == null || currentValue.isEmpty()) {
currentValue = element.getCssValue(attribute, locator);
}
return value.equals(currentValue);
});
}

@RobotKeyword("Waits until the current page title does not contain ``title``.\r\n" +
"\r\n" +
"Fails, if the timeout expires, before the page title does not contain the given title. \r\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ protected static List<String> parseTableLocator(String tableLocator, String loca

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

List<String> parsedTabeLocators = new ArrayList<>();
List<String> parsedTableLocators = new ArrayList<>();
for (String locatorSuffix : locatorSuffixes) {
parsedTabeLocators.add(tableLocator + locatorSuffix);
parsedTableLocators.add(tableLocator + locatorSuffix);
}
return parsedTabeLocators;
return parsedTableLocators;
}

protected static WebElement searchInLocators(WebDriver webDriver, List<String> locators, String content) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public static String commonPath(String p1, String p2) {
}

public static String secsToTimestr(double double_secs) {
TimestrHelper secsToTimestrHelper = new TimestrHelper(double_secs);
TimeStringHelper secsToTimestrHelper = new TimeStringHelper(double_secs);
return secsToTimestrHelper.getValue();
}

Expand All @@ -117,7 +117,7 @@ public static double timestrToSecs(String timestr) {
int mins = 0;
int hours = 0;
int days = 0;
int sign = 0;
int sign;
if (timestr.charAt(0) == '-') {
sign = -1;
timestr = timestr.substring(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
import java.util.ArrayList;
import java.util.List;

public class TimestrHelper {
public class TimeStringHelper {

protected boolean compact;
protected List<String> ret = new ArrayList<String>();
protected List<String> ret = new ArrayList<>();
protected String sign;
protected int millis;
protected int secs;
protected int mins;
protected int hours;
protected int days;

public TimestrHelper(double double_secs) {
public TimeStringHelper(double double_secs) {
this(double_secs, false);
}

public TimestrHelper(double double_secs, boolean compact) {
public TimeStringHelper(double double_secs, boolean compact) {
this.compact = compact;
secsToComponents(double_secs);
addItem(days, "d", "day");
Expand Down