diff --git a/src/main/java/com/frameworkium/core/ui/ExtraExpectedConditions.java b/src/main/java/com/frameworkium/core/ui/ExtraExpectedConditions.java
index d9f2d2f0..69e45999 100755
--- a/src/main/java/com/frameworkium/core/ui/ExtraExpectedConditions.java
+++ b/src/main/java/com/frameworkium/core/ui/ExtraExpectedConditions.java
@@ -7,6 +7,8 @@
import ru.yandex.qatools.htmlelements.element.TypifiedElement;
import java.util.List;
+import java.util.function.Function;
+import java.util.stream.Collectors;
/**
* Frameworkium extension of {@link ExpectedConditions}.
@@ -30,14 +32,17 @@ public class ExtraExpectedConditions {
* iff the element is visible, otherwise true.
*/
public static ExpectedCondition notPresentOrInvisible(
- WebElement element) {
- return driver -> {
- try {
- return !element.isDisplayed();
- } catch (NoSuchElementException e) {
- return true;
- }
- };
+ final WebElement element) {
+
+ return expectedCondition(driver -> {
+ try {
+ return !element.isDisplayed();
+ } catch (NoSuchElementException e) {
+ return true;
+ }
+ },
+ String.format(
+ "element '%s' to not be present or be invisible", element));
}
/**
@@ -45,29 +50,23 @@ public static ExpectedCondition notPresentOrInvisible(
* for {@link List} of {@link WebElement}s.
*
* @param elements the lazy proxy for List<WebElement>
to wait for
- * @return an {@link ExpectedCondition} which returns false
- * iff any element is visible, otherwise true.
+ * @return an {@link ExpectedCondition} which returns the list
+ * iff any element is visible, otherwise null.
* @see ExtraExpectedConditions#notPresentOrInvisible(WebElement)
*/
public static ExpectedCondition> notPresentOrInvisible(
- List extends WebElement> elements) {
-
- return driver ->
- elements.stream()
- .noneMatch(WebElement::isDisplayed)
- ? elements
- : null;
- }
-
- /**
- * @return true iff jQuery is available and 0 ajax queries are active.
- */
- public static ExpectedCondition jQueryAjaxDone() {
+ final List extends WebElement> elements) {
- return driver ->
- (Boolean) ((JavascriptExecutor) driver)
- .executeScript(
- "return !!window.jQuery && jQuery.active === 0;");
+ return expectedCondition(driver ->
+ elements.stream()
+ .noneMatch(WebElement::isDisplayed)
+ ? elements
+ : null,
+ String.format(
+ "the following elements to not be present or be invisible: %s",
+ elements.stream()
+ .map(WebElement::toString)
+ .collect(Collectors.joining(", "))));
}
/**
@@ -80,10 +79,9 @@ public static ExpectedCondition jQueryAjaxDone() {
public static ExpectedCondition> sizeGreaterThan(
List extends WebElement> list, int expectedSize) {
- return driver ->
- list.size() > expectedSize
- ? list
- : null;
+ return expectedCondition(
+ driver -> list.size() > expectedSize ? list : null,
+ "list size of " + list.size() + " to be greater than " + expectedSize);
}
/**
@@ -96,10 +94,19 @@ public static ExpectedCondition> sizeGreaterThan(
public static ExpectedCondition> sizeLessThan(
List extends WebElement> list, int expectedSize) {
- return driver ->
- list.size() < expectedSize
- ? list
- : null;
+ return expectedCondition(
+ driver -> list.size() < expectedSize ? list : null,
+ "list size of " + list.size() + " to be less than " + expectedSize);
+ }
+
+ /**
+ * @return true iff jQuery is available and 0 ajax queries are active.
+ */
+ public static ExpectedCondition jQueryAjaxDone() {
+
+ return javascriptExpectedCondition(
+ "return !!window.jQuery && jQuery.active === 0;",
+ "jQuery AJAX queries to not be active");
}
/**
@@ -111,8 +118,31 @@ public static ExpectedCondition> sizeLessThan(
*/
public static ExpectedCondition documentBodyReady() {
- return driver ->
- (Boolean) ((JavascriptExecutor) driver)
- .executeScript("return document.readyState == 'complete';");
+ return javascriptExpectedCondition(
+ "return document.readyState == 'complete';",
+ "the document ready state to equal 'complete'");
+ }
+
+ private static ExpectedCondition javascriptExpectedCondition(
+ String query, String message) {
+ return expectedCondition(
+ driver -> (Boolean) ((JavascriptExecutor) driver).executeScript(query),
+ message);
+ }
+
+ private static ExpectedCondition expectedCondition(
+ Function function, String string) {
+
+ return new ExpectedCondition() {
+ @Override
+ public T apply(WebDriver driver) {
+ return function.apply(driver);
+ }
+
+ @Override
+ public String toString() {
+ return string;
+ }
+ };
}
}