Last active
March 2, 2018 06:52
-
-
Save Ankit-Laddha/67cfcf9f0bcdb571ea20e517ddd5c471 to your computer and use it in GitHub Desktop.
Normal waits conditions to be used with Page Object Model
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public boolean isElementDisplayed(WebElement element) { | |
| try { | |
| return element.isDisplayed(); | |
| } catch (NoSuchElementException | TimeoutException | StaleElementReferenceException ex) { | |
| return false; | |
| } | |
| } | |
| public boolean areElementsDisplayed(List<WebElement> elements) { | |
| return elements.size() > 0 | |
| && elements.stream().allMatch(webElement -> isElementDisplayed(webElement)); | |
| } | |
| public Page waitUntilElementIsDisplayed(WebElement element) { | |
| FluentWait<WebElement> wait = new FluentWait<>(element); | |
| wait.withTimeout(30, TimeUnit.SECONDS); | |
| wait.until(webElement -> isElementDisplayed(webElement)); | |
| return this; | |
| } | |
| public Page waitUntilElementsAreDisplayed(List<WebElement> elements) { | |
| FluentWait<List<WebElement>> wait = new FluentWait<>(elements); | |
| wait.withTimeout(30, TimeUnit.SECONDS); | |
| wait.until(webElements -> areElementsDisplayed(webElements)); | |
| return this; | |
| } | |
| public boolean isElementClickable(final WebElement element) { | |
| return isElementDisplayed(element) && element.isEnabled(); | |
| } | |
| public Page waitUntilElementIsClickable(WebElement element) { | |
| FluentWait<WebElement> wait = new FluentWait<>(element); | |
| wait.withTimeout(30, TimeUnit.SECONDS); | |
| wait.until(webElement -> isElementClickable(webElement)); | |
| return this; | |
| } | |
| public boolean isElementNotDisplayed(WebElement element) { | |
| try { | |
| return !element.isDisplayed(); | |
| } catch (NoSuchElementException | TimeoutException | StaleElementReferenceException ex) { | |
| // Assuming a stale element isn't displayed. | |
| return true; | |
| } | |
| } | |
| public Page waitUntilElementIsNotDisplayed(WebElement element) { | |
| FluentWait<WebElement> wait = new FluentWait<>(element); | |
| wait.withTimeout(30, TimeUnit.SECONDS); | |
| wait.until(webElement -> isElementNotDisplayed(webElement)); | |
| return this; | |
| } | |
| public boolean areElementsNotDisplayed(List<WebElement> elements) { | |
| return elements.stream().allMatch(ele -> isElementNotDisplayed(ele)); | |
| } | |
| public Page waitUntilElementsAreNotDisplayed(List<WebElement> elements) { | |
| FluentWait<List<WebElement>> wait = new FluentWait<>(elements); | |
| wait.withTimeout(30, TimeUnit.SECONDS); | |
| wait.until(webElements -> areElementsNotDisplayed(webElements)); | |
| return this; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment