Skip to content

Commit ac6f02d

Browse files
committed
Added @invisible capability for waiting for things to NOT be present on page load
1 parent 6d6295e commit ac6f02d

File tree

2 files changed

+52
-4
lines changed

2 files changed

+52
-4
lines changed

src/main/java/com/frameworkium/pages/internal/BasePage.java

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,15 @@
99
import org.apache.commons.lang.StringUtils;
1010
import org.apache.logging.log4j.LogManager;
1111
import org.apache.logging.log4j.Logger;
12-
import org.openqa.selenium.JavascriptExecutor;
13-
import org.openqa.selenium.StaleElementReferenceException;
14-
import org.openqa.selenium.WebDriver;
15-
import org.openqa.selenium.WebElement;
12+
import org.openqa.selenium.*;
13+
import org.openqa.selenium.support.ui.ExpectedCondition;
1614
import org.openqa.selenium.support.ui.ExpectedConditions;
1715
import org.openqa.selenium.support.ui.WebDriverWait;
1816
import ru.yandex.qatools.htmlelements.element.HtmlElement;
1917
import ru.yandex.qatools.htmlelements.element.TypifiedElement;
2018
import ru.yandex.qatools.htmlelements.loader.HtmlElementLoader;
2119

20+
import javax.annotation.Nullable;
2221
import java.lang.annotation.Annotation;
2322
import java.lang.reflect.Field;
2423
import java.util.List;
@@ -115,6 +114,15 @@ private void waitForExpectedVisibleElements(Object pageObject, String visibleGro
115114
waitForObjectToBeVisible(obj);
116115
}
117116
}
117+
} else if (annotation instanceof Invisible) {
118+
field.setAccessible(true);
119+
Object obj = field.get(pageObject);
120+
if (obj instanceof WebElement) {
121+
wait.until(invisibilityOfElement((WebElement)obj));
122+
}
123+
else if(obj instanceof TypifiedElement ){
124+
wait.until(invisibilityOfElement(((TypifiedElement) obj).getWrappedElement()));
125+
}
118126
}
119127
}
120128
}
@@ -151,6 +159,31 @@ private void waitForObjectToBeVisible(Object obj) throws IllegalArgumentExceptio
151159
}
152160
}
153161

162+
private void waitForInvisibleElement(WebElement element){
163+
wait.until(invisibilityOfElement(element));
164+
}
165+
166+
private ExpectedCondition<Boolean> invisibilityOfElement(WebElement element){
167+
return new ExpectedCondition<Boolean>() {
168+
@Nullable
169+
@Override
170+
public Boolean apply(WebDriver input) {
171+
try {
172+
return !element.isDisplayed();
173+
} catch (NoSuchElementException var3) {
174+
return Boolean.valueOf(true);
175+
} catch (StaleElementReferenceException var4) {
176+
return Boolean.valueOf(true);
177+
}
178+
}
179+
public String toString() {
180+
return "element to no longer be visible: " + element;
181+
}
182+
};
183+
184+
}
185+
186+
154187
/**
155188
* Will wait up to ~10 seconds for the document to be ready.
156189
*/
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.frameworkium.pages.internal;
2+
3+
import org.apache.commons.lang.StringUtils;
4+
5+
import java.lang.annotation.ElementType;
6+
import java.lang.annotation.Retention;
7+
import java.lang.annotation.RetentionPolicy;
8+
import java.lang.annotation.Target;
9+
10+
@Retention(RetentionPolicy.RUNTIME)
11+
@Target(ElementType.FIELD)
12+
public @interface Invisible {
13+
String value() default StringUtils.EMPTY;
14+
}
15+

0 commit comments

Comments
 (0)